<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <blockquote type="cite"
      cite="mid:mailman.3.1523732401.23400.llvm-dev@lists.llvm.org">
      <pre wrap=""><div class="moz-txt-sig">On 4/14/2018 3:09 AM, 陳韋任 wrote:
</div></pre>
      <blockquote type="cite" style="color: #000000;">
        <pre wrap="">2018-04-14 7:51 GMT+08:00 Krzysztof Parzyszek via llvm-dev
<a class="moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" moz-do-not-send="true"><llvm-dev@lists.llvm.org></a>:
</pre>
        <blockquote type="cite" style="color: #000000;">
          <pre wrap="">On 4/13/2018 6:39 PM, Dávid Bolvanský via llvm-dev wrote:
</pre>
          <blockquote type="cite" style="color: #000000;">
            <pre wrap="">
Here is simple test code:
<a class="moz-txt-link-freetext" href="https://godbolt.org/g/mjAUpu" moz-do-not-send="true">https://godbolt.org/g/mjAUpu</a>

LLVM generally assumes that malloc never fails.

But I dont understand difference between these two example functions - and
why null check was not removed in f1, since in f2 it was removed.
</pre>
          </blockquote>
          <pre wrap="">
That's because the return value from malloc is discarded in f2. In that case
it simply doesn't matter if the malloc happened or not, and can be assumed
to have succeeded.
</pre>
        </blockquote>
        <pre wrap="">Wouldn't such assumption be too aggressive?
</pre>
      </blockquote>
      <pre wrap="">Normally, yes, but the standard explicitly allows the compiler to not 
call allocation/deallocation functions if the storage can be provided in 
another way. If the storage that would have been allocated by malloc 
cannot ever be accessed, we can pretend that it has been successfully 
provided in some way.

-Krzysztof</pre>
    </blockquote>
    How often does that really occur in normal programs?  Why bother? I
    find it quite surprising to fold away the call.  While the pointer
    doesn't escape F2(), the code does test the existance of the memory
    with the "if (!ptr)".  That would be enough to retain the call on
    all the compilers I've ever worked on.<br>
    <br>
    John<br>
    <blockquote type="cite"
      cite="mid:mailman.3.1523732401.23400.llvm-dev@lists.llvm.org">
      <pre wrap="">
</pre>
    </blockquote>
    <br>
  </body>
</html>