[Bug other/52609] -Wstrict-aliasing / missed diagnostics
rguenth at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 19 10:57:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609
--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-03-19 10:54:24 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > >accessing unsigned* via float* looks buggy
> >
> > It does not have to be if the original argument was originally of type float.
> > Aliasing is not about type of pointers but the type which is used to access and
> > such.
>
> ok, here's an updated testcase:
>
> $ cat alias-bug.c
> unsigned buffer[1];
>
> float bug1( unsigned u )
> {
> buffer[0]=u;
> return *(float*)(&buffer[0]); // warning.
> }
>
> float bug2( unsigned u )
> {
> buffer[0]=u;
> float* ptr=(float*)&buffer[0];
> return *ptr; // missed strict aliasing warning.
> }
>
> gcc repots warning only for bug1() and misses warning for bug2():
There is a duplicate bug for this somewhere. The warning machinery
only looks at a single stmt.
More information about the Gcc-bugs
mailing list