<div dir="ltr">No, you really don't need undefined behavior in the standard in order to enable bug-finding.<div><br></div><div><div style="font-size:12.8px">The standard could've (and still could...) make signed integer overflow "<span class="">implementation</span>-<span class="">defined</span>" rather than "undefined". Compilers would thus be required to have *some documented meaning* for it (e.g. wrap 2's-complement, wrap 1's-complement, saturate to min/max, trap, or whatever...), but must not have the current "Anything goes! I can set your cat on fire if the optimizer feels like it today!" behavior.</div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">Such a change to the standard</span><span style="font-size:12.8px"> would not reduce any ability to do error checking, as compilers that want to be helpful could perfectly-well define it to trap at runtime when given certain compiler flags, and perfectly well warn you of your dependence upon unportable implementation-defined behavior (or, that your program is going to trap), at build-time.</span></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 29, 2016 at 2:38 PM, Lawrence Crowl via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 2/28/16, Linus Torvalds <<a href="mailto:torvalds@linux-foundation.org">torvalds@linux-foundation.org</a>> wrote:<br>
> The fact is, undefined compiler behavior is never a good idea. Not for<br>
> serious projects.<br>
<br>
</span>Actually, undefined behavior is essential for serious projects, but<br>
not for the reasons mentioned.<br>
<br>
If the language has no undefined behavior, then from the compiler's view,<br>
there is no such thing as a bad program.  All programs will compile and<br>
enter functional debug (possibly after shipping to customer).  On the<br>
other hand, a language with undefined behavior makes it possible for<br>
compilers (and their run-time support) to identify a program as wrong.<br>
<br>
The problem with the latest spate of compiler optimizations was not the<br>
optimization, but the lack of warnings about exploiting undefined behavior.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Lawrence Crowl<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</div></div></blockquote></div><br></div>