This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug other/52609] -Wstrict-aliasing / missed diagnostics


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609

--- Comment #2 from Pawel Sikora <pluto at agmk dot net> 2012-03-18 09:32:03 UTC ---
(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():

$ gcc -Wall -Wstrict-aliasing=3 -O2 alias-bug.c -c
alias-bug.c: In function 'bug1':
alias-bug.c:6:2: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]