[LLVMdev] optimization assumes malloc return is non-null

Jonathan S. Shapiro shap at eros-os.com
Thu May 1 10:14:38 PDT 2008


On Thu, 2008-05-01 at 12:00 -0500, David Greene wrote:
> On Wednesday 30 April 2008 21:21, Chris Lattner wrote:
> 
> > If LLVM is able to eliminate all users of the malloc assuming the
> > malloc succeeded (as in this case), then it is safe to assume the malloc
> > returned success.
> 
> Ah, I missed this bit.  I didn't see that the result of malloc was not used
> outside the if test.
> 
> But is the if test considered a "use?"  If so, it's a use in the context of
> success or failure, so how can LLVM assume success?

Small correction. The pivotal issue isn't "use", it is "capture". In
this case, the value returned by malloc is not bound to any variable
that survives, so there is no capture of the return value.

> 1. LLVM can't assume malloc success

I was confused about this too. LLVM actually *can* assume malloc success
in this case, using any of several arguments that came up in my exchange
with Daveed.

What I do not know is *which* of these justifications (or some variant)
the optimizer is presently exploiting. Perhaps Chris can clarify that
for both of us.


shap




More information about the llvm-dev mailing list