public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94337] New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
@ 2020-03-26 2:03 vincent-gcc at vinc17 dot net
2020-03-26 7:03 ` [Bug c/94337] " rguenth at gcc dot gnu.org
2020-03-26 9:12 ` vincent-gcc at vinc17 dot net
0 siblings, 2 replies; 3+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2020-03-26 2:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94337
Bug ID: 94337
Summary: Incorrect "dereferencing type-punned pointer will
break strict-aliasing rules" warning
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent-gcc at vinc17 dot net
Target Milestone: ---
Consider the following example.
#include <stdio.h>
struct s1
{
int a;
};
struct s2
{
int a, b;
};
int main (void)
{
union {
struct s1 m1[1];
struct s2 m2[1];
} u;
(u.m2)->b = 17;
printf ("%d\n", ((struct s2 *) (struct s1 *) u.m2)->b);
printf ("%d\n", ((struct s2 *) u.m1)->b);
return 0;
}
zira:~> gcc-10 tst.c -o tst -O2 -Wstrict-aliasing
tst.c: In function ‘main’:
tst.c:22:20: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
22 | printf ("%d\n", ((struct s2 *) u.m1)->b);
| ~^~~~~~~~~~~~~~~~~~~
But there is no type-punning here. All accesses are done via struct s2.
Everything else is pointer conversions, which are not related to the aliasing
rules.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-26 9:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26 2:03 [Bug c/94337] New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning vincent-gcc at vinc17 dot net
2020-03-26 7:03 ` [Bug c/94337] " rguenth at gcc dot gnu.org
2020-03-26 9:12 ` vincent-gcc at vinc17 dot net
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).