From owner-freebsd-questions@FreeBSD.ORG Wed Oct 30 10:04:24 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 9CA651EF for ; Wed, 30 Oct 2013 10:04:24 +0000 (UTC) (envelope-from bruce@cran.org.uk) Received: from muon.cran.org.uk (muon.cran.org.uk [IPv6:2a01:348:0:15:5d59:5c40:0:1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5F3BC232D for ; Wed, 30 Oct 2013 10:04:24 +0000 (UTC) Received: from muon.cran.org.uk (localhost [127.0.0.1]) by muon.cran.org.uk (Postfix) with ESMTP id 8F7BAE6E39 for ; Wed, 30 Oct 2013 10:04:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cran.org.uk; h=message-id :date:from:mime-version:to:subject:content-type :content-transfer-encoding; s=mail; bh=MoinDCgSWs032Z6P0/crwGS0Y QM=; b=fa/ejEl4W1/MReRN8f+4Bki8kvgA+fagqjcEhnDR4j2n2f0if/TlCZb2S EBYUiqtoTHkGxC18C4qdp/kit9kd0jk4r66di1Rn6nvfhVfo+fpBSuSeLL+fDB2y MWWn8aSP8fQFoFRsL4GCHsQz3UyBHTI/Sgmr/0wuarJDmnNV3o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=cran.org.uk; h=message-id :date:from:mime-version:to:subject:content-type :content-transfer-encoding; q=dns; s=mail; b=wHydixINDMuPEA9mHI7 8LTwDEumVgd8mu/KKc2JSVFWr0Ih+T1ezqcC2D62dCiaAHX3QdER1adhzP9fDHx+ pLN5BFKo1m37OVgcQOCrivkffaZMTW4zBf0sjso/ZpnG+hZFavKaQbSIP7deu0cL jFz+X287yaEcbwwwvSe0Tsqw= Received: from [192.168.2.50] (unknown [93.89.81.205]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by muon.cran.org.uk (Postfix) with ESMTPSA id 530AAE6DDF for ; Wed, 30 Oct 2013 10:04:13 +0000 (GMT) Message-ID: <5270D99C.6070901@cran.org.uk> Date: Wed, 30 Oct 2013 10:04:12 +0000 From: Bruce Cran User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: FreeBSD Questions Subject: Code segfaults with clang -O1, works with gcc49 and clang -O2 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 10:04:24 -0000 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) : "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