<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 06/30/2017 11:16 AM, Peter Lawrence
      wrote:<br>
    </div>
    <blockquote
      cite="mid:3573E675-310B-41B2-AA3F-7F2B596BA454@sbcglobal.net"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <br class="">
      <div>
        <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="">      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" style="background-color: rgb(255, 255,
                    255);" class="">
                    <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
                    style="background-color: rgb(255, 255, 255);"
                    class="">
                  <span style="background-color: rgb(255, 255, 255);"
                    class="">> As I said, this is representation of
                    what the real code did, and looked like, after
                    other </span></div>
                <div class=""><span style="background-color: rgb(255,
                    255, 255);" class="">> inlining had taken place,
                    etc. In the original form, the user's intent was </span></div>
                <div class=""><span style="background-color: rgb(255,
                    255, 255);" class="">> clear. That code is never
                    executed when T is a small integer type.</span><br
                    style="background-color: rgb(255, 255, 255);"
                    class="">
                  <br style="background-color: rgb(255, 255, 255);"
                    class="">
                </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="">      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="">    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>
    That's correct. (And, as Sanjoy has said, you might end up with
    these situations in IR generated from source-level-safe languages
    where some combination of how the IR is generated by the frontend,
    and how the runtime works, guarantees that the IR-level UB is
    dynamically unreachable.)<br>
    <br>
     -Hal<br>
    <br>
    <blockquote
      cite="mid:3573E675-310B-41B2-AA3F-7F2B596BA454@sbcglobal.net"
      type="cite">
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class="">Peter Lawrence.</div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
      <div class=""><br class="">
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>