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]

noalias macro bug [was: Linux and aliasing?]


I have followed the aliasing discussion with some interest and 
decided to observe the aliasing effects on my own.
I used the following tiny program:

---------------------------------------------------------------------------------------------
#include <stdio.h>

#define noalias(type, ptr) (((union { type __x__; __typeof__(*(ptr)) __y__;} *)(ptr))->__x__)

int
main ()
{
    int a = 0x12345678;
    unsigned short *b = &noalias(unsigned short, &a);

    printf ("%x\n", a);
    b[1] = 0;
    printf ("%x\n", a);

    return 0;
}
---------------------------------------------------------------------------------------------

It uses the noalias macro proposed by Richard Henderson with the
typeof extension suggested by Jamie Lokier.

What I get is:
pommnitz ~>gcc -Wall -pedantic -ansi -fstrict-aliasing -O6 -march=pentium -o alias alias.c 
pommnitz ~>./alias 
12345678
12345678
pommnitz ~>gcc -Wall -pedantic -ansi -fno-strict-aliasing -O6 -march=pentium -o alias alias.c 
pommnitz ~>./alias 
12345678
5678

Is this an egcs bug, is the macro at fault or am I doing something stupid?

My system (in case it matters):
RedHat Linux 5.2 (i.e. glibc2) with gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release).

-- 
Regards
       Joerg
GMD-IPSI, Dolivostr. 15, Zimmer 120, D-64293 Darmstadt
+49-6151-869-786 (Phone), -818 (FAX)


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