diff mbox

PR c++/80287 backport on GCC 6 branch

Message ID CAD57uCfcRMfLkU84M=annkv7H79t0SUthnkT8euuascvFcFMFA@mail.gmail.com
State New
Headers show

Commit Message

Yvan Roux Aug. 24, 2017, 12:33 p.m. UTC
Hi,

As described in the PR, gcc-6-branch is impacted by this issue.  This
patch backports the original fix from Bernd and the recently added
testcase (which does not rely on c++17 features).

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80287
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00730.html

Bootstrapped and regression tested on x86, ARM and AArch64 targets.
Ok for gcc-6-branch ?

Thanks,
Yvan

2017-08-24  Yvan Roux  <yvan.roux@linaro.org>

    PR c++/80287 C++ crash with __attribute((may_alias))

    Backport from mainline
    2017-04-17  Bernd Edlinger  <bernd.edlinger@hotmail.de>

            PR c++/80287
            * class.c (fixup_may_alias): Fix all type variants.

    gcc/testsuite
    2017-08-22  Yvan Roux  <yvan.roux@linaro.org>

            PR c++/80287
            * g++.dg/pr8028.C: New test.

Comments

Nathan Sidwell Aug. 24, 2017, 1:01 p.m. UTC | #1
On 08/24/2017 08:33 AM, Yvan Roux wrote:
> Hi,

> 

> As described in the PR, gcc-6-branch is impacted by this issue.  This

> patch backports the original fix from Bernd and the recently added

> testcase (which does not rely on c++17 features).

> 

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80287

> https://gcc.gnu.org/ml/gcc-patches/2017-07/msg00730.html

> 

> Bootstrapped and regression tested on x86, ARM and AArch64 targets.

> Ok for gcc-6-branch ?


ok


-- 
Nathan Sidwell
diff mbox

Patch

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 35deb1e99cd..86e7e003fe4 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -1999,12 +1999,14 @@  fixup_type_variants (tree t)
 static void
 fixup_may_alias (tree klass)
 {
-  tree t;
+  tree t, v;
 
   for (t = TYPE_POINTER_TO (klass); t; t = TYPE_NEXT_PTR_TO (t))
-    TYPE_REF_CAN_ALIAS_ALL (t) = true;
+    for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
+      TYPE_REF_CAN_ALIAS_ALL (v) = true;
   for (t = TYPE_REFERENCE_TO (klass); t; t = TYPE_NEXT_REF_TO (t))
-    TYPE_REF_CAN_ALIAS_ALL (t) = true;
+    for (v = TYPE_MAIN_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
+      TYPE_REF_CAN_ALIAS_ALL (v) = true;
 }
 
 /* Early variant fixups: we apply attributes at the beginning of the class
diff --git a/gcc/testsuite/g++.dg/pr80287.C b/gcc/testsuite/g++.dg/pr80287.C
new file mode 100644
index 00000000000..da8d3fab150
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr80287.C
@@ -0,0 +1,13 @@ 
+// PR c++/80287
+// { dg-do compile { target c++11 } }
+// { dg-options "-g" }
+
+struct A {
+  operator long() {}
+} __attribute__((__may_alias__));
+
+struct {
+  A ino;
+} a;
+
+char b = a.ino;