<div dir="ltr">[Adding back cfe-commits]</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 6:46 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Mon, Dec 7, 2015 at 1:59 PM, Robinson, Paul <span dir="ltr"><<a href="mailto:Paul_Robinson@playstation.sony.com" target="_blank">Paul_Robinson@playstation.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div><span>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">|
</span>C11 <a href="http://6.3.1.5/1" target="_blank">6.3.1.5/1</a>: "If the value being converted is outside the range of values that can be represented, the behavior is undefined."<u></u><u></u></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></p>
</span><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I think 5.2.4.2.2/5 says if infinities are representable, there are no values "outside" the floating-point range?</span></p></div></div></blockquote><div><br></div></span><div>That interpretation would also require converting UINT128_MAX to float to have defined behavior (it must give either FLT_MAX or +inf, as those are the two closest represetnable values), which it does not on real hardware.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">And <a href="http://6.3.1.5/1" target="_blank">6.3.1.5/1</a> starts out with "if the value being converted can be represented exactly in the new type, it is unchanged." I'd think that NaNs could be represented
"exactly" (they can certainly be represented: 5.2.4.2.2/3) despite not having an actual numeric value.</span></p></div></div></blockquote><div><br></div></span><div>In talking about NaNs, you've switched to talking about a different case; we were talking about doubles that don't fit in a float. The division by zero cases have UB because 6.5.5/5 explicitly says they do.</div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I don't think <a href="http://6.3.1.5/1" target="_blank">6.3.1.5/1</a> means to exclude NaN/infinities, given that <a href="http://6.3.1.4/1" target="_blank">6.3.1.4/1</a> explicitly refers to "finite value" wrt conversion to an integer type.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">--paulr<u></u><u></u></span></p>
<p class="MsoNormal"><a name="1517f7c1452748aa_1517e7526be45efe__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u> <u></u></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> cfe-commits [mailto:<a href="mailto:cfe-commits-bounces@lists.llvm.org" target="_blank">cfe-commits-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Richard Smith via cfe-commits<br>
<b>Sent:</b> Monday, December 07, 2015 1:32 PM<br>
<b>To:</b> Joerg Sonnenberger; cfe-commits<br>
<b>Subject:</b> Re: r254574 - PR17381: Treat undefined behavior during expression evaluation as an unmodeled<u></u><u></u></span></p>
</div>
</div><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Dec 7, 2015 at 7:25 AM, Joerg Sonnenberger via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
<p class="MsoNormal">On Thu, Dec 03, 2015 at 01:36:22AM -0000, Richard Smith via cfe-commits wrote:<br>
> Author: rsmith<br>
> Date: Wed Dec 2 19:36:22 2015<br>
> New Revision: 254574<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=254574&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=254574&view=rev</a><br>
> Log:<br>
> PR17381: Treat undefined behavior during expression evaluation as an unmodeled<br>
> side-effect, so that we don't allow speculative evaluation of such expressions<br>
> during code generation.<br>
><br>
> This caused a diagnostic quality regression, so fix constant expression<br>
> diagnostics to prefer either the first "can't be constant folded" diagnostic or<br>
> the first "not a constant expression" diagnostic depending on the kind of<br>
> evaluation we're doing. This was always the intent, but didn't quite work<br>
> correctly before.<br>
><br>
> This results in certain initializers that used to be constant initializers to<br>
> no longer be; in particular, things like:<br>
><br>
> float f = 1e100;<br>
><br>
> are no longer accepted in C. This seems appropriate, as such constructs would<br>
> lead to code being executed if sanitizers are enabled.<br>
<br>
This leads to some pretty annoying regressions as it now seems to be<br>
impossible to use NaN or infinites as constant initializers. Expressions<br>
like 0.0 / 0.0, 1.0 / 0.0 and -1.0 / 0.0 are perfectly well defined<br>
under normal IEEE rules, so they shouldn't be rejected.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Well, we have a problem. The evaluation semantics of these expressions requires code to execute in some build modes (in particular, with sanitizers enabled), and thus has a side-effect.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I'm inclined to relax the restriction added in this change for the specific case of global variables in C, since (as you say) there is a fair amount of code using divide-by-zero as a "portable" way of generating an inf or nan.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Worse, it seems<br>
even using __builtin_nan() for example doesn't work.<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">__builtin_nan() works fine for me, can you provide a testcase?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">I'm not even sure about the example given in the commit message, how<br>
exactly is that undefined behavior?<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">C11 <a href="http://6.3.1.5/1" target="_blank">6.3.1.5/1</a>: "If the value being converted is outside the range of values that can be represented, the behavior is undefined."<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">We also have C11 6.6/4: "Each constant expression shall evaluate to a constant that is in the range of representable values for its type."<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div>