Chris Lattner <clatt...@apple.com> writes: > On Jan 27, 2009, at 5:10 PM, Ian Lance Taylor wrote: > >> Chris Lattner <clatt...@apple.com> writes: >> >>> On Jan 27, 2009, at 1:10 PM, Ian Lance Taylor wrote: >>> >>>> Laurent GUERBY <laur...@guerby.net> writes: >>>> >>>>> Just curious: is there a "portable" way to read from memory >>>>> address zero in C code? "portable" here means likely to work >>>>> on most compilers without exotic compile flags in 2009. >>>> >>>> char *my_null_pointer; >>>> char fn() { return *my_null_pointer; } >>>> >>>> It will be quite a while before whole program optimization is good >>>> enough to prove that my_null_pointer is not referenced by anything >>>> else. >>> >>> Perhaps in GCC, but this is not a good solution if you care about >>> other compilers. >> >> Is LLVM smart enough to optimize that away, even when using shared >> libraries? > > Yes absolutely. Just build with -fvisibility-hidden or use an export > map to say that my_null_pointer is not exported. If it is static, it > will also do it at -O2. This is not even a particularly aggressive > optimization.
Sure, but the whole idea here is for the compiler to *not* know that the pointer has a zero value. What I was really asking was whether LLVM would figure that out without taking any special action to restrict the visibility of the pointer. Ian