public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics
@ 2012-03-17 12:30 pluto at agmk dot net
2012-03-17 22:03 ` [Bug other/52609] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: pluto at agmk dot net @ 2012-03-17 12:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609
Bug #: 52609
Summary: -Wstrict-aliasing / missed diagnostics
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: pluto@agmk.net
Target: x86_64-gnu-linux
void bug1( unsigned* buffer, int index, float w )
{
*(float*)(&buffer[index])=w;
}
void bug2( unsigned* buffer, int index, float w )
{
float* ptr=(float*)&buffer[index];
*ptr=w;
}
accessing unsigned* via float* looks buggy but
$ gcc48 -Wall -Wstrict-aliasing=3 -Wextra -fstrict-aliasing -O2 -S alias-bug.c
reports no warnings.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/52609] -Wstrict-aliasing / missed diagnostics
2012-03-17 12:30 [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics pluto at agmk dot net
@ 2012-03-17 22:03 ` pinskia at gcc dot gnu.org
2012-03-18 12:53 ` pluto at agmk dot net
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-03-17 22:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-03-17 21:57:19 UTC ---
>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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/52609] -Wstrict-aliasing / missed diagnostics
2012-03-17 12:30 [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics pluto at agmk dot net
2012-03-17 22:03 ` [Bug other/52609] " pinskia at gcc dot gnu.org
@ 2012-03-18 12:53 ` pluto at agmk dot net
2012-03-19 10:57 ` rguenth at gcc dot gnu.org
2012-10-23 18:47 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pluto at agmk dot net @ 2012-03-18 12:53 UTC (permalink / raw)
To: gcc-bugs
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]
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/52609] -Wstrict-aliasing / missed diagnostics
2012-03-17 12:30 [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics pluto at agmk dot net
2012-03-17 22:03 ` [Bug other/52609] " pinskia at gcc dot gnu.org
2012-03-18 12:53 ` pluto at agmk dot net
@ 2012-03-19 10:57 ` rguenth at gcc dot gnu.org
2012-10-23 18:47 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-03-19 10:57 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/52609] -Wstrict-aliasing / missed diagnostics
2012-03-17 12:30 [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics pluto at agmk dot net
` (2 preceding siblings ...)
2012-03-19 10:57 ` rguenth at gcc dot gnu.org
@ 2012-10-23 18:47 ` manu at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-23 18:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52609
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dilyan.palauzov at aegee
| |dot org
--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-23 18:47:08 UTC ---
*** Bug 55040 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-10-23 18:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-17 12:30 [Bug other/52609] New: -Wstrict-aliasing / missed diagnostics pluto at agmk dot net
2012-03-17 22:03 ` [Bug other/52609] " pinskia at gcc dot gnu.org
2012-03-18 12:53 ` pluto at agmk dot net
2012-03-19 10:57 ` rguenth at gcc dot gnu.org
2012-10-23 18:47 ` manu at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).