<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 27, 2016, at 9:41 AM, Mehdi Amini <<a 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 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><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=""></body></html>