hi all,<br><br>i'm trying to use LLVM to compile some linux kernel code, and i noticed a mismatch with gcc.  here is a simplified test case:<br><br>struct foo {<br>  int a;<br>  int b;<br>  int c;<br>};<br><br>static struct foo x; // 'forward' declaration?<br>
<br>int bar() {<br>  printf("a: %d, b: %d, c: %d\n", x.a, x.b, x.c);<br>}<br><br>static struct foo x = {<br>  .a = 1, .b = 2, .c = 3,<br>};<br><br>int main() {<br>  bar();<br>  return 0;<br>}<br><br><br>when this code is compiled with gcc and run, stdout prints "a: 1, b: 2, c: 3", which means that it takes the true declaration of x, initialized to 1, 2, 3.  however, when it's compiled with llvm, llvm emits the following code for x:<br>
<br>@x = internal global %struct.foo zeroinitializer    ; <%struct.foo*> [#uses=3]<br><br>which seems to me like it's taking the first declaration of x, which is a forward declaration.  is that the correct behavior?  i believe that the kernel developers intended for the second (real declaration) of x to be visible, even in bar(), but that's not what's happening with llvm.  is there an easy workaround where i can get llvm to emit code initializing x to {1,2,3}?  thanks!<br>
<br>Philip<br><br>