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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  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-19  4:52 ` Jan Hubicka
  2 siblings, 0 replies; 14+ messages in thread
From: Kyrill Tkachov @ 2016-02-16 14:59 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: jason, Jan Hubicka


On 16/02/16 14:55, Martin Liška wrote:
> 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

  <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:

Minor nit, but I notice we have a different "Finally" point now ;).
Perhaps we shouldn't bother saying "finally" as we keep finding new entries for this list.

Thanks,
Kyrill

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  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-19  4:52 ` Jan Hubicka
  2 siblings, 1 reply; 14+ messages in thread
From: Martin Sebor @ 2016-02-16 16:55 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: jason, Jan Hubicka

On 02/16/2016 07:55 AM, Martin Liška wrote:
> 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:

I think the new text deserves a new heading of its own rather than
being added under the existing "Stricter flexible array member rules."
(The "Finally..." part changed by the patch still applies to the
flexible array members.)

Martin

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-16 16:55 ` Martin Sebor
@ 2016-02-17 14:21   ` Martin Liška
  2016-02-17 14:23     ` Jakub Jelinek
  0 siblings, 1 reply; 14+ messages in thread
From: Martin Liška @ 2016-02-17 14:21 UTC (permalink / raw)
  To: Martin Sebor, GCC Patches; +Cc: jason, Jan Hubicka

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

On 02/16/2016 05:55 PM, Martin Sebor wrote:
> I think the new text deserves a new heading of its own rather than
> being added under the existing "Stricter flexible array member rules."
> (The "Finally..." part changed by the patch still applies to the
> flexible array members.)
> 
> Martin

Hi Martin.

Thanks for the nit, fixed in v2.

Ready to be installed?
Martin

[-- Attachment #2: porting_6-lifetime-dse_v2.patch --]
[-- Type: text/x-patch, Size: 1598 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	17 Feb 2016 14:20:13 -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>)
+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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-17 14:21   ` Martin Liška
@ 2016-02-17 14:23     ` Jakub Jelinek
  2016-02-17 15:01       ` Martin Liška
  0 siblings, 1 reply; 14+ messages in thread
From: Jakub Jelinek @ 2016-02-17 14:23 UTC (permalink / raw)
  To: Martin Liška; +Cc: Martin Sebor, GCC Patches, jason, Jan Hubicka

On Wed, Feb 17, 2016 at 03:21:07PM +0100, Martin Liška wrote:
> --- htdocs/gcc-6/porting_to.html	14 Feb 2016 13:13:43 -0000	1.14
> +++ htdocs/gcc-6/porting_to.html	17 Feb 2016 14:20:13 -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>)
> +has been more aggressive in dead-store elimination in situations where

"has been" looks weird.  I'd say that the C++ compiler is now more
aggressive...

	Jakub

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-17 14:23     ` Jakub Jelinek
@ 2016-02-17 15:01       ` Martin Liška
  2016-02-25 10:01         ` Martin Liška
  2016-06-20 10:30         ` Gerald Pfeifer
  0 siblings, 2 replies; 14+ messages in thread
From: Martin Liška @ 2016-02-17 15:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Martin Sebor, GCC Patches, jason, Jan Hubicka

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

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...
> 
> 	Jakub

Sending v3.

M.

