From e9a35493b0811bd6dd2584dbe79e7e1dca4e1722 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 4 Mar 2016 08:31:19 +0000 Subject: [PATCH] re PR middle-end/70054 (GCC 6 gives a strict-aliasing warning on use of std::aligned_storage) 2016-03-04 Richard Biener 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. From-SVN: r233961 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 2 +- gcc/testsuite/ChangeLog | 6 ++++++ .../g++.dg/warn/Wstrict-aliasing-bogus-union-2.C | 14 ++++++++++++++ .../gcc.dg/Wstrict-aliasing-struct-member.c | 6 ++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C create mode 100644 gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 7a5e323cc4d..5c777b6ecee 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2016-03-04 Richard Biener + + PR c++/70054 + * c-common.c (strict_aliasing_warning): Use alias_set_subset_of + instead of alias_sets_conflict_p. + 2016-03-01 Marek Polacek PR c++/69795 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 22ea7dafe42..965cf493699 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -1568,7 +1568,7 @@ strict_aliasing_warning (tree otype, tree type, tree expr) alias_set_type set2 = get_alias_set (TREE_TYPE (type)); if (set1 != set2 && set2 != 0 - && (set1 == 0 || !alias_sets_conflict_p (set1, set2))) + && (set1 == 0 || !alias_set_subset_of (set2, set1))) { warning (OPT_Wstrict_aliasing, "dereferencing type-punned " "pointer will break strict-aliasing rules"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3627140b8da..dfa91cdefdc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-03-04 Richard Biener + + PR c++/70054 + * g++.dg/warn/Wstrict-aliasing-bogus-union-2.C: New testcase. + * gcc.dg/Wstrict-aliasing-struct-member.c: New testcase. + 2016-03-04 Dominik Vogt PR testsuite/69766 diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C new file mode 100644 index 00000000000..2b4895aea97 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C @@ -0,0 +1,14 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-options "-Wstrict-aliasing=2 -O2 -Wall" } */ + +#include + +struct foo +{ + std::aligned_storage::type raw; + + long& cooked() + { + return *static_cast(static_cast(&raw)); /* { dg-bogus "strict-aliasing" } */ + } +}; diff --git a/gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c b/gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c new file mode 100644 index 00000000000..6c5e88d856c --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c @@ -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" } */ -- 2.30.2