<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jul 30, 2014 at 2:08 PM, Ghitulete Razvan <span dir="ltr"><<a href="mailto:razvan.ghitulete@gmail.com" target="_blank">razvan.ghitulete@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I have an llvm pass, that goes through all the GlobalVariable objects inside a file and tries to match them to the corresponding type (at some point). And I have noticed the following behavior. For</div>

<div><br></div><div>struct v {</div><div>   int x:9;</div><div>   ....</div><div>};</div><div>struct v var1 = {.x=0};</div><div>struct v var2;</div><div><br></div><div>The LLVM IR generated will declare variable var1 of an anonymous type instead of type struct v, while var2 is okay. </div>

<div><br></div><div><div>%struct.v = type { [2 x i8], [6 x i8] }</div><div>@var1 = global { i8, i8, [6 x i8] } { i8 0, i8 0, [6 x i8] undef }, align 8<br></div></div><div>@var2 = common global %struct.v zeroinitializer, align 8<br>

</div><div><br></div><div>This actually happens always when the variable is statically initialized, and the bitfield is longer than 8 bits.</div><div><br></div><div>Does anyone have any idea why this is occurring,</div></div>
</blockquote><div><br></div><div>It happens essentially because it's more convenient for us to generate IR that way. There are no guarantees that IR struct types will match source-level struct types in any way, or be consistent from use to use. Another example:</div>
<div><br></div><div>typedef union { int n; float f; } U;</div><div>U u1 = { .n = 123 };</div><div>U u2 = { .f = 1.0f };</div><div><br></div><div>... gives ...</div><div><br></div><div><div>@u1 = global %union.U { i32 123 }, align 4</div>
<div>@u2 = global { float } { float 1.000000e+00 }, align 4</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div>or more exactly where the code responsible for generating this part is?</div></div></blockquote><div><br></div><div>lib/CodeGen/CGExprConstant.cpp -- look for ConstStructBuilder::Finalize.</div></div></div>
</div>