Bug 15277 - code generation error: enum in bit field
Summary: code generation error: enum in bit field
Status: RESOLVED DUPLICATE of bug 15069
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-04 04:57 UTC by Joseph Heled
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Heled 2004-05-04 04:57:25 UTC
Bug in g++ 3.4.0 code genetarion.
Included below a test program, and assembly output from 3.4.0 (incorrect) and
3.3 (correct).

Thanks, Joseph

> uname -a
Linux yoda 2.4.18-18.8.0 #1 Wed Nov 13 22:52:09 EST 2002 i686 athlon i386 GNU/Linux

c++ source
==============================================================================
struct X {
  static unsigned int const bit = 0x2;

  enum Mode {
    B0 = 0x0,
      
    B1 = 0x1,

    B2 = 0x2,

    B3 = 0x3,
  };

  Mode		mode : 2;

  // return true if second bit is on
  bool	bit2(void) const { return (mode & bit) ? true : false; }
};

#include <iostream>

int
main()
{
  X x;
  x.mode =  x.B3;
  std::cout << "should be 3 1: " << x.mode << ' ' << x.bit2();
  return 0;
}

================================================================================

Run result:
  should be 3 1: 3 0

================================================================================
Compilation

> g++ -v -o i2 i2.cc
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --with-cpu=athlon-xp
--with-arch=athlon-xp --enable-languages=c,c++
Thread model: posix
gcc version 3.4.0
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/cc1plus -quiet -v -D_GNU_SOURCE
i2.cc -quiet -dumpbase i2.cc -march=athlon-xp -auxbase i2 -version -o
/tmp/ccjQgv65.s
ignoring nonexistent directory "NONE/include"
ignoring nonexistent directory
"/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/i686-pc-linux-gnu
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../../../include/c++/3.4.0/backward
 /usr/local/include
 /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/include
 /usr/include
End of search list.
GNU C++ version 3.4.0 (i686-pc-linux-gnu)
	compiled by GNU C version 3.4.0.
GGC heuristics: --param ggc-min-expand=45 --param ggc-min-heapsize=29906
 as -V -Qy -o /tmp/cczxH2c6.o /tmp/ccjQgv65.s
GNU assembler version 2.13.90.0.2 (i386-redhat-linux) using BFD version
2.13.90.0.2 20020802
 /usr/local/libexec/gcc/i686-pc-linux-gnu/3.4.0/collect2 --eh-frame-hdr -m
elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o i2 /usr/lib/crt1.o
/usr/lib/crti.o /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/crtbegin.o
-L/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0
-L/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/../../.. /tmp/cczxH2c6.o -lstdc++
-lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.0/crtend.o /usr/lib/crtn.o
====================================================================================

Incorrect assembly code

_ZNK1X4bit2Ev:
.LFB2:
	pushl	%ebp
.LCFI7:
	movl	%esp, %ebp
.LCFI8:
	movl	8(%ebp), %eax
	movzbl	(%eax), %eax
	andl	$3, %eax
	shrl	$31, %eax         <===================== what the ...
	leave
	ret


====================================================================================

Correct 3.3 assembly code

_ZNK1X4bit2Ev:
.LFB1477:
	pushl	%ebp
.LCFI7:
	movl	%esp, %ebp
.LCFI8:
	movl	8(%ebp), %eax
	movzbl	(%eax), %eax
	andl	$3, %eax
	shrl	%eax
	andl	$1, %eax
	popl	%ebp
	ret
Comment 1 Andrew Pinski 2004-05-04 05:16:41 UTC
This is a dup of bug 15069.

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