Skip to main content

compilation warning "dereferencing type-punned pointer.." in gcc 3.x or 4.x

3 replies [Last post]
gyu
Offline
Joined: 2007-06-03
Points: 0

Hello,
I found warnings like followings in compiling with gcc 3.x or gcc 4.x.

../../src/share/javavm/native/java/security/AccessController.c|21| warning: dereferencing type-punned pointer will break strict-aliasing rules

CNIResultCode
CNIjava_security_AccessController_computeContext(CVMExecEnv* ee,
CVMStackVal32 *arguments, CVMMethodBlock **p_mb)
{
CVMInt32 n = 0;
CVMArrayOfBooleanICell *isPrivilegedRef =
(CVMArrayOfBooleanICell *)&arguments[0].j.r;
CVMArrayOfRefICell *contextRef =
(CVMArrayOfRefICell *)&arguments[1].j.r;

...

[and several same warnings around sources]

I found the fact that unlike gcc 2.x, gcc 3.x or later versions use strict-aliasing for further optimization, when compiled with -O2, -O3, or -O4.

Should I use -fno-strict-aliasing to prevent optimization base on invalid assumption?
Or is it safe to ignore this warnings?

- Sanggyu

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cjplummer
Offline
Joined: 2006-10-16
Points: 0

We fix strict aliasing warnings when they turn up, and haven't been seeing the one you mentioned (or any others in our currnet source). Can you send a full build log? Also, are you using MR1 or MR2?

Yes, using -fno-strict-aliasing would be a good idea until these are resolved. You can add it to CC_ARCH_FLAGS in the GNUmakefile.

Chris

Message was edited by: cjplummer

gyu
Offline
Joined: 2007-06-03
Points: 0

I use phoneME MR1 code.
I cannot generate the warnings again.
I think that warning was generated under specific configuration that I don't use now.

And as you suggested, I looked the MR2 code.
It seems to use -fno-strict-aliasing by default, except for on solaris using suncc.
Thus If I find the same warnings in MR1, I will use -fno-strict-aliasing.

Thank you always.

cjplummer
Offline
Joined: 2006-10-16
Points: 0

> I use phoneME MR1 code.
> I cannot generate the warnings again.
> I think that warning was generated under specific
> configuration that I don't use now.
>
> And as you suggested, I looked the MR2 code.
> It seems to use -fno-strict-aliasing by default,
> except for on solaris using suncc.
Ah yes. I completely forgot we made that change in MR2. I should have remembered since I made the change. :) Anyway, the reason we did this is not because we were lazy about fixing aliasing warnings. It is because GCC doesn't always report them. Seems like with each new release of GCC we'd run into another hard to find bug due to more aggressive aliasing, so we finally decided to turn it off.

> Thus If I find the same warnings in MR1, I will use
> -fno-strict-aliasing.
Sounds like a good idea.

Chris

>
> Thank you always.