This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15277] New: code generation error: enum in bit field


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

-- 
           Summary: code generation error: enum in bit field
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pepster at users dot sourceforge dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]