[LLVMdev] optimization assumes malloc return is non-null

Andrew Lenharth andrewl at lenharth.org
Thu May 1 11:41:58 PDT 2008


On Thu, May 1, 2008 at 12:14 PM, Jonathan S. Shapiro <shap at eros-os.com> wrote:
>  > 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.

So a small nit-pick here, if the transformation is unsafe, the step
that is unsafe is
call malloc -> malloc instruction.

The malloc instruction doesn't have to have a 1:1 mapping to c malloc
semantics and in fact this is not claimed in the language reference.
So if llvm wants to eliminate malloc in this instance that is
permissable under it's (under-specified) semantics.  If the malloc
instruction doesn't actually follow exactly the C standard, then it is
the lowering of malloc calls, when compiling C, to malloc instructions
that is at fault, not the subsequent removal of it.

Andrew



More information about the llvm-dev mailing list