<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi, Bhatu,</p>
    <p>I agree. The return from realloc is always a new allocation (in
      C's model, even if the same pointer is returned).<br>
    </p>
    <p>The core issue is that we don't generally add the noalias return
      attribute to malloc in a specific way, but rely on the system
      headers marking malloc with __attribute__((malloc)). The GCC docs
      explain why realloc is not marked with that attribute
(<a class="moz-txt-link-freetext" href="https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes">https://gcc.gnu.org/onlinedocs/gcc-7.1.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes</a>),
      but it has to do with a property of the GCC attribute that we
      don't capture with our noalias return attribute (that the memory
      contains no live pointers to other objects).</p>
    <p>That having been said, the relevant property of being
      allocation-like should already be captured by LLVM's analysis:</p>
    <p>
      <blockquote type="cite">/// \brief Tests if a value is a call or
        invoke to a function that returns a<br>
        /// NoAlias pointer (including malloc/calloc/realloc/strdup-like
        functions).<br>
        bool llvm::isNoAliasFn(...</blockquote>
    </p>
    <p>it recognized realloc and several other functions in this regard
      even if they're not marked with noalias. The core problem,
      however, is that our AA intrastructure is looking at the noalias
      attribute directly (instead of calling isNoAliasFn). Please feel
      free to submit a patch. Specifically, in
      lib/Analysis/AliasAnalysis.cpp, we have:</p>
    <p>
      <blockquote type="cite">bool llvm::isNoAliasCall(const Value *V) {<br>
          if (auto CS = ImmutableCallSite(V))<br>
            return CS.hasRetAttr(Attribute::NoAlias);<br>
          return false;<br>
        }<br>
      </blockquote>
    </p>
    <p>We should remove the current implementation of
      llvm::isNoAliasCall, and rename llvm::isNoAliasFn to
      llvm::isNoAliasCall (llvm::isNoAliasFn has only one caller, in
      MemoryDependenceAnalysis, so just update that call site). Then
      update some relevant test case (e.g.,
      test/Analysis/BasicAA/2008-11-23-NoaliasRet.ll). If you can't
      submit a patch, please open a bug report (and tag it with the
      beginner keyword).</p>
    <p> -Hal<br>
    </p>
    <div class="moz-cite-prefix">On 12/26/2017 04:13 AM, Bhatu via
      llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CALHEqfG2PMta6SmSsvkAaYb+YmUk9OhnMod6MD8Ezp8xeaKoWg@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <div dir="ltr">
        <div>Hello,</div>
        <div><br>
        </div>
        According to my understanding, it seems that the result of
        realloc will not technically alias the original pointer. When
        the realloc is done in-place the <a moz-do-not-send="true"
          href="http://en.cppreference.com/w/c/memory/realloc">reference</a> says:
        <div>"The original pointer ptr is invalidated and any access to
          it is undefined behavior (even if reallocation was in-place)."</div>
        <div><br>
        </div>
        <div>Additionally from the<a moz-do-not-send="true"
            href="https://port70.net/%7Ensz/c/c11/n1570.html#6.2.4p2">
            C11 standard</a> we have:</div>
        <div>"The value of a pointer becomes indeterminate when the
          object it points to (or just past) reaches the end of its
          lifetime"</div>
        <div><br>
        </div>
        <div>Is this enough to infer that we can safely mark realloc as
          noalias? <br clear="all">
          <div><br>
          </div>
          -- <br>
          <div class="gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div dir="ltr">
                          <div><font size="1"><span
                                style="color:rgb(84,141,212);font-family:arial,helvetica,sans-serif">Regards</span><br>
                            </font></div>
                          <div>
                            <div dir="ltr"><font color="#000000"
                                size="1" face="arial, helvetica,
                                sans-serif"><font color="#548dd4">Bhatu</font></font></div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </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>
    <pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </body>
</html>