Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 2014 17:45:12 GMT
From:      David Hines <freebsd@dph.fluff.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   i386/186848: CLANG/LLVM code generation bug with optimisation on i386
Message-ID:  <201402171745.s1HHjCsG010826@cgiserv.freebsd.org>
Resent-Message-ID: <201402171750.s1HHo0Ek061734@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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 <stdio.h>
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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201402171745.s1HHjCsG010826>