]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Add -flifetime-dse=1.
authorJason Merrill <jason@redhat.com>
Wed, 24 Feb 2016 15:18:04 +0000 (10:18 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 24 Feb 2016 15:18:04 +0000 (10:18 -0500)
gcc/
* common.opt (flifetime-dse): Add -flifetime-dse=1.
gcc/cp/
* decl.c (start_preparsed_function): Condition ctor clobber on
flag_lifetime_dse > 1.

From-SVN: r233672

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

index 0c2c960612c93b240909c5968c5c9e1bc3424879..913abc87b8ecd558a23fef12a60a42f0dbbadab0 100644 (file)
@@ -1,3 +1,7 @@
+2016-02-24  Jason Merrill  <jason@redhat.com>
+
+       * common.opt (flifetime-dse): Add -flifetime-dse=1.
+
 2016-02-24  Richard Biener  <rguenther@suse.de>
        Jakub Jelinek  <jakub@redhat.com>
 
index bc5b4c4e96b979bfc7ea89065e8899d72b0a85e6..e91f2257e55d45a16a5b75aeb0900cf71dfbfbca 100644 (file)
@@ -1946,10 +1946,13 @@ Common Ignore
 Does nothing. Preserved for backward compatibility.
 
 flifetime-dse
-Common Report Var(flag_lifetime_dse) Init(1) Optimization
+Common Report Var(flag_lifetime_dse,2) Init(2) Optimization
 Tell DSE that the storage for a C++ object is dead when the constructor
 starts and when the destructor finishes.
 
+flifetime-dse=
+Common Joined RejectNegative UInteger Var(flag_lifetime_dse) Optimization
+
 flive-range-shrinkage
 Common Report Var(flag_live_range_shrinkage) Init(0) Optimization
 Relief of register pressure through live range shrinkage.
index 582fd076189d85695283790770a7a6aa53add47f..6212d4343db34f84a276b2958c2105e874c0b657 100644 (file)
@@ -1,5 +1,8 @@
 2016-02-24  Jason Merrill  <jason@redhat.com>
 
+       * decl.c (start_preparsed_function): Condition ctor clobber on
+       flag_lifetime_dse > 1.
+
        * cp-gimplify.c (cp_fold): Don't fold constexpr calls if -fno-inline.
 
 2016-02-19  Jason Merrill  <jason@redhat.com>
index 30eef5ca664bc3dfb55a51b3f061ba87dedf06d6..2df3398d6c03e2d8a0c9ffb507a6f32c06b2c6f7 100644 (file)
@@ -14104,7 +14104,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
   store_parm_decls (current_function_parms);
 
   if (!processing_template_decl
-      && flag_lifetime_dse && DECL_CONSTRUCTOR_P (decl1)
+      && (flag_lifetime_dse > 1)
+      && DECL_CONSTRUCTOR_P (decl1)
       /* 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).  */
index 9ca379369021f157da86584246b9bfa3d120b718..b8b2e7060d9d4a28a2a2fbe93cf5eb917e1fa789 100644 (file)
@@ -6809,7 +6809,10 @@ 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.
+flag to disable this optimization.  To preserve stores before the
+constructor starts (e.g. because your operator new clears the object
+storage) but still treat the object as dead after the destructor you,
+can use -flifetime-dse=1.
 
 @item -flive-range-shrinkage
 @opindex flive-range-shrinkage
diff --git a/gcc/testsuite/g++.dg/opt/flifetime-dse4.C b/gcc/testsuite/g++.dg/opt/flifetime-dse4.C
new file mode 100644 (file)
index 0000000..c72444a
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-options "-O3 -flifetime-dse=1" }
+// { 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] = { 42 };
+  A* ap = new(ar) A;
+
+  // With -flifetime-dse=1 we retain the old value.
+  if (ap->i != 42) __builtin_abort();
+
+  ap->i = 42;
+  ap->~A();
+
+  // When the destructor ends the object no longer exists.
+  if (ar[0] == 42) __builtin_abort();
+}