This is the mail archive of the gcc@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]

g++ and aliasing bools



It looks like g++ has some problems with aliasing bools, and gcc
doesn't.


The following program: 

#ifdef __cplusplus

struct bool_struct         
{
  bool f0;
  bool f1;
  bool f2; 
  bool f3;
};
#else
struct bool_struct         
{
  _Bool f0;
  _Bool f1;
  _Bool f2; 
  _Bool f3;
};

#endif


struct bool_struct *str; 


void 
g (void)
{
  str->f0 = 1;
  str->f1 = 0;
  str->f2 = 1;
  str->f3 = 0; 
}

compiles to: 

_Z1gv:
.LLFB1:
        !#PROLOGUE# 0
        !#PROLOGUE# 1
        sethi   %hi(str), %o2
        ld      [%o2+%lo(str)], %o1
        mov     1, %o3
        stb     %o3, [%o1]
        ld      [%o2+%lo(str)], %o0   <- this load is not needed
        stb     %g0, [%o0+1]
        ld      [%o2+%lo(str)], %o1   <- this load is not needed
        stb     %o3, [%o1+2]
        ld      [%o2+%lo(str)], %o0   <- this load is not needed
        retl
        stb     %g0, [%o0+3]

when compiled with g++ -O2  on sparc-sun-solaris2.8 using a GCC from
CVS as of this morning. 

but the code is much better when compiling with gcc -O2 

g:
        !#PROLOGUE# 0
        !#PROLOGUE# 1
        sethi   %hi(str), %o0
        ld      [%o0+%lo(str)], %o1
        mov     1, %o2
        stb     %o2, [%o1+2]
        stb     %g0, [%o1+3]
        stb     %o2, [%o1]
        retl
        stb     %g0, [%o1+1]


so it looks like g++ has some issues with aliasing bools. 

Any idea what is wrong? 

        


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