[llvm-dev] Malloc null checks, why sometimes are moved and sometimes not?
Krzysztof Parzyszek via llvm-dev
llvm-dev at lists.llvm.org
Fri Apr 13 16:51:08 PDT 2018
On 4/13/2018 6:39 PM, Dávid Bolvanský via llvm-dev wrote:
>
> Here is simple test code:
> https://godbolt.org/g/mjAUpu
>
> 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.
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.
In the first case, the pointer is returned from the function, which
means that someone may actually want to access the allocated storage.
-Krzysztof
More information about the llvm-dev
mailing list