Skip to content

Commit

Permalink
Precalculate size for alloca
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Apr 5, 2024
1 parent a8832d1 commit bd003a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cc/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ static VReg *gen_alloca(Expr *expr) {
assert(curfunc != NULL);
Expr *size = args->data[0];
const Token *token = size->token;
Expr *aligned_size = new_expr_bop(
EX_BITAND, &tySSize, token,
Expr *aligned_size = new_expr_int_bop(
EX_BITAND, token,
new_expr_addsub(EX_ADD, token, make_cast(&tySSize, token, size, false),
new_expr_fixlit(&tySSize, token, stack_align - 1)),
new_expr_fixlit(&tySSize, token, -stack_align));
Expand Down
10 changes: 5 additions & 5 deletions src/wcc/gen_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1961,11 +1961,11 @@ static void gen_alloca(Expr *expr, enum BuiltinFunctionPhase phase) {
assert(curfunc != NULL);
Expr *size = args->data[0];
const Token *token = size->token;
Expr *aligned_size =
new_expr_bop(EX_BITAND, &tySSize, token,
new_expr_addsub(EX_ADD, token, make_cast(&tySSize, token, size, false),
new_expr_fixlit(&tySSize, token, stack_align - 1)),
new_expr_fixlit(&tySSize, token, -stack_align));
Expr *aligned_size = new_expr_int_bop(
EX_BITAND, token,
new_expr_addsub(EX_ADD, token, make_cast(&tySSize, token, size, false),
new_expr_fixlit(&tySSize, token, stack_align - 1)),
new_expr_fixlit(&tySSize, token, -stack_align));

Expr *spvar = get_sp_var();
gen_expr_stmt(new_expr_bop(EX_ASSIGN, &tyVoid, NULL, spvar,
Expand Down

0 comments on commit bd003a7

Please sign in to comment.