From owner-freebsd-i386@FreeBSD.ORG Mon Feb 17 17:50:01 2014 Return-Path: Delivered-To: freebsd-i386@smarthost.ysv.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 1365048B for ; Mon, 17 Feb 2014 17:50:00 +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 6AB491C61 for ; Mon, 17 Feb 2014 17:50:00 +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 s1HHo0Ri061735 for ; Mon, 17 Feb 2014 17:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s1HHo0Ek061734; Mon, 17 Feb 2014 17:50:00 GMT (envelope-from gnats) Resent-Date: Mon, 17 Feb 2014 17:50:00 GMT Resent-Message-Id: <201402171750.s1HHo0Ek061734@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-i386@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, David Hines 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 5015AAD1 for ; Mon, 17 Feb 2014 17:45:13 +0000 (UTC) Received: from newred.freebsd.org (cgiserv.freebsd.org [IPv6:2001:1900:2254:206a::50:4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1E9391C16 for ; Mon, 17 Feb 2014 17:45:13 +0000 (UTC) Received: from cgiserv.freebsd.org ([127.0.1.6]) by newred.freebsd.org (8.14.7/8.14.7) with ESMTP id s1HHjCae010827 for ; Mon, 17 Feb 2014 17:45:12 GMT (envelope-from nobody@cgiserv.freebsd.org) Received: (from nobody@localhost) by cgiserv.freebsd.org (8.14.7/8.14.7/Submit) id s1HHjCsG010826; Mon, 17 Feb 2014 17:45:12 GMT (envelope-from nobody) Message-Id: <201402171745.s1HHjCsG010826@cgiserv.freebsd.org> Date: Mon, 17 Feb 2014 17:45:12 GMT From: David Hines To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: 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 List-Id: I386-specific issues for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Feb 2014 17:50:01 -0000 >Number: 186848 >Category: i386 >Synopsis: CLANG/LLVM code generation bug with optimisation on i386 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-i386 >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Feb 17 17:50:00 UTC 2014 >Closed-Date: >Last-Modified: >Originator: David Hines >Release: FreeBSD 10.0-RELEASE #0 r260789 >Organization: >Environment: FreeBSD free100 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: Fri Jan 17 01:46:25 UTC 2014 root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC i386 >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. >How-To-Repeat: Compile and run the attached programme. When this is compiled without optimisation the output is correct. cc -o clang_bug clang_bug.c; ./clang_bug An int has 32 bits With optimisation it is incorrect. cc -O -o clang_bug-O clang_bug.c; ./clang_bug-O An int has 33 bits >Fix: No fix known. Work-arounds include not using optimiser, or using gcc. Patch attached with submission follows: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # clang_bug.c # echo x - clang_bug.c sed 's/^X//' >clang_bug.c << '7cdc9fc910e8be01c1758f1d1bf4e799' X#include X X/* X * This demonstrates a bug in the code generation of the C compiler X * distributed as part of FreeBSD 10.0 on i386 when using optimisation. X * X * To identify the affected system: X * Output from uname -ap: X * FreeBSD free100 10.0-RELEASE FreeBSD 10.0-RELEASE #0 r260789: X * Fri Jan 17 01:46:25 UTC 2014 X * root@snap.freebsd.org:/usr/obj/usr/src/sys/GENERIC i386 i386 X * Output from cc -v: X * FreeBSD clang version 3.3 (tags/RELEASE_33/final 183502) 20130610 X * Target: i386-unknown-freebsd10.0 X * Thread model: posix X * X * When this is compiled without optimisation the output is correct. X * cc -o clang_bug clang_bug.c; ./clang_bug X * An int has 32 bits X * X * With optimisation it is incorrect. X * cc -O -o clang_bug-O clang_bug.c; ./clang_bug-O X * An int has 33 bits X */ X 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} 7cdc9fc910e8be01c1758f1d1bf4e799 exit >Release-Note: >Audit-Trail: >Unformatted: