Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Oct 2013 10:04:12 +0000
From:      Bruce Cran <bruce@cran.org.uk>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Code segfaults with clang -O1, works with gcc49 and clang -O2
Message-ID:  <5270D99C.6070901@cran.org.uk>

next in thread | raw e-mail | index | archive | help
The following code works (on FreeBSD 11-CURRENT) with gcc49 or clang -O2 
or higher, but segfaults in do_cpuid() with clang -O1 or lower. Is there 
a bug in the asm statement, or is clang doing something wrong?

#include <stdio.h>

static inline void do_cpuid(unsigned int *eax, unsigned int *ebx,
                             unsigned int *ecx, unsigned int *edx)
{
         asm volatile("cpuid"
                 : "=a" (*eax), "=b" (*ebx), "=r" (*ecx), "=d" (*edx)
                 : "0" (*eax), "2" (*ecx)
                 : "memory");
}

int main(int argc, char **argv)
{
     unsigned int a = 0, b = 0, c = 0, d = 0;
     do_cpuid(&a, &b, &c, &d);
     printf("%d %d %d %d\n", a, b, c, d);
     return 0;
}


-- 
Bruce Cran



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5270D99C.6070901>