From: Richard Biener Date: Fri, 4 Mar 2016 08:31:19 +0000 (+0000) Subject: re PR middle-end/70054 (GCC 6 gives a strict-aliasing warning on use of std::aligned_... X-Git-Tag: basepoints/gcc-7~593 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9a35493b0811bd6dd2584dbe79e7e1dca4e1722;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 7a5e323cc4db..5c777b6ecee1 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 22ea7dafe42b..965cf493699a 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 3627140b8da4..dfa91cdefdc0 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 000000000000..2b4895aea97d --- /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 000000000000..6c5e88d856c9 --- /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" } */