<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="">On Mar 2, 2015, at 1:22 PM, Douglas Gregor <<a href="mailto:dgregor@apple.com" class="">dgregor@apple.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><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=""><div class=""><div class=""><div class=""><ul class="MailOutline"><li class=""><b class="">Zero effect on ABI or code generation:</b> There are a huge number of interfaces that could benefit from the use of nullability qualifiers, but we won’t get widespread adoption if introducing the nullability qualifiers means breaking existing code, either in the ABI (say, because nullability qualifiers are mangled into the type) or at execution time (e.g., because a non-null pointer ends up being null along some error path and causes undefined behavior).</li></ul></div></div></div></div></div></blockquote><br class=""></div><div>I’m pretty sure that you know this, Doug, but:</div><div><br class=""></div><div>gcc already does (some of) this kind of stuff, and they *absolutely* use it in their codegen decisions.</div><div><br class=""></div><div>consider the following (simplified, fanciful) code:</div><div><br class=""></div><div>char global[1000];</div><div><br class=""></div><div>char *foo (char *p, size_t sz)</div><div>{</div><div>//<span class="Apple-tab-span" style="white-space:pre">    </span>stash a copy away</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>memcpy(global, p, sz);</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>if (p == NULL)</div><div><span class="Apple-tab-span" style="white-space:pre">               </span>p = (char *) malloc(100);</div><div><span class="Apple-tab-span" style="white-space:pre">    </span>return p;</div><div>}</div><div><br class=""></div><div>char *p2 = NULL;</div><div>char *p3 = foo(p2, 0);</div><div><br class=""></div><div>After executing this code, what will the value of ‘p3’ be?</div><div>Under gcc/glibc, it will be NULL, because memcpy is marked with “non-null” attributes, and so the “if (p==NULL)” branch is removed.</div><div>(Yes, even though memcpy(x, y, 0) will not dereference the pointer)</div><div><br class=""></div><div>— Marshall</div><div><br class=""></div><div><br class=""></div></body></html>