g++ and aliasing bools

Daniel Berlin dan@dberlin.org
Wed Jan 23 18:27:00 GMT 2002


On Wed, 23 Jan 2002, Dan Nicolaescu 
wrote:

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

It's a side effect of C++ not making alias sets for classes, i think.
Try commenting out the AGGREGATE_TYPE_P check in cxx_get_alias_set and see 
if it goes away.
> 
> 
> 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? 
> 
>         
> 



More information about the Gcc mailing list