Jonathan S. Shapiro
2008-May-14 13:31 UTC
[LLVMdev] optimization assumes malloc return is non-null
One more question on this. 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. But I am not aware of any requirement that compliant C code must be linked with the Standard C Library. If this requirement does not exist, then no portion of the C library specification can be used to justify a compile-time optimization unless we have some sort of compilation model information that tells us the C library can be assumed. Is there a requirement somewhere in the C *Language* Specification that ties all of this together in the required way? shap
Jonathan S. Shapiro wrote:-> One more question on this. > > 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. > > But I am not aware of any requirement that compliant C code must be > linked with the Standard C Library. If this requirement does not exist, > then no portion of the C library specification can be used to justify a > compile-time optimization unless we have some sort of compilation model > information that tells us the C library can be assumed. > > Is there a requirement somewhere in the C *Language* Specification that > ties all of this together in the required way?Reserved identifiers and header inclusion. Neil.
Duncan Sands
2008-May-14 14:31 UTC
[LLVMdev] optimization assumes malloc return is non-null
Hi,> 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. > > But I am not aware of any requirement that compliant C code must be > linked with the Standard C Library. If this requirement does not exist, > then no portion of the C library specification can be used to justify a > compile-time optimization unless we have some sort of compilation model > information that tells us the C library can be assumed. > > Is there a requirement somewhere in the C *Language* Specification that > ties all of this together in the required way?this is what -ffreestanding is for. More generally, don't run SimplifyLibcalls if you are not going to link with the standard C library. Ciao, Duncan.
Jonathan S. Shapiro
2008-May-14 14:46 UTC
[LLVMdev] optimization assumes malloc return is non-null
On Wed, 2008-05-14 at 23:23 +0900, Neil Booth wrote:> Jonathan S. Shapiro wrote:- > > Is there a requirement somewhere in the C *Language* Specification that > > ties all of this together in the required way? > > Reserved identifiers and header inclusion. > > Neil.What section of the C standard do I need to refresh myself on here?
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.
Possibly Parallel Threads
- [LLVMdev] optimization assumes malloc return is non-null
- [LLVMdev] optimization assumes malloc return is non-null
- [LLVMdev] optimization assumes malloc return is non-null
- [LLVMdev] optimization assumes malloc return is non-null
- [LLVMdev] optimization assumes malloc return is non-null