Re: -fstrict-aliasing, -Wstrict-aliasing=2, and indirect conversions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Harald van Dijk <truedfx@xxxxxxxxxx> writes:

> Thank you for your quick reply. Your patch has been very helpful. It
> doesn't seem to catch these similar cases, though:
> 
> int main() {
>      int a = 1;
> 
>      void *p1 = (void *) &a;
>      * (short *) p1 = 2;
> 
>      char *p2 = (char *) &a;
>      * (short *) p2 = 3;
> 
>      return a;
> }
> 
> This still returns 1 without a warning. (I am now using
> 4.1.0-20050723, so that I could try your patch.)

That is true.  I'm frankly not too sure what should be done.  If we
enable the warnings for these cases, the effect will be to warn about
almost every type cast which is not to or from void* or char*.  That
doesn't seem very useful.  On the other hand strict aliasing is a
serious problem.

Perhaps the problem is that the warning currently triggers on the
cast, but should perhaps somehow trigger on the dereference.  I think
the bug occurs if you have these statements:
    P2 = (TYPE *) P1;
    *P1;
    *P2;
in some order in the same function.  However, I don't know whether the
compiler has the data structures we would need to efficiently
determine whether this happens.

Could you please open a bugzilla PR for this at
http://gcc.gnu.org/bugzilla/ ?  That way at least the issue will get
recorded.  Thanks.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux