<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><br>
</p>
<div class="moz-cite-prefix">On 09/22/2017 01:09 PM, Kaylor, Andrew
wrote:<br>
</div>
<blockquote
cite="mid:0983E6C011D2DC4188F8761B533492DE823BAEF0@ORSMSX115.amr.corp.intel.com"
type="cite">
<pre wrap="">The reason I introduced this patch to begin with is that there are circumstances under which the optimizer will eliminate loads from addresses that were generated based on the null pointer arithmetic (because clang previously emitted a null-based GEP and still will in the Firefox case because it's using subtraction). It would seem that the Firefox case won't ever dereference the pointer it is creating this way, so it should be safe from the optimization I was seeing.
On the other hand, what the warning says is true, right? I believe clang will produce an inbounds GEP in the Firefox case and the LLVM language reference says, "The only in bounds address for a null pointer in the default address-space is the null pointer itself." So it's entirely possible that some optimization will interpret the result of the GEP generated to represent '(((char*)0)-1)' as a poison value.
-Andy</pre>
</blockquote>
<br>
I agree. The warning seems good here. As I recall, doing pointer
arithmetic on the null pointer is UB (even if we never dereference
it).<br>
<br>
For convenience, it looks like this:<br>
<br>
<blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<pre class="comment-text " id="ct-0" style="font-size: small; white-space: pre-wrap; line-height: 1.2; font-family: "Droid Sans Mono", Menlo, Monaco, "Courier New", monospace; background: rgb(255, 255, 255); color: rgb(34, 34, 34); margin: 1px 0px 0px; overflow: auto; padding: 8px; border-top: 1px solid rgb(221, 221, 221); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;">pointer arithmetic on a null pointer has undefined behavior if the offset is nonzero [-Werror,-Wnull-pointer-arithmetic]
return net_FindCharInSet(str, NET_MAX_ADDRESS, set);
^~~~~~~~~~~~~~~
/data/jenkins/workspace/firefox-clang-last/obj-x86_64-pc-linux-gnu/dist/include/nsURLHelper.h:224:36: note: expanded from macro 'NET_MAX_ADDRESS'
#define NET_MAX_ADDRESS (((char*)0)-1)</pre>
</blockquote>
<br>
-Hal<br>
<br>
<blockquote
cite="mid:0983E6C011D2DC4188F8761B533492DE823BAEF0@ORSMSX115.amr.corp.intel.com"
type="cite">
<pre wrap="">
-----Original Message-----
From: Sylvestre Ledru via Phabricator [<a class="moz-txt-link-freetext" href="mailto:reviews@reviews.llvm.org">mailto:reviews@reviews.llvm.org</a>]
Sent: Friday, September 22, 2017 9:02 AM
To: Kaylor, Andrew <a class="moz-txt-link-rfc2396E" href="mailto:andrew.kaylor@intel.com"><andrew.kaylor@intel.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:rjmccall@gmail.com">rjmccall@gmail.com</a>; <a class="moz-txt-link-abbreviated" href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>; <a class="moz-txt-link-abbreviated" href="mailto:efriedma@codeaurora.org">efriedma@codeaurora.org</a>
Cc: <a class="moz-txt-link-abbreviated" href="mailto:sylvestre@debian.org">sylvestre@debian.org</a>; Ivchenko, Alexander <a class="moz-txt-link-rfc2396E" href="mailto:alexander.ivchenko@intel.com"><alexander.ivchenko@intel.com></a>; <a class="moz-txt-link-abbreviated" href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>; <a class="moz-txt-link-abbreviated" href="mailto:mcrosier@codeaurora.org">mcrosier@codeaurora.org</a>; <a class="moz-txt-link-abbreviated" href="mailto:david.majnemer@gmail.com">david.majnemer@gmail.com</a>; <a class="moz-txt-link-abbreviated" href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>
Subject: [PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc
sylvestre.ledru added a comment.
For the record, Firefox was using this trick. This patch is breaking a ci build (clang trunk + warning as errors) More information here: <a class="moz-txt-link-freetext" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1402362">https://bugzilla.mozilla.org/show_bug.cgi?id=1402362</a>
Repository:
rL LLVM
<a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D37042">https://reviews.llvm.org/D37042</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</body>
</html>