From owner-freebsd-i386@FreeBSD.ORG Thu Feb 20 03:07:05 2014 Return-Path: Delivered-To: freebsd-i386@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 ESMTPS id 9F4AFD06; Thu, 20 Feb 2014 03:07:05 +0000 (UTC) Received: from mail105.syd.optusnet.com.au (mail105.syd.optusnet.com.au [211.29.132.249]) by mx1.freebsd.org (Postfix) with ESMTP id 6146D15A0; Thu, 20 Feb 2014 03:07:05 +0000 (UTC) Received: from c122-106-144-87.carlnfd1.nsw.optusnet.com.au (c122-106-144-87.carlnfd1.nsw.optusnet.com.au [122.106.144.87]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id AC1D61044895; Thu, 20 Feb 2014 14:06:56 +1100 (EST) Date: Thu, 20 Feb 2014 14:06:55 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: David Hines Subject: Re: i386/186848: CLANG/LLVM code generation bug with optimisation on i386 In-Reply-To: <201402171745.s1HHjCsG010826@cgiserv.freebsd.org> Message-ID: <20140220135253.K889@besplex.bde.org> References: <201402171745.s1HHjCsG010826@cgiserv.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=HZAtEE08 c=1 sm=1 tr=0 a=p/w0leo876FR0WNmYI1KeA==:117 a=PO7r1zJSAAAA:8 a=b8iQ1apsL0UA:10 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=EhSFfmjhm6YA:10 a=SIEYPsji4qkKTh2LWYMA:9 a=CjuIK1q_8ugA:10 Cc: freebsd-gnats-submit@freebsd.org, freebsd-i386@freebsd.org X-BeenThere: freebsd-i386@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: I386-specific issues for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Feb 2014 03:07:05 -0000 On Mon, 17 Feb 2014, David Hines wrote: >> Description: > "cc -O -o clang_bug-O clang_bug.c" generates incorrect code on i386, with the attached sample code. Without the "-O", or on an amd64 install the problem does not occur. This is a bug in clang_bug.c. It's behaviour is undefined. > Xunion > X{ > X int i; > X} u; > X > X > Xint > Xmain(int argc, char *argv[]) > X{ > X int j = 1; > X > X for (u.i = 1; u.i += u.i; ++j) > X ; > X printf("An int has %d bits\n", j); > X > X return 0; > X} Undefined behaviour occurs when the addition overflows. clang somehow notices this (u.i starts as 1, and repeated doublings of it cannot make it 0 unless overflow occurs). The addition does in fact overflow. The result can be anything. Some people (not me) don't like clang not giving the "normal" behaviour on overflow. Bruce