From owner-freebsd-questions@FreeBSD.ORG Wed Oct 30 13:33:12 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id AFCC3B78 for ; Wed, 30 Oct 2013 13:33:12 +0000 (UTC) (envelope-from tijl@coosemans.org) Received: from mailrelay003.isp.belgacom.be (mailrelay003.isp.belgacom.be [195.238.6.53]) by mx1.freebsd.org (Postfix) with ESMTP id 4F0F4218C for ; Wed, 30 Oct 2013 13:33:12 +0000 (UTC) X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al8GAKwJcVJbs47V/2dsb2JhbABZgwe9WYMAgSQXdIIlAQEFOhwjEAsYCSUPKh4GiB4BunSPTweELAOYCZIKgyc7 Received: from 213.142-179-91.adsl-dyn.isp.belgacom.be (HELO kalimero.tijl.coosemans.org) ([91.179.142.213]) by relay.skynet.be with ESMTP; 30 Oct 2013 14:33:04 +0100 Received: from kalimero.tijl.coosemans.org (kalimero.tijl.coosemans.org [127.0.0.1]) by kalimero.tijl.coosemans.org (8.14.7/8.14.7) with ESMTP id r9UDX3qP019856; Wed, 30 Oct 2013 14:33:03 +0100 (CET) (envelope-from tijl@coosemans.org) Date: Wed, 30 Oct 2013 14:33:01 +0100 From: Tijl Coosemans To: Bruce Cran Subject: Re: Code segfaults with clang -O1, works with gcc49 and clang -O2 Message-ID: <20131030143301.623be910@kalimero.tijl.coosemans.org> In-Reply-To: <5270D99C.6070901@cran.org.uk> References: <5270D99C.6070901@cran.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Oct 2013 13:33:12 -0000 On Wed, 30 Oct 2013 10:04:12 +0000 Bruce Cran wrote: > 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 > > 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) Should be: "=c" (*ecx) But you can also use the '+' modifier and remove the input operands: : "+a" (*eax), "=b" (*ebx), "+c" (*ecx), "=d" (*edx) : : "memory" > : "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; > } > >