mirror of https://github.com/rui314/chibicc
Align local variables
This commit is contained in:
parent
9443e4b8bc
commit
dfec1157b4
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue