* [PATCH] Fix PR70054
@ 2016-03-03 12:36 Richard Biener
2016-03-04 7:28 ` Jeff Law
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2016-03-03 12:36 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: TEXT/PLAIN, Size: 3157 bytes --]
The following patch adjusts strict_aliasing_warning to use
proper alias_set_subset_of instead of relying on alias_sets_conflict_p
as after the PR66110 fix aggregates with a char[] member do not
automatically behave like having alias-set zero. As a side-effect
the test will be somewhat stricter as well accessing a 'long' with
a struct { int i; long l; } * will now warn while it previously
didn't:
struct S { int i; long l; };
long x;
struct S foo () { return *(struct S *)&x; }
now warns:
t.c: In function Β‘fooΒ’:
t.c:3:35: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
struct S foo () { return *(struct S *)&x; }
^
Bootstrap and regtest running on x86_64-unknown-linux-gnu, ok for trunk?
Thanks,
Richard.
2016-03-03 Richard Biener <rguenther@suse.de>
PR c++/70054
* c-common.c (strict_aliasing_warning): Use alias_set_subset_of
instead of alias_sets_conflict_p.
* g++.dg/warn/Wstrict-aliasing-bogus-union-2.C: New testcase.
* gcc.dg/Wstrict-aliasing-struct-member.c: New testcase.
Index: gcc/c-family/c-common.c
===================================================================
*** gcc/c-family/c-common.c (revision 233902)
--- gcc/c-family/c-common.c (working copy)
*************** strict_aliasing_warning (tree otype, tre
*** 1568,1574 ****
alias_set_type set2 = get_alias_set (TREE_TYPE (type));
if (set1 != set2 && set2 != 0
! && (set1 == 0 || !alias_sets_conflict_p (set1, set2)))
{
warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
"pointer will break strict-aliasing rules");
--- 1568,1574 ----
alias_set_type set2 = get_alias_set (TREE_TYPE (type));
if (set1 != set2 && set2 != 0
! && (set1 == 0 || !alias_set_subset_of (set2, set1)))
{
warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
"pointer will break strict-aliasing rules");
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C
===================================================================
*** gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C (revision 0)
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C (working copy)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile { target c++11 } } */
+ /* { dg-options "-Wstrict-aliasing=2 -O2 -Wall" } */
+
+ #include <type_traits>
+
+ struct foo
+ {
+ std::aligned_storage<sizeof(long), alignof(long)>::type raw;
+
+ long& cooked()
+ {
+ return *static_cast<long*>(static_cast<void*>(&raw)); /* { dg-bogus "strict-aliasing" } */
+ }
+ };
Index: gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c
===================================================================
--- gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c (working copy)
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct S { int i; long l; };
+long x;
+struct S foo () { return *(struct S *)&x; } /* { dg-warning "will break strict-aliasing" } */
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix PR70054
2016-03-03 12:36 [PATCH] Fix PR70054 Richard Biener
@ 2016-03-04 7:28 ` Jeff Law
2016-03-04 8:26 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2016-03-04 7:28 UTC (permalink / raw)
To: Richard Biener, gcc-patches
On 03/03/2016 05:35 AM, Richard Biener wrote:
>
> The following patch adjusts strict_aliasing_warning to use
> proper alias_set_subset_of instead of relying on alias_sets_conflict_p
> as after the PR66110 fix aggregates with a char[] member do not
> automatically behave like having alias-set zero. As a side-effect
> the test will be somewhat stricter as well accessing a 'long' with
> a struct { int i; long l; } * will now warn while it previously
> didn't:
>
> struct S { int i; long l; };
> long x;
> struct S foo () { return *(struct S *)&x; }
>
> now warns:
>
> t.c: In function Β‘fooΒ’:
> t.c:3:35: warning: dereferencing type-punned pointer will break
> strict-aliasing rules [-Wstrict-aliasing]
> struct S foo () { return *(struct S *)&x; }
> ^
> Bootstrap and regtest running on x86_64-unknown-linux-gnu, ok for trunk?
>
> Thanks,
> Richard.
>
> 2016-03-03 Richard Biener <rguenther@suse.de>
>
> PR c++/70054
> * c-common.c (strict_aliasing_warning): Use alias_set_subset_of
> instead of alias_sets_conflict_p.
>
> * g++.dg/warn/Wstrict-aliasing-bogus-union-2.C: New testcase.
> * gcc.dg/Wstrict-aliasing-struct-member.c: New testcase.
The PR doesn't have a regression marker, but from reading the PR it's
clearly a regression.
OK for the trunk,
Thanks,
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix PR70054
2016-03-04 7:28 ` Jeff Law
@ 2016-03-04 8:26 ` Richard Biener
0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2016-03-04 8:26 UTC (permalink / raw)
To: Jeff Law; +Cc: gcc-patches
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1505 bytes --]
On Fri, 4 Mar 2016, Jeff Law wrote:
> On 03/03/2016 05:35 AM, Richard Biener wrote:
> >
> > The following patch adjusts strict_aliasing_warning to use
> > proper alias_set_subset_of instead of relying on alias_sets_conflict_p
> > as after the PR66110 fix aggregates with a char[] member do not
> > automatically behave like having alias-set zero. As a side-effect
> > the test will be somewhat stricter as well accessing a 'long' with
> > a struct { int i; long l; } * will now warn while it previously
> > didn't:
> >
> > struct S { int i; long l; };
> > long x;
> > struct S foo () { return *(struct S *)&x; }
> >
> > now warns:
> >
> > t.c: In function Β‘fooΒ’:
> > t.c:3:35: warning: dereferencing type-punned pointer will break
> > strict-aliasing rules [-Wstrict-aliasing]
> > struct S foo () { return *(struct S *)&x; }
> > ^
> > Bootstrap and regtest running on x86_64-unknown-linux-gnu, ok for trunk?
> >
> > Thanks,
> > Richard.
> >
> > 2016-03-03 Richard Biener <rguenther@suse.de>
> >
> > PR c++/70054
> > * c-common.c (strict_aliasing_warning): Use alias_set_subset_of
> > instead of alias_sets_conflict_p.
> >
> > * g++.dg/warn/Wstrict-aliasing-bogus-union-2.C: New testcase.
> > * gcc.dg/Wstrict-aliasing-struct-member.c: New testcase.
> The PR doesn't have a regression marker, but from reading the PR it's clearly
> a regression.
Yes, it is - sorry for not updating the bugzilla appropriately.
> OK for the trunk,
Thanks,
Richard.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-04 8:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-03 12:36 [PATCH] Fix PR70054 Richard Biener
2016-03-04 7:28 ` Jeff Law
2016-03-04 8:26 ` Richard Biener
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).