On Sat, Aug 19, 2017 at 02:24:59AM +0100, Dibyendu Majumdar wrote: > Hi, > > This test program appears to generate incorrect IR. > > extern int printf(const char *s, ...); > > int main(void) { > struct { char a:4; char b:4; } x = { 2, 4 }; > printf("a=%d b=%d\n", (int)x.a, (int)x.b); > return 0; > } It's a very surprising bug. It's not a linearization or an optimization bug as the AST is already wrong. With a simpler test case, like: struct s { char a:4; char b:4; }; int foo(void) { struct s x = { .a = 2, .b = 4 }; return x.b; } you can see that the linearization produce correct code for the initializer. You can also see that the return statement to be linearized is something like STMT_RETURN ret_value: EXPR_VALUE (value = 2) The EXPR_VALUE means that the expression is a constant (which is indeed the case but I would expect that the optimization has to deduce this) but it's value is wrong (a quick check seems to indicate that whatever selected by the x.<member> expression, it's always the value of the first member that we get here. It needs real investigation, though. It would guess for a bug in the expansion or something. Nice catch! -- Luc -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html