[LLVMdev] LLVM 2.4 problem? (resend)

Pertti Kellomäki pertti.kellomaki at tut.fi
Wed Oct 15 04:01:50 PDT 2008


Tatu Vaajalahti wrote:
> With this program llvm-gcc -O2 optimizes test2 away even though it's  
> address is taken in program (gcc-4.2 does not, neither does llvm-gcc  
> with -O or -O0):
> 
> 
> #include <stdio.h>
> 
> static const char test1 = 'x';
> static const char test2 = 'x';
> 
> int main(int argc, char **argv)
> {
>    printf("%p\n", &test1);
>    printf("%p\n", &test2);
> 
>    return 0;
> }

Seems to me that it is perfectly legitimate for the compiler to fold the
two char constants together. Since they are both static and const,
they cannot be changed from outside the compilation unit, and the
compiler sees that they are not changed within the unit.

If you give test2 the value 'y', both test1 and test2 are retained.
-- 
Pertti



More information about the llvm-dev mailing list