gcc __may_alias__ wonders

Thomas Doerfler Thomas.Doerfler at embedded-brains.de
Fri Dec 15 07:56:57 UTC 2006


I have somehow extended your example:

#include <stdio.h>

typedef volatile long unsigned xxx __attribute__((__may_alias__));

typedef struct {
  long unsigned  y1;
  long unsigned  y2;
} yyy_t __attribute__((__may_alias__));

extern xxx x;
extern yyy_t yy;

int testfnc(long unsigned *p)
  return *p * *p;

void test()


$ /opt/rtems-4.7/bin/powerpc-rtems4.7-gcc -Wall alias_test1.c
alias_test1.c: In function 'test':
alias_test1.c:20: warning: format '%lx' expects type 'long unsigned
int', but argument 2 has type 'long unsigned int'
alias_test1.c:23: warning: passing argument 1 of 'testfnc' from
incompatible pointer type

After ompiling, gcc still complains about "your" printf, but not about
the second one. Possibly gcc attaches the attribute to your data type
xxx and finds, that xxx is slightly different to unsigned long. And gcc
really sees that in the call


I pass a pointer to something that is not really an "unsigned long" to

So gcc treats the types



aaa_t __attribute__((__may_alias__))

as distinct types, which is all in all not so bad.

I think, when we might add this keyword to critical structure types, we
will most of the time do it consistently, so I think this will not
generate real problems.

But all in all I am still not sure whether it is possible with
reasonable effort and acceptable reliability to make RTEMS aliasing-proof.


Till Straumann schrieb:
> I started to play with __attribute__((__may_alias__))
> and here's what gcc now fills my screen with:
> warning: format '%08lx' expects type 'long unsigned int', but argument 2 
> has type 'long unsigned int'
> (because the argument 2 has the attribute __may_alias__)
> this alias crap is really annoying...
> #include <stdio.h>
> typedef volatile long unsigned xxx __attribute__((__may_alias__));
> extern xxx x;
> void test()
> {
> printf("0x%lx\n",x);
> }
> gcc -Wall -c test.c
> -- Till
> -- C is not Java --
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users

embedded brains GmbH
Thomas Doerfler           Obere Lagerstr. 30
D-82178 Puchheim          Germany
Tel. : +49-89-18 90 80 79-2
Fax  : +49-89-18 90 80 79-9
email: Thomas.Doerfler at embedded-brains.de
PGP public key available on request

More information about the users mailing list