Need some clarification about optimization flags, what "exactly" does -O1 do?

Andrew Haley
Thu Nov 27 14:33:00 GMT 2008

Andrzej Giniewicz wrote:

>> What does the declaration of IndexType look like?
> nothing special:
>         enum IndexType {
>           IT_16BIT,
>           IT_32BIT
>         };
>> The bug is probably in your app, not in gcc.
>> I think you'd be much better off fixing the bug than trying to
>> discover which optimization pass it breaks.
> not quite my app just app I try to build, i.e. developer seems to not
> have gcc 4.3 yet and I am just trying to get it on :) To be more
> precise - the value that is defined as:
> ... ? HardwareIndexBuffer::IT_32BIT : HardwareIndexBuffer::IT_16BIT
> is then checked with:
>         switch (mIndexType)
>         {
>         case IT_16BIT:
>             mIndexSize = sizeof(unsigned short);
>             break;
>         case IT_32BIT:
>             mIndexSize = sizeof(unsigned int);
>             break;
>         }
> but it don't trigger any of those in anything more than -O0 (if I add
> default with cerr<< it is triggered) and works on -O0... I didn't
> thought such funny thing can be caused by some bug where code is quite
> easy, simple switch on enumerated value that is set to one of two and
> not used/changed anywhere else...

Yeah, but that bug almost certainly isn't in the code you're looking at.

I've recently seen a bug that was triggered by -O in an enum where the
declaration was:

   enum Cell {

and gcc quite correctly assumed that a Cell could only have one value.

I'm not saying I'm absolutely certain this isn't a bug in gcc.  It's just
that it probably isn't.


More information about the Gcc-help mailing list