[LLVMbugs] [Bug 18095] clang 3.3 and more recent miscompiles NULL pointer arithmetic in optimized builds (O2)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 29 23:38:01 PST 2013


jonathan.sauer at gmx.de changed:

           What    |Removed                     |Added
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from jonathan.sauer at gmx.de ---
(In reply to comment #3)
> Have you guys considered perhaps emitting a warning when clang finds such an
> undefined behavior ?

That question is discussed in part three of the blog posts I mentioned :-) From
<http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html> (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:
<http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation>. 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)

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20131130/7dcd07b2/attachment.html>

More information about the llvm-bugs mailing list