diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index c0b291789..48476ab89 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -1419,6 +1419,28 @@ append_expr (expr_t *block, expr_t *e) return block; } +expr_t * +prepend_expr (expr_t *block, expr_t *e) +{ + if (block->type != ex_block) + internal_error (block, "not a block expression"); + + if (!e || e->type == ex_error) + return block; + + if (e->next) + internal_error (e, "append_expr: expr loop detected"); + + e->next = block->e.block.head; + block->e.block.head = e; + + if (block->e.block.tail == &block->e.block.head) { + block->e.block.tail = &e->next; + } + + return block; +} + static symbol_t * get_struct_field (const type_t *t1, expr_t *e1, expr_t *e2) { diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 189f6cf90..82982b955 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -677,16 +677,14 @@ build_code_function (symbol_t *fsym, expr_t *state_expr, expr_t *statements) if (options.code.progsversion == PROG_VERSION) { expr_t *e; e = new_with_expr (2, LOCALS_REG, new_short_expr (0)); - e->next = statements; e->file = func->def->file; e->line = func->def->line; - statements = e; + prepend_expr (statements, e); e = new_adjstk_expr (0, 0); - e->next = statements; e->file = func->def->file; e->line = func->def->line; - statements = e; + prepend_expr (statements, e); func->temp_reg = LOCALS_REG; for (def_t *def = func->locals->space->defs; def; def = def->next) {