<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <br>
    <div class="moz-cite-prefix">On 1/8/2015 1:55 AM, Philip Reames
      wrote:<br>
    </div>
    <blockquote class=" cite" id="mid_54AD9648_1050100_philipreames_com"
      cite="mid:54AD9648.1050100@philipreames.com" type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <blockquote class=" cite"
        id="mid_97E6C63E_F924_421E_B34F_572F470EF160_gmail_com"
        cite="mid:97E6C63E-F924-421E-B34F-572F470EF160@gmail.com"
        type="cite">
        <div>
          <blockquote id="Cite_6893699" type="cite" class=" cite">
            <div class="">
              <div bgcolor="#FFFFFF" text="#000000" class="">
                <blockquote
                  id="mid_8C98EC88_B695_4AB0_94DB_1E3BC62E76AB_gmail_com"
cite="mid:8C98EC88-B695-4AB0-94DB-1E3BC62E76AB@gmail.com" type="cite"
                  class=" cite">
                  <div class="">
                    <div class="">I think the problems aren’t so much
                      that accessing 0 doesn’t work (although I imagine
                      there are problems with that), but expectations of
                      comparison with null. The main problem I’m aware
                      of is comparisons with null pointers. The first
                      global object in addrspace(3) will have the
                      address of 0, so if a user does if (x != NULL), it
                      will not behave as expected. For C I think this is
                      supposed to be fixed by changing the value of NULL
                      to -1, but I don’t think that is currently
                      supported. That is also complicated because the
                      null value is different for different address
                      spaces, and I think the actual null pointer value
                      must be 0 for C++. It doesn’t really turn up often
                      in real code so I don’t think anybody has really
                      spent time thinking about how to properly solve
                      this.</div>
                  </div>
                </blockquote>
                Just to make sure I'm interpreting this right: the
                problem is essentially that we hard code "null" to mean
                address 0 in all address spaces?  If we allowed the
                numeric value of null to be configurable per address
                space, would that resolve the issue at the LLVM IR
                level?<br class="">
              </div>
            </div>
          </blockquote>
          <div><br class="">
          </div>
          <div>Yes, it would. I’ve always imagined this to a be a large
            undertaking though</div>
        </div>
      </blockquote>
      I'd agree on the scope, but it also seems fairly straight
      forward.  If this becomes a serious issue, this seems like a
      workable approach.  <br>
    </blockquote>
    <br>
    This sounds similar to a problem we face in the HSAIL backend. NULL
    is not a constant in HSAIL, but an instruction that returns "a
    constant address that is guaranteed to be invalid for the given
    address space". The instruction will always return the same
    constant, so it can be stored and used in a comparison. So in HSAIL,
    zero is a valid address that is not required to coincide with NULL.
    It would be incorrect to say that "null is dereferenceable" or that
    an object "resides at null" just because its address is zero.<br>
    <br>
    The LLVM IR has the symbolic constant "null", which is great, but
    the trouble is in the SelectionDAG where it gets replaced by a zero.
    If the SDNode were to retain a symbolic "null", that would be
    sufficient for the HSAIL backend to emit the appropriate
    instruction.<br>
    <br>
    Sameer.<br>
    <br>
    <blockquote class=" cite" id="mid_54AD9648_1050100_philipreames_com"
      cite="mid:54AD9648.1050100@philipreames.com" type="cite">
      <blockquote class=" cite"
        id="mid_97E6C63E_F924_421E_B34F_572F470EF160_gmail_com"
        cite="mid:97E6C63E-F924-421E-B34F-572F470EF160@gmail.com"
        type="cite">
        <div><br class="">
          <blockquote id="Cite_6708776" type="cite" class=" cite">
            <div class="">
              <div bgcolor="#FFFFFF" text="#000000" class=""> <br
                  class="">
                Solving the frontend/language spec problem seems out of
                scope for LLVM, though probably not for clang.  Can you
                point me to a usage of C++ with non-zero address
                spaces?  I'd be curious to know what's happening in this
                space.  <br class="">
              </div>
            </div>
          </blockquote>
          <div><br class="">
          </div>
          <div>There’s an AMD static C++ extension language, and a
            khronos draft for an OpenCL C++ kernel language which
            applies the same sort of restrictions and address spaces to
            C++ as OpenCL C has. Last time I looked at this I remember
            that C allows a non-zero null pointer value, but 0 must be
            implicitly converted to the correct null pointer value and
            the NULL macro will expand to this integer value. I don’t
            think the OpenCL C spec touches the issue of different NULL
            values for different address spaces, but does explicitly
            allow different sized pointers for each. I am less clear on
            what C++ requires, but C++11 4.10 says "A null pointer
            constant is an integral constant expression (5.19) prvalue
            of integer type that evaluates to zero or a prvalue of type
            std::nullptr_t."</div>
          <div><br class="">
          </div>
          <br class="">
          <blockquote id="Cite_3151132" type="cite" class=" cite">
            <div class="">
              <div bgcolor="#FFFFFF" text="#000000" class=""> <br
                  class="">
                <blockquote
                  id="mid_8C98EC88_B695_4AB0_94DB_1E3BC62E76AB_gmail_com"