[-- Attachment #2: porting_6-lifetime-dse_v3.patch --]
[-- Type: text/x-patch, Size: 1592 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	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 &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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  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-19  4:52 ` Jan Hubicka
  2016-02-25 11:22   ` Martin Liška
  2 siblings, 1 reply; 14+ messages in thread
From: Jan Hubicka @ 2016-02-19  4:52 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, jason, Jan Hubicka

> 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:

Hi,
thank you for working this out and writting summary. I think in a shorter form this would make
excellent entry for changes.html, too.  We tell about the new feature and warn users about fallout
that is always good.

Honza
> 
> Ok?
> Thanks,
> Martin

> 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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-17 15:01       ` Martin Liška
@ 2016-02-25 10:01         ` Martin Liška
  2016-02-25 10:07           ` Markus Trippelsdorf
  2016-06-20 10:30         ` Gerald Pfeifer
  1 sibling, 1 reply; 14+ messages in thread
From: Martin Liška @ 2016-02-25 10:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Martin Sebor, GCC Patches, jason, Jan Hubicka

On 02/17/2016 04:01 PM, 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...
>>
>> 	Jakub
> 
> Sending v3.
> 
> M.
> 

Hi.

I've been thinking if the suggested patch makes sense any longer after the following patch was applied:
https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01651.html ?

Martin

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-25 10:01         ` Martin Liška
@ 2016-02-25 10:07           ` Markus Trippelsdorf
  2016-02-25 10:11             ` Markus Trippelsdorf
  0 siblings, 1 reply; 14+ messages in thread
From: Markus Trippelsdorf @ 2016-02-25 10:07 UTC (permalink / raw)
  To: Martin Liška
  Cc: Jakub Jelinek, Martin Sebor, GCC Patches, jason, Jan Hubicka

On 2016.02.25 at 11:01 +0100, Martin Liška wrote:
> On 02/17/2016 04:01 PM, 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...
> >>
> I've been thinking if the suggested patch makes sense any longer after
> the following patch was applied:
> https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01651.html ?

It still makes sense, just replace -fno-lifetime-dse with
-fno-lifetime-dse=1.

-- 
Markus

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-25 10:07           ` Markus Trippelsdorf
@ 2016-02-25 10:11             ` Markus Trippelsdorf
  0 siblings, 0 replies; 14+ messages in thread
From: Markus Trippelsdorf @ 2016-02-25 10:11 UTC (permalink / raw)
  To: Martin Liška
  Cc: Jakub Jelinek, Martin Sebor, GCC Patches, jason, Jan Hubicka

On 2016.02.25 at 11:07 +0100, Markus Trippelsdorf wrote:
> On 2016.02.25 at 11:01 +0100, Martin Liška wrote:
> > On 02/17/2016 04:01 PM, 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...
> > >>
> > I've been thinking if the suggested patch makes sense any longer after
> > the following patch was applied:
> > https://gcc.gnu.org/ml/gcc-patches/2016-02/msg01651.html ?
> 
> It still makes sense, just replace -fno-lifetime-dse with
> -fno-lifetime-dse=1.

Err, I mean -flifetime-dse=1 of course.

-- 
Markus

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-19  4:52 ` Jan Hubicka
@ 2016-02-25 11:22   ` Martin Liška
  2016-02-28 21:43     ` Gerald Pfeifer
  0 siblings, 1 reply; 14+ messages in thread
From: Martin Liška @ 2016-02-25 11:22 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches, jason

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

On 02/19/2016 05:52 AM, Jan Hubicka wrote:
> Hi,
> thank you for working this out and writting summary. I think in a shorter form this would make
> excellent entry for changes.html, too.  We tell about the new feature and warn users about fallout
> that is always good.

Good idea.

That's a suggestion for changes.html.

Ready to be installed?
Martin

[-- Attachment #2: gcc-6-changes-lifetime-dse.patch --]
[-- Type: text/x-patch, Size: 824 bytes --]

Index: htdocs/gcc-6/changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
retrieving revision 1.62
diff --unified -r1.62 changes.html
--- htdocs/gcc-6/changes.html	24 Feb 2016 09:36:06 -0000	1.62
+++ htdocs/gcc-6/changes.html	25 Feb 2016 11:21:42 -0000
@@ -230,6 +230,10 @@
     <li>The default mode has been changed to <code>-std=gnu++14</code>.</li>
     <li>C++ Concepts are now supported when compiling with
         <code>-std=gnu++1z</code> or <code>-std=c++1z</code>.</li>
+    <li><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.</li>
   </ul>
 
 <h4 id="libstdcxx">Runtime Library (libstdc++)</h4>

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-25 11:22   ` Martin Liška
@ 2016-02-28 21:43     ` Gerald Pfeifer
  0 siblings, 0 replies; 14+ messages in thread
From: Gerald Pfeifer @ 2016-02-28 21:43 UTC (permalink / raw)
  To: Martin Liška; +Cc: Jan Hubicka, gcc-patches, Jason Merrill

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

On Thu, 25 Feb 2016, Martin Liška wrote:
> That's a suggestion for changes.html.
> 
> Ready to be installed?

Works for me, Martin, but please give Jason a day or two to comment.

Thanks,
Gerald

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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-02-17 15:01       ` Martin Liška
  2016-02-25 10:01         ` Martin Liška
@ 2016-06-20 10:30         ` Gerald Pfeifer
  2016-06-20 10:34           ` Gerald Pfeifer
  1 sibling, 1 reply; 14+ messages in thread
From: Gerald Pfeifer @ 2016-06-20 10:30 UTC (permalink / raw)
  To: Martin Liška
  Cc: Jakub Jelinek, Martin Sebor, gcc-patches, Jason Merrill, Jan Hubicka

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

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 &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

* Re: [wwwdocs] Describe behavior of -flifetime-dse in class constructors
  2016-06-20 10:30         ` Gerald Pfeifer
@ 2016-06-20 10:34           ` Gerald Pfeifer
  0 siblings, 0 replies; 14+ messages in thread
From: Gerald Pfeifer @ 2016-06-20 10:34 UTC (permalink / raw)
  To: Martin Liška
  Cc: Jakub Jelinek, Martin Sebor, gcc-patches, Jason Merrill, Jan Hubicka

On Mon, 20 Jun 2016, Gerald Pfeifer wrote:
> 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?

And here is one small change I just applied...

Gerald

Index: changes.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/gcc-6/changes.html,v
retrieving revision 1.85
diff -u -r1.85 changes.html
--- changes.html	8 Jun 2016 15:00:53 -0000	1.85
+++ changes.html	20 Jun 2016 10:33:35 -0000
@@ -283,7 +283,7 @@
         <code>-fconcepts</code>.</li>
     <li><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
+    a memory store to a location precedes a constructor to that
     memory location.</li>
     <li>G++ now supports
         <a href="https://gcc.gnu.org/projects/cxx-status.html#cxx1z.html">C++17</a>

^ 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).