<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>(remembering to cc the list this time)<br>
</p>
<div class="moz-cite-prefix">On 12/3/18 8:02 PM, Hal Finkel wrote:<br>
</div>
<blockquote type="cite" cite="mid:1bfe6ac2-c094-5d09-b090-22184c781e07@anl.gov">
<div class="moz-cite-prefix">On 12/3/18 7:44 PM, via cfe-dev wrote:<br>
</div>
<blockquote type="cite" cite="mid:44903361AB618F4EA43589941BAC06BF0105640103@USCULXMSG05.am.sony.com">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">A commit earlier this year, r325630, changed the behavior of the following program under –O1:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-----------------------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">#include <new><o:p></o:p></p>
<p class="MsoNormal">#include <stdlib.h><o:p></o:p></p>
<p class="MsoNormal">extern "C" int printf(const char *, ...);<o:p></o:p></p>
<p class="MsoNormal">int UsedMyCode = 0;<o:p></o:p></p>
<p class="MsoNormal">void * operator new(std::size_t count)<o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal"> UsedMyCode = 1;<o:p></o:p></p>
<p class="MsoNormal"> return malloc(count);<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal">int main(int argc, char * argv[])<o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal"> int* p = new int();<o:p></o:p></p>
<p class="MsoNormal"> *p = 10;<o:p></o:p></p>
<p class="MsoNormal"> printf("*p=%d. UsedMyCode=%d\n", *p, UsedMyCode);<o:p></o:p></p>
<p class="MsoNormal"> delete p;<o:p></o:p></p>
<p class="MsoNormal"> return 0;<o:p></o:p></p>
<div style="mso-element:para-border-div;border:none;border-bottom:solid
windowtext 1.0pt;padding:0in 0in 1.0pt 0in">
<p class="MsoNormal" style="border:none;padding:0in">}<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The printed value of UsedMyCode became 0 after that checkin.
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The compiler is eliminating the new/delete pair, printing just 10 for *p, because the usage
<o:p></o:p></p>
<p class="MsoNormal">inside the function can be fully analyzed.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But I am wondering whether this is a valid optimization, because the implementation is not<o:p></o:p></p>
<p class="MsoNormal">calling the user supplied replacement as per 15.5.4.6. The complaint is that the side effects of
<o:p></o:p></p>
<p class="MsoNormal">the user supplied replacement are not occurring.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The commit r325630 did not actually implement this optimization, but most likely it enabled<o:p></o:p></p>
<p class="MsoNormal">an already implemented optimization that was being foiled by something.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any opinions?</p>
</div>
</blockquote>
<p>The implementation is allowed to elide those side effects, and the standard was clarified in recent years to reflect this explicitly. See 8.3.4p10, "An implementation is allowed to omit a call to a replaceable global allocation function (21.6.2.1, 21.6.2.2).
When it does so, the storage is instead provided by the implementation or provided by extending the allocation of another new-expression. The implementation may extend the allocation..."<br>
</p>
<p> -Hal<br>
</p>
<blockquote type="cite" cite="mid:44903361AB618F4EA43589941BAC06BF0105640103@USCULXMSG05.am.sony.com">
<div class="WordSection1">
<p class="MsoNormal"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sunil Srivastava<o:p></o:p></p>
<p class="MsoNormal">Sony Interactive Entertainment.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org" moz-do-not-send="true">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>