<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 7/6/2017 3:05 PM, James Y Knight via
      llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAA2zVHpmMz8hZr=AM6EMEkyd33tpxe5p5dwQ_Mu=VRtakPzxwQ@mail.gmail.com">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Thu, Jul 6, 2017 at 2:06 PM,
            Kaylor, Andrew via llvm-dev <span dir="ltr"><<a
                href="mailto:llvm-dev@lists.llvm.org" target="_blank"
                moz-do-not-send="true">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">
              <div link="#0563C1" vlink="#954F72" lang="EN-US">
                <div class="m_8381347372558589288WordSection1">
                  <p class="MsoNormal">I've got a problem that I would
                    like some input on.  The problem basically boils
                    down to a program that I am compiling, whose source
                    I don't control, doing something like this:<br>
                  </p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">  p = (char*)0 + n</p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">where 'n' is an intptr_t-sized
                    value that the program knows is actually a valid
                    address for a pointer.</p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">clang translates this as</p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">  %p = getelementptr inbounds i8,
                    i8* null, i64 %n</p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">So far, so good.  The problem is
                    that while LLVM seems to consider the above IR to be
                    valid, we officially do not allow dereferencing a
                    pointer constructed in this way (if I’m reading the
                    rules correctly).  Consequently, if this GEP ever
                    gets close enough to a load using the pointer,
                    InstCombine will eliminate the GEP and the load.</p>
                  <p class="MsoNormal"> </p>
                  <p class="MsoNormal">I've been told that the '(char*)0
                    + n' construct is invalid according to the C
                    standard.  However, this pattern appears in the
                    glibc malloc implementation, so I'd like to be able
                    to handle it anyway.</p>
                </div>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>glibc does accept patches...or are you talking about
              two separate instances of this problem, both in glibc and
              something else?</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    FWIW and IIUC this same issue occurs in SPEC2017/gcc (with ref
    input) and I hear getting patches past the SPEC committee is
    incredibly difficult...<br>
    <br>
    <blockquote type="cite"
cite="mid:CAA2zVHpmMz8hZr=AM6EMEkyd33tpxe5p5dwQ_Mu=VRtakPzxwQ@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
            </div>
            <div><br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>