]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/70054 (GCC 6 gives a strict-aliasing warning on use of std::aligned_...
authorRichard Biener <rguenther@suse.de>
Fri, 4 Mar 2016 08:31:19 +0000 (08:31 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 4 Mar 2016 08:31:19 +0000 (08:31 +0000)
2016-03-04  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.

From-SVN: r233961

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union-2.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wstrict-aliasing-struct-member.c [new file with mode: 0644]

index 7a5e323cc4db174f3963055fdcf4f2e020afa8e6..5c777b6ecee155ea31cb81ef11e235d81f529658 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-04  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.
+
 2016-03-01  Marek Polacek  <polacek@redhat.com>
 
        PR c++/69795
index 22ea7dafe42b9ac757a033fb4edf71eed90d065a..965cf493699a7950c78f7d7af04c50d00f83895f 100644 (file)
@@ -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");
index 3627140b8da4c17d2ae700909692582fc2069de3..dfa91cdefdc092fe5be12b9eb492bb484d784085 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-04  Richard Biener  <rguenther@suse.de>
+
+       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  <vogt@linux.vnet.ibm.com>
 
        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 (file)
index 0000000..2b4895a
--- /dev/null
@@ -0,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" } */
+    }
+};
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 (file)
index 0000000..6c5e88d
--- /dev/null
@@ -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" } */