<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=""><span style="font-size: 14px;" class="">Mehdi,</span><div class=""><span style="font-size: 14px;" class="">           Hal’s transformation only kicks in in the *presence* of UB, and</span></div><div class=""><span style="font-size: 14px;" class="">it does not matter how that UB got there, whether by function inlining</span></div><div class=""><span style="font-size: 14px;" class="">or without function inlining.</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class="">The problem with Hal’s argument is that the compiler does not have</span></div><div class=""><span style="font-size: 14px;" class="">a built in ouija board with which it can conjure up the spirit of the</span></div><div class=""><span style="font-size: 14px;" class="">author of the source code and find out if the UB was intentional</span></div><div class=""><span style="font-size: 14px;" class="">with the expectation of it being deleted, or is simply a bug.</span></div><div class=""><span style="font-size: 14px;" class="">Function inlining does not magically turn a bug into not-a-bug, nor</span></div><div class=""><span style="font-size: 14px;" class="">does post-inlining simplification magically turn a bug into not-a-bug.</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class="">Let me say it again:  if the compiler can find this UB (after whatever</span></div><div class=""><span style="font-size: 14px;" class="">optimizations it takes to get there) then the static analyzer must</span></div><div class=""><span style="font-size: 14px;" class="">be able to do the same thing, forcing the programmer to fix it</span></div><div class=""><span style="font-size: 14px;" class="">rather than have the compiler optimize it.</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class="">Or, to put it another way:  there is no difference between a compiler</span></div><div class=""><span style="font-size: 14px;" class="">and a static analyzer [*]. So regardless of whether it is the compiler or</span></div><div class=""><span style="font-size: 14px;" class="">the static analyzer that finds any UB, the only rational thing to do with</span></div><div class=""><span style="font-size: 14px;" class="">it is report it as a bug.</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class="">Peter Lawrence.</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><span style="font-size: 14px;" class="">[* in fact that’s one of the primary reasons Apple adopted llvm, to use</span></div><div class=""><span style="font-size: 14px;" class="">  It as a base for static analysis]</span></div><div class=""><span style="font-size: 14px;" class=""><br class=""></span></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 21, 2017, at 10:03 PM, Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" class="">joker.eph@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><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;" class=""><div class="gmail_quote" 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;">2017-07-21 21:27 GMT-07:00 Peter Lawrence<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:peterl95124@sbcglobal.net" target="_blank" class="">peterl95124@sbcglobal.net</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><font face="Menlo" class="">Sean,</font><div class=""><font face="Menlo" class="">     Let me re-phrase a couple words to make it perfectly clear</font></div><div class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class=""><font face="Menlo" class="">On Jul 21, 2017, at 6:29 PM, Peter Lawrence <<a href="mailto:peterl95124@sbcglobal.net" target="_blank" class="">peterl95124@sbcglobal.net</a>> wrote:</font></div><font face="Menlo" class=""><br class="m_2150444843056015504Apple-interchange-newline"></font><div class=""><div style="word-wrap: break-word;" class=""><font face="Menlo" class="">Sean,</font><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">Dan Gohman’s “transform” changes a loop induction variable, but does not change the CFG,</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">Hal’s “transform” deletes blocks out of the CFG, fundamentally altering it.</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><span style="font-family: Menlo;" class="">These are two totally different transforms.</span></div></div></div></blockquote><blockquote type="cite" class=""><div style="word-wrap: break-word;" class=""><div class=""><br class=""></div><div class=""><span style="font-family: Menlo;" class=""><br class=""></span></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word;" class=""><div class=""><font face="Menlo" class="">And even the analysis is different,</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">The first is based on an *assumption* of non-UB (actually there is no analysis to perform)</font></div></div></div></blockquote></span><font face="Menlo" class="">                       the *absence* of UB<br class=""></font><span class=""><blockquote type="cite" class=""><div style="word-wrap: break-word;" class=""><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">the second Is based on a *proof* of existence of UB (here typically some non-trivial analysis is required)</font></div></div></blockquote></span><font face="Menlo" class="">                       <span class="Apple-converted-space"> </span>the *presence* of UB<br class=""></font><span class=""><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word;" class=""><div class=""><font face="Menlo" class="">These have, practically speaking, nothing in common.</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div></span><div class=""><font face="Menlo" class="">In particular, the first is an optimization, while the second is a transformation that</font></div><div class=""><font face="Menlo" class="">fails to be an optimization because the opportunity for it happening in real world</font></div><div class=""><font face="Menlo" class="">code that is expected to pass compilation without warnings, static analysis without</font></div><div class=""><font face="Menlo" class="">warnings, and dynamic sanitizers without warnings, is zero.</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">Or to put it another way, if llvm manages to find some UB that no analyzer or</font></div><div class=""><font face="Menlo" class="">sanitizer does, and then deletes the UB, then the author of that part of llvm</font></div><div class=""><font face="Menlo" class="">is in the wrong group, and belongs over in the analyzer and/or sanitizer group.</font></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I don't understand your claim, it does not match at all my understand of what we managed to get on agreement on in the past.</div><div class=""><br class=""></div><div class="">The second transformation (dead code elimination to simplify) is based on the assumption that there is no UB.</div><div class=""><br class=""></div><div class="">I.e. after inlining for example, the extra context of the calling function allows us to deduce the value of some conditional branching in the inline body based on the impossibility of one of the path *in the context of this particular caller*.</div><div class=""><br class=""></div><div class="">This does not mean that the program written by the programmer has any UB inside.</div><div class=""><br class=""></div><div class="">This is exactly the example that Hal gave.</div><div class=""><br class=""></div><div class="">This can't be used to expose any meaningful information to the programmer, because it would be full of false positive. Basically a program could be clean of any static analyzer error, of any UBSAN error, and totally UB-free, and still exhibit tons and tons of such issues.</div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div></div></div></blockquote></div><br class=""></div></body></html>