[LLVMdev] global question

Patrick Boettcher pb at linuxtv.org
Sat Mar 7 10:50:18 PST 2009


Hi John,

On Sat, 7 Mar 2009, John Regehr wrote:
> Below is some C code and its LLVM translation (using a recent rev).  The
> compiler goes ahead and loads from x in main, but it seems clear that a
> constant propagation pass could have inferred that x is 0.  In fact that
> is what happens if x is static, but in this case I cannot see how
> external linkage of x would invalidate that optimization.


> int x;
> 
> int main (void)
> {
>   return x;
> }
>

Please correct me if I'm wrong, but how can the compiler know, that x is not 
initialized in another file which defines x as extern? It can only be sure, 
when x is declared static.

So, for me the LLVM-code is right.

(I even remember someone, that it is platform specific whether x is initialized 
to 0 or not... or was it a question of C89 or C99?)

regards,
Patrick.

--
   Mail: patrick.boettcher at desy.de
   WWW:  http://www.wi-bw.tfh-wildau.de/~pboettch/



More information about the llvm-dev mailing list