<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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {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">Seems like there ought to be some kind of "unreachable" warning on the "return 0;" statement?<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"><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-dev-bounces@cs.uiuc.edu [mailto:cfe-dev-bounces@cs.uiuc.edu]
<b>On Behalf Of </b>David Blaikie<br>
<b>Sent:</b> Friday, September 19, 2014 7:25 AM<br>
<b>To:</b> Martin Richtarsky; Nick Lewycky<br>
<b>Cc:</b> cfe-dev Developers<br>
<b>Subject:</b> Re: [cfe-dev] Addresses of referenced objects in clang 3.5<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>(+Nick who had a hand in implementing this optimization)<o:p></o:p></p>
<p>I don't think there's a flag to control this, no.<o:p></o:p></p>
<div>
<p class="MsoNormal">On Sep 19, 2014 1:47 AM, "Richtarsky, Martin" <<a href="mailto:martin.richtarsky@sap.com">martin.richtarsky@sap.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Hi,<br>
<br>
since clang 3.5 code as below is optimized away with -O1, assuming that the address of the object<br>
can never be NULL:<br>
<br>
class A { };<br>
<br>
int func(A& a)<br>
{<br>
    if (&a)<br>
    {<br>
        return 1;<br>
    }<br>
    return 0;<br>
}<br>
<br>
int main()<br>
{<br>
    A &a = *reinterpret_cast<A *>(0);<br>
    return func(a);<br>
}<br>
<br>
clang++ -Wall -O1  ptrnull.cpp -o ptrnull<br>
<br>
ptrnull.cpp:5:10: warning: reference cannot be bound to dereferenced null pointer<br>
in well-defined C++ code; pointer may be assumed to always convert to true [-Wundefined-bool-conversion]<br>
    if (&a)<br>
    ~~   ^<br>
1 warning generated.<br>
<br>
<br>
./ptrnull<br>
Return code: 1<br>
<br>
This is as described in the release notes.<br>
<br>
When changing func() as follows the warning is not shown, but clang still performs<br>
the same optimization. Shouldn't the warning be shown here aswell?<br>
<br>
int func(A& a)<br>
{<br>
    A *aptr = &a;<br>
    if (aptr)<br>
    {<br>
        return 1;<br>
    }<br>
    return 0;<br>
}<br>
<br>
Is it possible to disable this optimization specifically (without resorting to -O0)<br>
to gradually fix codebases that rely on such checks? I saw that I can use<br>
-fsanitize=null, which helps, but disabling the optimization would still<br>
be the best temporary workaround.<br>
<br>
Thanks and Best regards,<br>
Martin<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>