Align local variables

This commit is contained in:
Rui Ueyama 2019-08-09 00:10:31 +09:00
parent 9443e4b8bc
commit dfec1157b4
2 changed files with 4 additions and 0 deletions

View File

@ -250,6 +250,7 @@ static void assign_lvar_offsets(Obj *prog) {
int offset = 0;
for (Obj *var = fn->locals; var; var = var->next) {
offset += var->ty->size;
offset = align_to(offset, var->ty->align);
var->offset = -offset;
}
fn->stack_size = align_to(offset, 16);

View File

@ -47,6 +47,9 @@ int main() {
ASSERT(2, ({ int x=2; { int x=3; } int y=4; x; }));
ASSERT(3, ({ int x=2; { x=3; } x; }));
ASSERT(15, ({ int x; int y; char z; char *a=&y; char *b=&z; b-a; }));
ASSERT(1, ({ int x; char y; int z; char *a=&y; char *b=&z; b-a; }));
printf("OK\n");
return 0;
}