From owner-freebsd-i386@FreeBSD.ORG Thu Feb 20 03:10:01 2014 Return-Path: Delivered-To: freebsd-i386@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id AB729EB1 for ; Thu, 20 Feb 2014 03:10:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 924FD15F4 for ; Thu, 20 Feb 2014 03:10:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id s1K3A1bG027673 for ; Thu, 20 Feb 2014 03:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s1K3A1OG027672; Thu, 20 Feb 2014 03:10:01 GMT (envelope-from gnats) Date: Thu, 20 Feb 2014 03:10:01 GMT Message-Id: <201402200310.s1K3A1OG027672@freefall.freebsd.org> To: freebsd-i386@FreeBSD.org Cc: From: Bruce Evans Subject: Re: i386/186848: CLANG/LLVM code generation bug with optimisation on i386 X-BeenThere: freebsd-i386@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: Bruce Evans 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:10:01 -0000 The following reply was made to PR i386/186848; it has been noted by GNATS. From: Bruce Evans To: David Hines Cc: freebsd-gnats-submit@freebsd.org, freebsd-i386@freebsd.org Subject: Re: i386/186848: CLANG/LLVM code generation bug with optimisation on i386 Date: Thu, 20 Feb 2014 14:06:55 +1100 (EST) 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