<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><span class="vcard"><a class="email" href="mailto:jonathan.sauer@gmx.de" title="jonathan.sauer@gmx.de">jonathan.sauer@gmx.de</a>
</span> changed
              <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang 3.3 and more recent miscompiles NULL pointer arithmetic in optimized builds (O2)"
   href="http://llvm.org/bugs/show_bug.cgi?id=18095">bug 18095</a>
        <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>jonathan.sauer@gmx.de
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang 3.3 and more recent miscompiles NULL pointer arithmetic in optimized builds (O2)"
   href="http://llvm.org/bugs/show_bug.cgi?id=18095#c2">Comment # 2</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang 3.3 and more recent miscompiles NULL pointer arithmetic in optimized builds (O2)"
   href="http://llvm.org/bugs/show_bug.cgi?id=18095">bug 18095</a>
              from <span class="vcard"><a class="email" href="mailto:jonathan.sauer@gmx.de" title="jonathan.sauer@gmx.de">jonathan.sauer@gmx.de</a>
</span></b>
        <pre>As you said, this is undefined behavior (as the NULL pointer does not point to
the element of an array object, cf. C99 6.5.6p8), so the compiler can do
whatever it wants -- which includes assuming that the pointer will never be
NULL.

There is a nice series of blog posts on the LLVM blog that goes into some
detail on how compilers exploit undefined behavior for optimization:
<<a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html</a>>

Another paper on the subject is "Undefined Behavior: What Happened to My
Code?": <<a href="http://people.csail.mit.edu/akcheung/papers/apsys12.html">http://people.csail.mit.edu/akcheung/papers/apsys12.html</a>></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>