[BusyBox] Where do I report a compiler bug?

Manuel Novoa III mjn3 at codepoet.org
Mon Oct 13 14:06:30 UTC 2003


On Mon, Oct 13, 2003 at 08:05:35AM -0500, Rob Landley wrote:
> On Monday 13 October 2003 04:11, Wolfgang Denk wrote:
> > In message <200310130319.57281.rob at landley.net> you wrote:
> > > Yup, it's a compiler bug.  Here's the test case.  gcc 3.2.2 out of Red
> > > Hat 9 miscompiles this with -Os, but compiles it correctly without -Os.
> >
> > ...
> >
> > > 		/* Bug: this fails to move array */
> > >
> > > 		while(i) {
> > > 			mtfSymbol[i] = mtfSymbol[--i];
> > > 		}
> >
> > Are you sure this is a compiler bug? Or is it undefined behaviour?
> Yes, I'm sure it's a compiler bug.
> If it was undefined behavior, dest[i]=source[i++] wouldn't work.  If the 
> second occurrence of i could be evaluated before the first, then the 
> postincrement on the second would change the value of the first.  (Note, just 
> as preincrement says we must change the value before using it, postincrement 
> says the value is changed for everyone after us who uses it.)  And that's an 
> extremely common idiom.  It's evaluated from left to right.  Lvalue or not 
> doesn't change that.  (I'm a bit sleep deprived just now, but I remember 
> reading this in the spec ten years ago when I was studying what it would take 
> to implement my own C compiler...)

Quoting from the ANSI/ISO C99 standard...

6.5 Expressions

1 An expression is a sequence of operators and operands that specifies
  computation of a value, or that designates an object or a function,
  or that generates side effects, or that performs a combination thereof.

2 Between the previous and next sequence point an object shall have its
  stored value modified at most once by the evaluation of an expression.
  Furthermore, the prior value shall be read only to determine the value
  to be stored. (see footnote 70)

Footnote 70)
  This paragraph renders undefined statement expressions such as
       i = ++i + 1;
       a[i++] = i;
    while allowing
       a[i] = i;

> I'd also like to point out that the problem only occurs when an optimization 
> flag is given, and that it works correctly when you don't say -Os.

Since optimization can change the evaluation order, it often triggers
bad behavior in such undefined constructs.


More information about the busybox mailing list