Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Feb 2014 14:06:55 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        David Hines <freebsd@dph.fluff.org>
Cc:        freebsd-gnats-submit@freebsd.org, freebsd-i386@freebsd.org
Subject:   Re: i386/186848: CLANG/LLVM code generation bug with optimisation on i386
Message-ID:  <20140220135253.K889@besplex.bde.org>
In-Reply-To: <201402171745.s1HHjCsG010826@cgiserv.freebsd.org>
References:  <201402171745.s1HHjCsG010826@cgiserv.freebsd.org>

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

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



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