[LLVMdev] malloc(), free(), and alloca() with zero size

Chris Lattner sabre at nondot.org
Sun Oct 7 10:40:24 PDT 2007


On Oct 7, 2007, at 9:19 AM, Jon Sargeant wrote:

>>
>>> Also, I'm assuming that free()ing a null pointer is a legal NOP?
>>
>> Yes, 7.20.3.2p2.
>
> Ok, just to be clear...
> The semantics of the LLVM malloc and free instructions and the
> llvm.memcpy, llvm.memmove, and llvm.memset intrinsics are the same as
> their C counterparts (except for the extra alignment parameter).  The
> LLVM alloca instruction is not standard, so does that mean alloca()ing
> zero elements is undefined?

In the LLVM IR, alloca of zero elements is legal, but not defined.   
You can't dereference the returned pointer.

-Chris



More information about the llvm-dev mailing list