<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><br></div><div><div><div>On Nov 19, 2013, at 10:52, Micah Villmow <<a href="mailto:micah.villmow@smachines.com">micah.villmow@smachines.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="WordSection1" style="page: WordSection1;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">+llvm-dev<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Yes. The question then becomes, does LLVM handle the case where the cast of the value 0 to a non-void* pointer?<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Think of this case:<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">int *<b>ptr = (int</b>*)0;<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">based on a strict reading of the spec, ptr itself technically is not the null pointer constant.</span></div></div></div></blockquote><div><br></div><div>Not true, the literal zero *is* a null pointer constant, which is then converted to a null pointer.</div><div><br></div><br><blockquote type="cite"><div lang="EN-US" link="blue" vlink="purple" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="WordSection1" style="page: WordSection1;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> If ptr points to an object in the local address space in OpenCL, or any address space where 0 is a valid address and memory exists, does LLVM handle this correctly?<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">I don’t believe that it does, but I can’t say for certain.<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);">Micah<o:p></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);"> </span></div><div style="border-style: none none none solid; border-left-color: blue; border-left-width: 1.5pt; padding: 0in 0in 0in 4pt; position: static; z-index: auto;"><div><div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in; position: static; z-index: auto;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span>Michael LIAO [<a href="mailto:michael.hliao@gmail.com" style="color: purple; text-decoration: underline;">mailto:michael.hliao@gmail.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>Sunday, November 17, 2013 10:46 PM<br><b>To:</b><span class="Apple-converted-space"> </span>Micah Villmow<br><b>Subject:</b><span class="Apple-converted-space"> </span>Re: [LLVMdev] Null pointers with a non-0 representation<o:p></o:p></span></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">Hi Micah & Michael<o:p></o:p></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">By C standard, section 6.3.2.2, "An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function." As LLVM IR is modelled after C, I assume null pointer in LLVM IR is equivalent to 0 as well. The folding from 0 to null pointer in LLVM follows that behaviour very similar.<o:p></o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">- michael<o:p></o:p></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div></div><div><p class="MsoNormal" style="margin: 0in 0in 12pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></p><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">On Sun, Nov 17, 2013 at 1:00 PM, Micah Villmow <<a href="mailto:micah.villmow@smachines.com" target="_blank" style="color: purple; text-decoration: underline;">micah.villmow@smachines.com</a>> wrote:<o:p></o:p></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">The reason why I suggested looking there is because the same questions came up as address 0 in some of the OpenCL address spaces are legal addresses. So in order to solve this problem, they would have to find answers to your questions, mainly your ‘c)’ question.  </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">I took a look at LangRef and it does look like there is a ‘null’ representation of the null pointer constant, which wasn’t part of LLVM back when I worked on this problem.  So maybe you are just running into an issue where the code hasn’t been updated yet because it works on everyones platform but yours.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"><br>Micah</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="border-style: none none none solid; border-left-color: blue; border-left-width: 1.5pt; padding: 0in 0in 0in 4pt;"><div><div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span>Kuperstein, Michael M [mailto:<a href="mailto:michael.m.kuperstein@intel.com" target="_blank" style="color: purple; text-decoration: underline;">michael.m.kuperstein@intel.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>Sunday, November 17, 2013 3:28 AM<br><b>To:</b><span class="Apple-converted-space"> </span>Micah Villmow;<span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" style="color: purple; text-decoration: underline;">LLVMdev@cs.uiuc.edu</a></span><o:p></o:p></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><br><b>Subject:</b><span class="Apple-converted-space"> </span>RE: Null pointers with a non-0 representation<o:p></o:p></div></div></div></div><div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Hi Micah,</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Thanks a lot for the reference.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Unfortunately, it looks like the discussion there is dealing with a somewhat different issue – modeling OpenCL address spaces. It’s true that the null pointer issue may arise in a similar context (e.g. null pointers in different address spaces may have different internal representations), but it’s not entirely related. Or have I missed something in the thread?</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Thanks,</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">  Michael</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div><div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span>Micah Villmow [<a href="mailto:micah.villmow@smachines.com" target="_blank" style="color: purple; text-decoration: underline;">mailto:micah.villmow@smachines.com</a>]<span class="Apple-converted-space"> </span><br><b>Sent:</b><span class="Apple-converted-space"> </span>Sunday, November 17, 2013 11:42<br><b>To:</b><span class="Apple-converted-space"> </span>Kuperstein, Michael M;<span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" style="color: purple; text-decoration: underline;">LLVMdev@cs.uiuc.edu</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>RE: Null pointers with a non-0 representation</span><o:p></o:p></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">I ran into the same problem in OpenCL with Local/Private address spaces and I believe it was discussed here in the past. So I would suggest looking through the archives as I believe some of your questions are answered there.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">This post might be a good starting point:</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/044101.html" target="_blank" style="color: purple; text-decoration: underline;">http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/044101.html</a><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Also the SPIR provisional spec as of last November deals with this issue if I remember correctly, so maybe you can discuss with Boaz Ouriel if he is still at Intel Israel about how they went about handling this problem, or look at the SPIR related posts from last year.</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Hope this helps,</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);">Micah</span><o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="color: rgb(31, 73, 125);"> </span><o:p></o:p></div><div><div style="border-style: solid none none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt 0in 0in;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;">From:</span></b><span style="font-size: 10pt; font-family: Tahoma, sans-serif;"><span class="Apple-converted-space"> </span><a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank" style="color: purple; text-decoration: underline;">llvmdev-bounces@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>[<a href="mailto:llvmdev-bounces@cs.uiuc.edu" target="_blank" style="color: purple; text-decoration: underline;">mailto:llvmdev-bounces@cs.uiuc.edu</a>]<span class="Apple-converted-space"> </span><b>On Behalf Of<span class="Apple-converted-space"> </span></b>Kuperstein, Michael M<br><b>Sent:</b><span class="Apple-converted-space"> </span>Sunday, November 17, 2013 1:15 AM<br><b>To:</b><span class="Apple-converted-space"> </span><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank" style="color: purple; text-decoration: underline;">LLVMdev@cs.uiuc.edu</a><br><b>Subject:</b><span class="Apple-converted-space"> </span>[LLVMdev] Null pointers with a non-0 representation</span><o:p></o:p></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">I feel a bit silly asking this, but here goes.<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">The C spec  does not require the null pointer to be implemented as an integer with the 0 bit-pattern. The implementation may arbitrarily choose any other (integer, but not necessarily) representation, as long as it’s distinct from any legal pointer. The only requirement is that casting an integer 0 to a pointer type results in a null pointer.  <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">LLVM IR appears to have similar the casting behavior.  That is, if I try to create a pointer with integer value 0 (e.g. by constructing an inttoptr constant expression with a i32 0 argument), it gets immediately folded into a null pointer constant. Furthermore, a PtrToInt from a null pointer results in 0 (which is even “stricter” than the C spec.)<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">So, that raises a few question:<o:p></o:p></div><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">a)<span style="font-size: 7pt;">     <span class="Apple-converted-space"> </span></span>Are those the desired semantics? I guess if clang generates this kind of IntToPtr instructions (as opposed to directly resolving the cast to a null pointer) this is unavoidable. But otherwise, why does LLVM treat null pointers and pointers with the integer value 0 as equivalent?<span class="Apple-converted-space"> </span><br>It’s completely natural for most platforms, but isn’t necessarily the right thing to do.<o:p></o:p></p><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">b)<span style="font-size: 7pt;">     <span class="Apple-converted-space"> </span></span>Assuming this is really desirable, should the fact that casting an integer 0 to a pointer type results in a null pointer be documented in the langref (as part of the inttoptr/ptrtoint documentation)? Or is it too “low-level”?<o:p></o:p></p><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">c)<span style="font-size: 7pt;">      <span class="Apple-converted-space"> </span></span>Let’s say I want to create a pointer with the numeric value 0, distinct from the null pointer, because 0 really does represent a valid pointer on my platform. Should this possible at the IR level? If it should be, then how?<o:p></o:p></p><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">Anyone has any inputs, except laughing me out of the (virtual) room? :-)<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> <o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">Thanks,<o:p></o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;">   Michael<o:p></o:p></div><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">---------------------------------------------------------------------<br>Intel Israel (74) Limited<o:p></o:p></p><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.<o:p></o:p></p><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">---------------------------------------------------------------------<br>Intel Israel (74) Limited<o:p></o:p></p><p style="margin-right: 0in; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman', serif;">This e-mail and any attachments may contain confidential material for<br>the sole use of the intended recipient(s). Any review or distribution<br>by others is strictly prohibited. If you are not the intended<br>recipient, please contact the sender and delete all copies.<o:p></o:p></p></div></div></div><p class="MsoNormal" style="margin: 0in 0in 12pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><br>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" style="color: purple; text-decoration: underline;">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>       <span class="Apple-converted-space"> </span><a href="http://llvm.cs.uiuc.edu/" target="_blank" style="color: purple; text-decoration: underline;">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank" style="color: purple; text-decoration: underline;">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><o:p></o:p></p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><o:p> </o:p></div></div></div></div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" style="color: purple; text-decoration: underline;">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>        <a href="http://llvm.cs.uiuc.edu/" style="color: purple; text-decoration: underline;">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" style="color: purple; text-decoration: underline;">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></div></blockquote></div><br></div></body></html>