dereferencing type-punned pointer will break strict-aliasing
rules
Jun Kuriyama
kuriyama at imgsrc.co.jp
Sun Jul 27 18:35:26 PDT 2003
At Mon, 28 Jul 2003 00:30:35 +0000 (UTC),
kuriyama wrote:
> Is this caused by -oS option?
Grrr, of course this should be s/-oS/-Os/.
These warnings are caused from DROP_GIANT() macro. By tracking this
down, actual source is __PCPU_GET() macro (line: 115) in
sys/i386/include/pcpu.h.
__result = *(__pcpu_type(name) *)&__i;
To test this with simplified code:
-----
% cat test.c
struct T {
int a;
};
void
test()
{
struct T* c;
int __i = 0;
c = *(struct T* *)&__i;
}
% cc -c -Os -Wall test.c
test.c: In function `test':
test.c:11: warning: dereferencing type-punned pointer will break strict-aliasing rules
-----
__PCPU_GET() macro seems to be harmless if -Os is not used or
__pcpu_type() returns actual type rather than pointer.
What should we do?
--
Jun Kuriyama <kuriyama at imgsrc.co.jp> // IMG SRC, Inc.
<kuriyama at FreeBSD.org> // FreeBSD Project
More information about the freebsd-current
mailing list