Codegen seems to assume aggregates are 8-byte alligned while placing them on the stack seems to only align them on 2 bytes. This causes code like the following to miscompile:
struct Foo {int a, b;};
int* i;
void g(void)
{
struct Foo foo;
i = &foo.b;
}Here, i is assigned the address of foo.a.
This problem seems to be fixed by adding a0:16:16 to the data layout string.
Note that the patch doesn't include a test case since the above function is now compiled to
g: ; @g
; BB#0: ; %entry
push.w r4
mov.w r1, r4
sub.w #4, r1
mov.w r4, r12
sub.w #4, r12
add.w #2, r12
mov.w r12, &i
add.w #4, r1
pop.w r4
retand I don't really want to encode this inefficient sub.w #4, r12, add.w #2, r12 in a test case. Any idea on how to create a decent test case for this?