cite="mid:8C98EC88-B695-4AB0-94DB-1E3BC62E76AB@gmail.com" type="cite"
                  class=" cite">
                  <div class="">
                    <div class=""><br class="">
                    </div>
                    <div class="">-Matt</div>
                    <div class=""><br class="">
                    </div>
                    <br class="">
                    <blockquote id="Cite_5347812" type="cite" class="
                      cite">
                      <div class="">
                        <div bgcolor="#FFFFFF" text="#000000" class="">
                          <blockquote
                            id="mid_AB31CCB0_C2EB_47DB_8C12_E657F97527ED_gmail_com"
cite="mid:AB31CCB0-C2EB-47DB-8C12-E657F97527ED@gmail.com" type="cite"
                            class=" cite">
                            <div class="">
                              <div class=""><br class="">
                              </div>
                              <div class="">-Matt</div>
                              <div class=""><br class="">
                              </div>
                              <div class=""><br class="">
                              </div>
                              <br class="">
                              <blockquote id="Cite_7599427" type="cite"
                                class=" cite">
                                <div class="">
                                  <div dir="auto" class="">
                                    <div class=""><br class="">
                                      On Jan 7, 2015, at 1:18 PM, Philip
                                      Reames <<a
                                        moz-do-not-send="true"
                                        href="mailto:listmail@philipreames.com"
                                        class="">listmail@philipreames.com</a>>


                                      wrote:<br class="">
                                      <br class="">
                                    </div>
                                    <blockquote id="Cite_7799686"
                                      type="cite" class=" cite">
                                      <div class=""> On the review for <a
                                          moz-do-not-send="true"
                                          class="moz-txt-link-freetext"
href="http://reviews.llvm.org/D6808">http://reviews.llvm.org/D6808</a>,
                                        <a moz-do-not-send="true"
                                          href="http://reviews.llvm.org/p/majnemer/"
                                          class=" phui-handle
                                          phui-link-person">majnemer</a>
                                        commented that:<br class="">
                                        <span
                                          class="transaction-comment"
                                          data-sigil="transaction-comment"
                                          data-meta="14_7">"Address
                                          space 1 has a special meaning
                                          in LLVM, it's identical to
                                          address space 0 except for the
                                          fact that "null" may be
                                          dereferenced. You might want
                                          to consider a different
                                          address space."<br class="">
                                          <br class="">
                                          This is the first I've heard
                                          of this and I can't find any
                                          documentation about it being
                                          reserved, either in general,
                                          or specifically for x86.  Can
                                          anyone clarify?<br class="">
                                          <br class="">
                                          The only address spaces with
                                          special meanings I know of
                                          are:<br class="">
                                          - 0 (the normal address space,
                                          null is not dereferencable)<br
                                            class="">
                                          - 256 - TLS, GS relative
                                          addressing<br class="">
                                          - 257 - FS relative addressing<br
                                            class="">
                                          <br class="">
                                          Philip<br class="">
                                        </span> </div>
                                    </blockquote>
                                    <blockquote id="Cite_1780618"
                                      type="cite" class=" cite">
                                      <div class=""><span class="">_______________________________________________</span><br
                                          class="">
                                        <span class="">LLVM Developers
                                          mailing list</span><br
                                          class="">
                                        <span class=""><a
                                            moz-do-not-send="true"
                                            href="mailto:LLVMdev@cs.uiuc.edu"
                                            class="">LLVMdev@cs.uiuc.edu</a>
                                                  <a
                                            moz-do-not-send="true"
                                            href="http://llvm.cs.uiuc.edu/"
                                            class="">http://llvm.cs.uiuc.edu</a></span><br
                                          class="">
                                        <span class=""><a
                                            moz-do-not-send="true"
                                            href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"
                                            class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></span><br
                                          class="">
                                      </div>
                                    </blockquote>
                                  </div>
_______________________________________________<br class="">
                                  LLVM Developers mailing list<br
                                    class="">
                                  <a moz-do-not-send="true"
                                    href="mailto:LLVMdev@cs.uiuc.edu"
                                    class="">LLVMdev@cs.uiuc.edu</a>
                                          <a moz-do-not-send="true"
                                    href="http://llvm.cs.uiuc.edu/"
                                    class="">http://llvm.cs.uiuc.edu</a><br
                                    class="">
                                  <a moz-do-not-send="true"
                                    href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"
                                    class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br
                                    class="">
                                </div>
                              </blockquote>
                            </div>
                            <br class="">
                          </blockquote>
                          <br class="">
                        </div>
                      </div>
                    </blockquote>
                  </div>
                  <br class="">
                </blockquote>
                <br class="">
              </div>
            </div>
          </blockquote>
        </div>
        <br class="">
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
    <br>
  </body>
</html>