This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15776] New: enum optimization produces wrong code
- From: "gollin at informatik dot hu-berlin dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Jun 2004 13:15:10 -0000
- Subject: [Bug c++/15776] New: enum optimization produces wrong code
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following program doesn't run properly when compiled with -O
#include <stdio.h>
enum OptionStateEnum
{
SLEEPING,
ACTIVE,
INTENDED,
DESIRED,
EXECUTED,
ABORTED
};
int main()
{
OptionStateEnum l[2] = { EXECUTED, ACTIVE };
OptionStateEnum state;
for ( int i = 0; i < 2; ++i ) {
state = l[i];
printf( "state = %d\n", state );
if ( ( state == DESIRED ) ||
( state == INTENDED ) ||
( state == ACTIVE ) ) {
printf( "break state = %d\n", state );
break;
}
}
return 0;
}
The program was compiled using the following command:
gcc -O -g0 optimize-enum.cpp -o optimize-enum.exe
Resulting in the following output:
state = 4
break state = 4
When compiled with -O0 the output is as expected:
state = 4
state = 1
break state = 1
The problem also vanishes when checking for 4 or only 2 enums in the
if-statement. Or when assigning explicit values to the enums (0, 2, 4, 8, 16,
32, 64).
Cheers,
Michael Gollin
--
Summary: enum optimization produces wrong code
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gollin at informatik dot hu-berlin dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15776