<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.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]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Explicitly cc: cfe-commits *again*….<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<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">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."<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<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?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">And 6.3.1.5/1 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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I don't think 6.3.1.5/1 means to exclude NaN/infinities, given that 6.3.1.4/1 explicitly refers to "finite value" wrt conversion to an integer type.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></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:cfe-commits-bounces@lists.llvm.org]
<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<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></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:<o:p></o:p></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.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">__builtin_nan() works fine for me, can you provide a testcase?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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?<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">C11 <a href="http://6.3.1.5/1">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."<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></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."<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>