public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [wwwdocs] Describe behavior of -flifetime-dse in class constructors
@ 2016-02-16 14:55 Martin Liška
  2016-02-16 14:59 ` Kyrill Tkachov
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Martin Liška @ 2016-02-16 14:55 UTC (permalink / raw)
  To: GCC Patches; +Cc: jason, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

Hello.

As I finally hunted issue in Firefox that was responsible for start-up segfault, I would like
to describe a new behavior of the compiler that emits clobbers to class constructors (w/ -flifetime-dse).
As also Richi spotted quite similar issue in openjade package, I think it worth for mentioning in porting:

Ok?
Thanks,
Martin

[-- Attachment #2: porting_6-lifetime-dse.patch --]
[-- Type: text/x-patch, Size: 1945 bytes --]

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	16 Feb 2016 14:41:10 -0000
@@ -316,7 +316,7 @@
 </code></pre>
 
 <p>
-Finally, the type and mangling of flexible array members has changed
+Furthermore, the type and mangling of flexible array members has changed
 from previous releases.  While in GCC 5 and prior the type of a flexible
 array member is an array of zero elements (a GCC extension), in GCC 6 it
 is that of an array of an unspecified bound (i.e., <tt>T[]</tt> as opposed
@@ -324,6 +324,50 @@
 <tt>-fabi-version</tt> or <tt>-Wabi</tt> option to disable or warn about.
 </p>
 
+<p>
+Finally, the C++ compiler (with enabled <code>-flifetime-dse</code>)
+has been 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 &lt;stdlib.h&gt;
+#include &lt;string.h&gt;
+#include &lt;assert.h&gt;
+
+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-&gt;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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-06-20 10:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-16 14:55 [wwwdocs] Describe behavior of -flifetime-dse in class constructors Martin Liška
2016-02-16 14:59 ` Kyrill Tkachov
2016-02-16 16:55 ` Martin Sebor
2016-02-17 14:21   ` Martin Liška
2016-02-17 14:23     ` Jakub Jelinek
2016-02-17 15:01       ` Martin Liška
2016-02-25 10:01         ` Martin Liška
2016-02-25 10:07           ` Markus Trippelsdorf
2016-02-25 10:11             ` Markus Trippelsdorf
2016-06-20 10:30         ` Gerald Pfeifer
2016-06-20 10:34           ` Gerald Pfeifer
2016-02-19  4:52 ` Jan Hubicka
2016-02-25 11:22   ` Martin Liška
2016-02-28 21:43     ` Gerald Pfeifer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).