public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15776] New: enum optimization produces wrong code
@ 2004-06-02 13:15 gollin at informatik dot hu-berlin dot de
  2004-06-02 13:18 ` [Bug c++/15776] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gollin at informatik dot hu-berlin dot de @ 2004-06-02 13:15 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/15776] enum optimization produces wrong code
  2004-06-02 13:15 [Bug c++/15776] New: enum optimization produces wrong code gollin at informatik dot hu-berlin dot de
@ 2004-06-02 13:18 ` pinskia at gcc dot gnu dot org
  2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
  2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-02 13:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-02 13:18 -------
This is a dup of bug 15069 which is fixed for 3.4.1.

*** This bug has been marked as a duplicate of 15069 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15776


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/15776] enum optimization produces wrong code
  2004-06-02 13:15 [Bug c++/15776] New: enum optimization produces wrong code gollin at informatik dot hu-berlin dot de
  2004-06-02 13:18 ` [Bug c++/15776] " pinskia at gcc dot gnu dot org
@ 2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
  2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-27 23:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-27 23:32 -------
Reopen as I marked it as a wrong bug as a dup of.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15776


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/15776] enum optimization produces wrong code
  2004-06-02 13:15 [Bug c++/15776] New: enum optimization produces wrong code gollin at informatik dot hu-berlin dot de
  2004-06-02 13:18 ` [Bug c++/15776] " pinskia at gcc dot gnu dot org
  2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
@ 2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-27 23:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-27 23:32 -------


*** This bug has been marked as a duplicate of 16372 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15776


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-07-27 23:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-02 13:15 [Bug c++/15776] New: enum optimization produces wrong code gollin at informatik dot hu-berlin dot de
2004-06-02 13:18 ` [Bug c++/15776] " pinskia at gcc dot gnu dot org
2004-07-27 23:32 ` pinskia at gcc dot gnu dot org
2004-07-27 23:32 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).