<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>REOPENED
           </td>
           <td>RESOLVED
           </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#c4">Comment # 4</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>(In reply to <a href="show_bug.cgi?id=18095#c3">comment #3</a>)
<span class="quote">> Have you guys considered perhaps emitting a warning when clang finds such an
> undefined behavior ?</span >

That question is discussed in part three of the blog posts I mentioned :-) From
<<a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html">http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html</a>> (I'm
just quoting the headings, the blog post goes into much more detail):

| Why can't you warn when optimizing based on undefined behavior?
| [...]
| It is "really hard" to make it actually useful
| [...]
| It is hard to generate these warnings only when people want them
| [...]
| Explaining a series of optimizations that exposed an opportunity
| [...]

However you could look into clang's sanitizer for undefined behavior:
<<a href="http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation">http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation</a>>. By
enabling it, clang instruments the code it generates to check for undefined
behavior and produces a log message at runtime when UB is triggered. I am using
it myself, and it discovered several mistakes in my code.

With the UB sanitizer you could instrument your test builds and discover
undefined behavior during testing.

(I'm closing the bug as I think further discussion should happen on the cfe-dev
mailing list; feel free to disagree though)</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>