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++/38818] New: C++ bitfield static initialisation problem


The following program seems to show a
compiler bug on x86 using 4.3.2 compilers

The correct output should be;

  giChannelTiming0.Setup 0xff
  giChannelTiming0.Recover 0xff000000

which occurs only when no optimiser or -O is used.

When -O2 or greater is used the mask's are incorrectly
computed and print as 0.

It is known also not to work on 4.1.2 compilers.

It works perfectly with all optimisation levels on 3.2.3
compilers.

/* ---- */

#include <stdio.h>
#include <sys/param.h>

typedef struct giChannelTiming {
#if BYTE_ORDER == BIG_ENDIAN
  /* Bits 24..31 */ unsigned Recover : 8 ;
  /* Bits 16..23 */ unsigned Hold : 8 ;
  /* Bits  8..15 */ unsigned Pulse : 8 ;
  /* Bits  0.. 7 */ unsigned Setup : 8 ;
#else
  /* Bits  0.. 7 */ unsigned Setup : 8 ;
  /* Bits  8..15 */ unsigned Pulse : 8 ;
  /* Bits 16..23 */ unsigned Hold : 8 ;
  /* Bits 24..31 */ unsigned Recover : 8 ;
#endif

 giChannelTiming(long l = 0) { *(unsigned long *)this=l; }
 operator unsigned long *(void) { return((unsigned long *)this) ; }
 operator unsigned long (void) { return(*(unsigned long *)this) ; }
} t_giChannelTiming ;

#define FIO_LOCATED(n) 0
#define ID_GEN_giChannelTiming0Setup 0
#define ID_GEN_giChannelTiming0Recover 0

#define GI_REG_F(field,reg) { #reg "." #field, ID_GEN_##reg##field, \
   { FIO_LOCATED(reg), (gr.reg=0, gr.reg.field =~0, (unsigned long)gr.reg)}}

struct gen_registers {
 t_giChannelTiming giChannelTiming0;
} ;

static gen_registers gr ;

struct regs {
          const char *name ;
          int id ;
          struct masks {
                  int locn ;
                  unsigned long mask ;
          } s ;
        } r[] = {
                GI_REG_F(Setup, giChannelTiming0),
                GI_REG_F(Recover, giChannelTiming0)
} ;

main() {
 printf("%s 0x%lx\n", r[0].name, r[0].s.mask);
 printf("%s 0x%lx\n", r[1].name, r[1].s.mask);
}

/* --------- */


-- 
           Summary: C++ bitfield static initialisation problem
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: john dot spelis at 3dlabs dot com
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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


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