re PR c++/80593 (GCC 7, aligned_storage and “dereferencing type-punned pointer will...
authorRichard Biener <rguenther@suse.de>
Fri, 19 May 2017 12:34:54 +0000 (12:34 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 19 May 2017 12:34:54 +0000 (12:34 +0000)
2017-05-19  Richard Biener  <rguenther@suse.de>

PR c++/80593
* c-warn.c (strict_aliasing_warning): Do not warn for accesses
to alias-set zero memory.

* g++.dg/warn/Wstrict-aliasing-bogus-char-2.C: New testcase.
* g++.dg/warn/Wstrict-aliasing-6.C: Adjust expected outcome.

From-SVN: r248269

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

index 8287876d38eb9294f8f1d7855487731f69c4079d..4ce70e4d67a35996d5c503e5e528eb1973da9ddd 100644 (file)
@@ -1,3 +1,9 @@
+2017-05-19  Richard Biener  <rguenther@suse.de>
+
+       PR c++/80593
+       * c-warn.c (strict_aliasing_warning): Do not warn for accesses
+       to alias-set zero memory.
+
 2017-05-18  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * c-format.c (local_tree_type_node): Add GTY attribute.
index 1b2a8d89ff2bc784de9aa08d369bd2f6f1220aa0..e67ffb77bd9aa61a7a38892973dab4cdcccf1530 100644 (file)
@@ -537,10 +537,10 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
            = get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
          alias_set_type set2 = get_alias_set (TREE_TYPE (type));
 
-         if (set1 != set2 && set2 != 0
-             && (set1 == 0
-                 || (!alias_set_subset_of (set2, set1)
-                     && !alias_sets_conflict_p (set1, set2))))
+         if (set2 != 0
+             && set1 != set2
+             && !alias_set_subset_of (set2, set1)
+             && !alias_sets_conflict_p (set1, set2))
            {
              warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
                       "pointer will break strict-aliasing rules");
index 29a19ccbf2a2df79d7eaaa371986b4956941d793..a8adc9195061ba54374ee5279b9f5b8d67540984 100644 (file)
@@ -1,3 +1,9 @@
+2017-05-19  Richard Biener  <rguenther@suse.de>
+
+       PR c++/80593
+       * g++.dg/warn/Wstrict-aliasing-bogus-char-2.C: New testcase.
+       * g++.dg/warn/Wstrict-aliasing-6.C: Adjust expected outcome.
+
 2017-05-19  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/80764
index 6f935c8540bf8aefd4aa3312777816b96fbc0f7e..2d1a95bde1295c4a43442a9f88a3b81364b7aab9 100644 (file)
@@ -4,6 +4,6 @@
 int foo ()
 {
   char buf[8];
-  return *((int *)buf); /* { dg-warning "strict-aliasing" } */
+  return *((int *)buf); /* { dg-bogus "strict-aliasing" } */
 }
 
diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-2.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-2.C
new file mode 100644 (file)
index 0000000..0f04bf1
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-O2 -Wstrict-aliasing" }
+
+template<unsigned _Len, unsigned _Align>
+struct aligned_storage
+{
+  union type
+    {
+      unsigned char __data[_Len];
+      struct __attribute__((__aligned__((_Align)))) { } __align;
+    };
+};
+
+aligned_storage<sizeof(int), __alignof__(int)>::type storage;
+
+int main()
+{
+  *reinterpret_cast<int*>(&storage) = 42; // { dg-bogus "break strict-aliasing" }
+}