[LLVMdev] optimization assumes malloc return is non-null

Mike Stump mrs at apple.com
Wed May 14 12:48:40 PDT 2008


On May 14, 2008, at 6:31 AM, Jonathan S. Shapiro wrote:
> The substitution of malloc() is predicated on the assumption that the
> compiler knows the implementation of malloc(), and the argument for  
> that
> seems to rest in part on the specification of the Standard C Library.

This is kinda a compilers 101 type question...

The Standard C Library is part of the C Standard.  Compilers compile  
for that standard and can make use of anything contained in it in any  
way they see fit.

> But I am not aware of any requirement that compliant C code must be
> linked with the Standard C Library.

The requirement is present, See

        -ffreestanding
            Assert that compilation takes place in a freestanding  
environment.  This implies -fno-builtin.  A freestanding environment  
is one in
            which the standard library may not exist, and program  
startup may not necessarily be at "main".  The most obvious example is  
an OS
            kernel.  This is equivalent to -fno-hosted.

for example.

> Is there a requirement somewhere in the C *Language* Specification  
> that
> ties all of this together in the required way?

Yes.  The C standard.  Likewise the C++ language standard, likewise  
any language standard.



More information about the llvm-dev mailing list