[Bug optimization/15354] New: wrong code regression on enum test

senor_fjord at yahoo dot com gcc-bugzilla@gcc.gnu.org
Sun May 9 20:35:00 GMT 2004


The following code compiles fine on g++ 3.3.3 and 3.2.2, but does not on 3.4.0 or 3.4.1 release 
20040502.  I'm not sure if this is related to bug 15069 or not.  The code example is below.  When 
compiled with 3.4, it executes the print statement.  This bug only occurs when optimization (-O1, -O2, 
or -O3) is enabled.

int printf(char *, ...);

enum my_enum_e {
  zero      = 0,
  one       = 1,
  two       = 2,
  three     = 3,
  four      = 4,
  five      = 5,
  six       = 6,
  seven     = 7,
  eight     = 8,
  nine      = 9,
  ten       = 10,
  eleven    = 11,
  twelve    = 12,
  thirteen  = 13,
  fourteen  = 14,
  fifteen   = 15,
  sixteen   = 16,
  seventeen = 17,
  eighteen  = 18,
  nineteen  = 19,
  numbers   = 20
};

my_enum_e ret_nineteen() {
  return nineteen;
}


int main() {
  my_enum_e enm = ret_nineteen();

  if (enm == one      || enm == two      || enm == three   ||
      enm == four     || enm == five     || enm == six     ||
      enm == seven    || enm == eight    || enm == nine    ||
      enm == ten      || enm == eleven   || enm == twelve  ||
      enm == thirteen || enm == fourteen || enm == fifteen ||
      enm == sixteen)
    printf("shouldn't print");

  return 0;
}


The generated assembly is the following.  The test at EIP 804844f isn't correct if I'm reading the code 
right.

08048434 <ret_nineteen()>:
 8048434:       55                      push   %ebp
 8048435:       89 e5                   mov    %esp,%ebp
 8048437:       b8 13 00 00 00          mov    $0x13,%eax
 804843c:       5d                      pop    %ebp
 804843d:       c3                      ret    

0804843e <main>:
 804843e:       55                      push   %ebp
 804843f:       89 e5                   mov    %esp,%ebp
 8048441:       83 ec 08                sub    $0x8,%esp
 8048444:       83 e4 f0                and    $0xfffffff0,%esp
 8048447:       83 ec 10                sub    $0x10,%esp
 804844a:       e8 e5 ff ff ff          call   8048434 <ret_nineteen()>
 804844f:       85 c0                   test   %eax,%eax
 8048451:       74 0c                   je     804845f <main+0x21>
 8048453:       c7 04 24 48 85 04 08    movl   $0x8048548,(%esp,1)
 804845a:       e8 f9 fe ff ff          call   8048358 <_init+0x38>
 804845f:       b8 00 00 00 00          mov    $0x0,%eax
 8048464:       c9                      leave  
 8048465:       c3                      ret    
 8048466:       90                      nop    
 8048467:       90                      nop

-- 
           Summary: wrong code regression on enum test
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: senor_fjord at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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



More information about the Gcc-bugs mailing list