<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 1, 2017, at 12:14 PM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="moz-cite-prefix" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">On 06/30/2017 11:16 AM, Peter Lawrence wrote:<br class=""></div><blockquote cite="mid:3573E675-310B-41B2-AA3F-7F2B596BA454@sbcglobal.net" type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 29, 2017, at 5:48 PM, Hal Finkel <<a moz-do-not-send="true" href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div bgcolor="#FFFFFF" text="#000000" class=""><p class=""><br class=""></p><div class="moz-cite-prefix">On 06/29/2017 07:26 PM, Peter Lawrence wrote:<br class=""></div><blockquote cite="mid:56CF6936-E6DC-445C-AAEA-FB51E4FB89D5@sbcglobal.net" type="cite" class=""><div class="">Hal,</div><div class="">     <span class="Apple-converted-space"> </span>Mehdi points out I mis-quoted you, I apologize sincerely.</div><div class=""><br class=""></div>Mehdi,<div class="">           Thank you for forcing me to go back and re-read what Hal wrote,</div><div class="">I could have sworn Hal and I were in agreement at the time I wrote you,</div><div class="">Must have been asleep at the wheel, not enough sleep last night</div><div class="">However my request for a more concrete example stands</div><div class=""><br class=""></div><div class="">Here’s what I said</div><div class=""><blockquote cite="mid:8D1216F2-8E1C-4895-8DA2-19932A92BD1B@sbcglobal.net" type="cite" class="" style="background-color: rgb(255, 255, 255);"><div class="">This doesn’t make sense to me, a shift amount of 48 is “undefined” for unsigned char,</div><div class="">How do we know this isn’t a source code bug,</div><div class="">What makes us think the the user intended the result to be “0”.</div></blockquote><br class="">Here’s what Hal said in response<br class="" style="background-color: rgb(255, 255, 255);"><span class="" style="background-color: rgb(255, 255, 255);">> As I said, this is representation of what the real code did, and looked like, after other </span></div><div class=""><span class="" style="background-color: rgb(255, 255, 255);">> inlining had taken place, etc. In the original form, the user's intent was </span></div><div class=""><span class="" style="background-color: rgb(255, 255, 255);">> clear. That code is never executed when T is a small integer type.</span><br class="" style="background-color: rgb(255, 255, 255);"><br class="" style="background-color: rgb(255, 255, 255);"></div><div class=""><br class=""></div><div class="">The problem is I don’t know how to interpret what Hal said here,</div><div class="">I can’t construct the “real” example from the “representative” example</div><div class="">given his advise.</div></blockquote><br class="">Hopefully, the description I later provided helps. I can't share the "real" code, but I reconstructed this example from my memory of the original code plus some of the intermediate IR I'd looked at.<br class=""><br class=""></div></div></blockquote></div><br class=""><div class="">Hal,</div><div class="">     <span class="Apple-converted-space"> </span>I’d like to see if I understand you, here’s what I think, let me know if this is correct</div><div class=""><br class=""></div><div class="">1. Sometimes there are abstraction penalties in C++ code</div><div class="">2. That can be optimized away after template instantiation, function inlining, etc</div><div class="">3. When they for example exhibit this pattern</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">   </span>if (A) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>stuff;</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">  </span>} else {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>other stuff including “undefined behavior”;</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">    </span>}</div><div class="">4. Where the compiler assumes “undefined behavior” doesn’t actually happen because</div><div class="">   <span class="Apple-converted-space"> </span>In the C language standard it is the users responsibility to avoid it</div><div class="">5. Therefore in this example the compiler can a) delete the else-clause</div><div class="">     b) delete the if-cond, c) assume A is true and propagate that information</div></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">That's correct. […]</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class=""> -Hal</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote><br class=""></div><div><br class=""></div><div>Great, so it seems like this definition enables us to lift ourselves</div><div>out of our current dilemma of only being able to discuss this rhetorically</div><div>to now being able to discuss this objectively.</div><div><br class=""></div><div>It is also incredibly practical, for example now I can write my own program that </div><div>shows why it could be beneficial to define branch-on-undef to be “undefined </div><div>behavior” rather than a binary choice.</div><div><br class=""></div><div>And finally, with this objective definition we can decide which issues that</div><div>are nagging us can be decided on technical grounds and which ones cannot.</div><div><br class=""></div><div>An example of one that is not decidable on technical grounds is the question</div><div>of whether these optimizations are legal [*], rather this is a philosophical question.</div><div><br class=""></div><div><div>* finding the right wording here is a struggle, perhaps “justified”,</div><div>  “ethical”, “desirable”, or some other word, works better. The sense of</div><div>  the issue even if imperfectly worded is this, that the alternative which</div><div>  is to replace undefined behavior with a run-time trap has equally compelling</div><div>  arguments in its favor.</div><div><br class=""></div></div><div>Perhaps this philosophical question can’t even be decided within the llvm</div><div>community, rather the discussion might have play out in places like standards</div><div>committees and in publications like Communications of the ACM.</div><div><br class=""></div><div><br class=""></div><div>Thoughts ?</div><div>Comments ?</div><div>Questions ?</div><div><br class=""></div><div><br class=""></div><div>Peter Lawrence.</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div><div><br class=""></div></body></html>