re PR c++/70259 (-flifetime-dse=2 bug with empty bases)
authorJason Merrill <jason@redhat.com>
Wed, 16 Mar 2016 19:37:22 +0000 (15:37 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 16 Mar 2016 19:37:22 +0000 (15:37 -0400)
PR c++/70259
* decl.c (start_preparsed_function): Don't clobber an empty base.

From-SVN: r234267

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/opt/flifetime-dse5.C [new file with mode: 0644]

index b1424136a08f96995794ac7de59d4c16eeae47a0..ac7387846feeefb2e8391b3b6c1334c768674be4 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-16  Jason Merrill  <jason@redhat.com>
+
+       PR c++/70259
+       * decl.c (start_preparsed_function): Don't clobber an empty base.
+
 2016-03-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/70147
index 27c3597a570215e0fcac3e7f6e5a44001fdbaeaf..216d7268c280e95457b07f61b6916cbed5f26f33 100644 (file)
@@ -14121,6 +14121,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
       && (flag_lifetime_dse > 1)
       && DECL_CONSTRUCTOR_P (decl1)
       && !DECL_CLONED_FUNCTION_P (decl1)
+      /* Clobbering an empty base is harmful if it overlays real data.  */
+      && !is_empty_class (current_class_type)
       /* We can't clobber safely for an implicitly-defined default constructor
         because part of the initialization might happen before we enter the
         constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
diff --git a/gcc/testsuite/g++.dg/opt/flifetime-dse5.C b/gcc/testsuite/g++.dg/opt/flifetime-dse5.C
new file mode 100644 (file)
index 0000000..2c49021
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/70259
+// { dg-options -O2 }
+// { dg-do run }
+
+struct Empty { };
+struct A { A() : a(true) { } bool a; };
+struct B : Empty { B() : Empty() { } };
+struct C : A, B { C() : A(), B() { } };
+int main() {
+  C c;
+  if ( c.a == false )
+    __builtin_abort();
+};