<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 09/27/2016 10:05 PM, Chris Lattner
      via llvm-dev wrote:<br>
    </div>
    <blockquote
      cite="mid:30F0A2F7-7679-43C4-96DA-232DFCC54C75@apple.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <br class="">
      <div>
        <blockquote type="cite" class="">
          <div class="">On Sep 27, 2016, at 9:41 AM, Mehdi Amini <<a
              moz-do-not-send="true" href="mailto:mehdi.amini@apple.com"
              class="">mehdi.amini@apple.com</a>> wrote:</div>
          <br class="Apple-interchange-newline">
          <div class="">
            <meta http-equiv="Content-Type" content="text/html;
              charset=utf-8" class="">
            <div style="word-wrap: break-word; -webkit-nbsp-mode: space;
              -webkit-line-break: after-white-space;" class=""><br
                class="">
              <div class="">
                <blockquote type="cite" class="">
                  <div class="">On Sep 25, 2016, at 5:40 PM, Chris
                    Lattner <<a moz-do-not-send="true"
                      href="mailto:clattner@apple.com" class="">clattner@apple.com</a>>
                    wrote:</div>
                  <br class="Apple-interchange-newline">
                  <div class="">
                    <meta http-equiv="content-type" content="text/html;
                      charset=utf-8" class="">
                    <div dir="auto" class="">
                      <div class="">
                        <div style="direction: inherit;" class="">The
                          pointer could only be null if the length is
                          zero.  If the length is zero, you shouldn't be
                          loading it.</div>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <div class=""><br class="">
                </div>
                <div class="">I was thinking about functions that takes
                  a non-null pointer. For example, assuming you have:</div>
                <div class=""><br class="">
                </div>
                <div class="">
                  <div class="">extern void *my_memcpy (void *dest,
                    const void *src, size_t len) __attribute__((nonnull
                    (1, 2)));</div>
                </div>
                <div class=""><br class="">
                </div>
                <div class="">You can just be calling it with any
                  StringRef without a null pointer check.</div>
                <div class=""><br class="">
                </div>
                <div class="">That said it is just a thought I had, I
                  don’t have any data or actual example to back this up.</div>
              </div>
            </div>
          </div>
        </blockquote>
        <div><br class="">
        </div>
        <div>Yeah, I’m not sure where this comes up, and whether memcpy
          should take null when the length is zero is also a highly
          contentious thing that flares up in debates periodically.</div>
      </div>
    </blockquote>
    One place that might be relevant is the existing special handling in
    StringRef around memcmp to avoid undefined behavior due to null
    pointers.  It hints that we've already hit this issue once.  <br>
    <blockquote
      cite="mid:30F0A2F7-7679-43C4-96DA-232DFCC54C75@apple.com"
      type="cite">
      <div><br class="">
        <blockquote type="cite" class="">
          <div class="">
            <div style="word-wrap: break-word; -webkit-nbsp-mode: space;
              -webkit-line-break: after-white-space;" class="">
              <div class="">
                <div class=""><br class="">
                </div>
                <br class="">
                <blockquote type="cite" class="">
                  <div class="">
                    <div dir="auto" class="">
                      <div class="">
                        <div style="direction: inherit;" class="">
                           Defaulting to null instead of "" is also a
                          microoptimization.</div>
                      </div>
                    </div>
                  </div>
                </blockquote>
                <div class=""><br class="">
                </div>
                <div class="">You mean: because initializing to 0 is
                  faster than a constant?</div>
              </div>
            </div>
          </div>
        </blockquote>
        <br class="">
      </div>
      <div>Yes, 0 is a “load immediate”, initializing to “” requires
        materializing the address of a global.</div>
      <div><br class="">
      </div>
      <div>-Chris </div>
      <br class="">
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>