]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
common.opt (-flifetime-dse): New.
authorJason Merrill <jason@redhat.com>
Thu, 26 Feb 2015 02:43:52 +0000 (21:43 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 26 Feb 2015 02:43:52 +0000 (21:43 -0500)
gcc/
* common.opt (-flifetime-dse): New.
gcc/cp/
* decl.c (begin_destructor_body): Condition clobber on
-flifetime-dse.

From-SVN: r220996

gcc/ChangeLog
gcc/common.opt
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/doc/invoke.texi
gcc/testsuite/g++.dg/opt/flifetime-dse1.C [new file with mode: 0644]

index 326a98ddfb440fab13aae5f25508cf3105f30707..0d8f66fff7c725f08064fc1330af3e75c5c12417 100644 (file)
@@ -1,3 +1,7 @@
+2015-02-25  Jason Merrill  <jason@redhat.com>
+
+       * common.opt (-flifetime-dse): New.
+
 2015-02-25  Kai Tietz  <ktietz@redhat.com>
 
        PR tree-optimization/61917
index 2259f29d19e4531a12fb2fac5977d9bcb52b907d..51ddd77c9a9c34ad75914f1dcb9f831162050b96 100644 (file)
@@ -1745,6 +1745,11 @@ fregmove
 Common Ignore
 Does nothing. Preserved for backward compatibility.
 
+flifetime-dse
+Common Report Var(flag_lifetime_dse) Init(1) Optimization
+Tell DSE that the storage for a C++ object is dead when the constructor
+starts and when the destructor finishes.
+
 flive-range-shrinkage
 Common Report Var(flag_live_range_shrinkage) Init(0) Optimization
 Relief of register pressure through live range shrinkage
index 90f2923f99e102c0ac95ed55965a931faacb4769..30b1c3f24fd109c08c3a8d6db608d784c1a85556 100644 (file)
@@ -1,3 +1,8 @@
+2015-02-25  Jason Merrill  <jason@redhat.com>
+
+       * decl.c (begin_destructor_body): Condition clobber on
+       -flifetime-dse.
+
 2015-02-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/62017
index 631ce9191325e7496e9a2100272ea63c094e3e20..b0bbf9e4fb25c1a60e6e79d3eedc56fc01993bd3 100644 (file)
@@ -13667,15 +13667,19 @@ begin_destructor_body (void)
       initialize_vtbl_ptrs (current_class_ptr);
       finish_compound_stmt (compound_stmt);
 
-      /* Insert a cleanup to let the back end know that the object is dead
-        when we exit the destructor, either normally or via exception.  */
-      tree btype = CLASSTYPE_AS_BASE (current_class_type);
-      tree clobber = build_constructor (btype, NULL);
-      TREE_THIS_VOLATILE (clobber) = true;
-      tree bref = build_nop (build_reference_type (btype), current_class_ptr);
-      bref = convert_from_reference (bref);
-      tree exprstmt = build2 (MODIFY_EXPR, btype, bref, clobber);
-      finish_decl_cleanup (NULL_TREE, exprstmt);
+      if (flag_lifetime_dse)
+       {
+         /* Insert a cleanup to let the back end know that the object is dead
+            when we exit the destructor, either normally or via exception.  */
+         tree btype = CLASSTYPE_AS_BASE (current_class_type);
+         tree clobber = build_constructor (btype, NULL);
+         TREE_THIS_VOLATILE (clobber) = true;
+         tree bref = build_nop (build_reference_type (btype),
+                                current_class_ptr);
+         bref = convert_from_reference (bref);
+         tree exprstmt = build2 (MODIFY_EXPR, btype, bref, clobber);
+         finish_decl_cleanup (NULL_TREE, exprstmt);
+       }
 
       /* And insert cleanups for our bases and members so that they
         will be properly destroyed if we throw.  */
index 870e637f93df915a86a14451e56556b1d91c6691..1aea050d0cdd96696b9697b39dc800809d859a35 100644 (file)
@@ -7401,6 +7401,16 @@ registers after writing to their lower 32-bit half.
 Enabled for Alpha, AArch64 and x86 at levels @option{-O2},
 @option{-O3}, @option{-Os}.
 
+@item -fno-lifetime-dse
+@opindex fno-lifetime-dse
+In C++ the value of an object is only affected by changes within its
+lifetime: when the constructor begins, the object has an indeterminate
+value, and any changes during the lifetime of the object are dead when
+the object is destroyed.  Normally dead store elimination will take
+advantage of this; if your code relies on the value of the object
+storage persisting beyond the lifetime of the object, you can use this
+flag to disable this optimization.
+
 @item -flive-range-shrinkage
 @opindex flive-range-shrinkage
 Attempt to decrease register pressure through register live range
diff --git a/gcc/testsuite/g++.dg/opt/flifetime-dse1.C b/gcc/testsuite/g++.dg/opt/flifetime-dse1.C
new file mode 100644 (file)
index 0000000..733d28a
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-options "-O3 -fno-lifetime-dse" }
+// { dg-do run }
+
+typedef __SIZE_TYPE__ size_t;
+inline void * operator new (size_t, void *p) { return p; }
+
+struct A
+{
+  int i;
+  A() {}
+  ~A() {}
+};
+
+int main()
+{
+  int ar[1];
+
+  A* ap = new(ar) A;
+  ap->i = 42;
+  ap->~A();
+
+  if (ar[0] != 42) __builtin_abort();
+}