[LLVMdev] optimization assumes malloc return is non-null

Sandro Magi naasking at gmail.com
Thu May 1 12:30:41 PDT 2008


Sorry, for j
On Thu, May 1, 2008 at 1:16 PM, David Vandevoorde
<daveed at vandevoorde.com> wrote:
>
>  Another valid implementation of malloc is one that actually returns a
>  non-null pointer in this case, and for such an implementation, a valid
>  reduction is "int main() { return 1; }".  That reduction is IMO not
>  only valid, but also defensible and maybe desirable.  (And LLVM
>  apparently does so.)

But this reduction depends on knowledge of the malloc implementation,
which no one has confirmed is actually the case here.

On Wed, Apr 30, 2008 at 10:21 PM, Chris Lattner <sabre at nondot.org> wrote:
>  LLVM should not (and does not, afaik) assume the malloc succeeds in
>  general.
>
>  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.

I don't see how this could be true in general, without either
knowledge of the malloc implementation, which would be fine, or
presuming knowledge of the target, which would not be fine. If
"malloc(sizeof(int))" were changed to "malloc(3245677423)", would it
still be eliminated?

Sandro



More information about the llvm-dev mailing list