[wwwdocs] Describe behavior of -flifetime-dse in class constructors

Gerald Pfeifer gerald@pfeifer.com
Mon Jun 20 10:30:00 GMT 2016


Hi Martin,

On Wed, 17 Feb 2016, Martin Liška wrote:
> On 02/17/2016 03:23 PM, Jakub Jelinek wrote:
>> "has been" looks weird.  I'd say that the C++ compiler is now more
>> aggressive...
> Sending v3.

I know a short version of this was applied, but am wondering
whether to retain the example (and a note on -flifetime-dse=1),
both per the discussion in February?

Want to make those enhancements?

Gerald

Index: htdocs/gcc-6/porting_to.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/porting_to.html,v
retrieving revision 1.14
diff --unified -r1.14 porting_to.html
--- htdocs/gcc-6/porting_to.html	14 Feb 2016 13:13:43 -0000	1.14
+++ htdocs/gcc-6/porting_to.html	17 Feb 2016 15:00:35 -0000
@@ -324,6 +324,52 @@
 <tt>-fabi-version</tt> or <tt>-Wabi</tt> option to disable or warn about.
 </p>
 
+<h3>More aggressive optimization of <code>-flifetime-dse</code></h3>
+
+<p>
+The C++ compiler (with enabled <code>-flifetime-dse</code>)
+is more aggressive in dead-store elimination in situations where
+a memory store to a location precedes a constructor to the
+memory location. Described situation can be commonly found in programs
+which zero a memory that is eventually passed to a placement new operator:
+
+<pre><code>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+struct A
+{
+  A () {}
+  void *operator new (size_t s)
+  {
+    void *ptr = malloc (s);
+    memset (ptr, 0, s);
+    return ptr;
+  }
+
+  int value;
+};
+
+A *
+__attribute__ ((noinline))
+build (void)
+{
+  return new A ();
+}
+
+int main()
+{
+  A *a =  build ();
+  assert (a->value == 0); /* Use of uninitialized value */
+  free (a);
+}
+</code></pre>
+
+If the program cannot be fixed to remove the undefined behavior then
+the option <code>-fno-lifetime-dse</code> can be used to disable
+this optimization.
+
 <h2>-Wmisleading-indentation</h2>
 <p>
 A new warning <code>-Wmisleading-indentation</code> was added


More information about the Gcc-patches mailing list