From 4c603c3989c851e71727726620d1bb299987c42b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 13 Sep 2024 21:41:40 +0900 Subject: [PATCH] [qfcc] Remove rvalue flag from expr_t It seems it was needed for dealing with the result expression for block expressions, but it turns out (possibly thanks to dags), that it's easy to check for the result value and using the appropriate call to emit the code thus avoiding the non-executable code warning. --- tools/qfcc/include/expr.h | 1 - tools/qfcc/source/expr.c | 3 --- tools/qfcc/source/statements.c | 19 +++++++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 83968c2dc..d41a7fa59 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -328,7 +328,6 @@ typedef struct expr_s { expr_type type; ///< the type of the result of this expression int printid; ///< avoid duplicate output when printing unsigned paren:1; ///< the expression is enclosed in () - unsigned rvalue:1; ///< the expression is on the right side of = unsigned implicit:1; ///< don't warn for implicit casts unsigned nodag:1; ///< prevent use of dags for this expression ///< propagates up diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 5ec092387..e166dbb94 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2708,9 +2708,6 @@ return_expr (function_t *f, const expr_t *e) if (e->type == ex_vector) { e = assign_expr (new_temp_def_expr (t), e); } - if (e->type == ex_block) { - ((expr_t *) e->block.result)->rvalue = 1;//FIXME - } return new_return_expr (e); } diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index 442005e86..47d18072d 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -1728,12 +1728,27 @@ expr_deref (sblock_t *sblock, const expr_t *deref, operand_t **op) return sblock; } +static sblock_t * +expr_slist (sblock_t *sblock, const ex_list_t *slist, const expr_t *result, + operand_t **op) +{ + + for (auto s = slist->head; s; s = s->next) { + if (s->expr == result) { + sblock = statement_subexpr (sblock, s->expr, op); + } else { + sblock = statement_single (sblock, s->expr); + } + } + return sblock; +} + static sblock_t * expr_block (sblock_t *sblock, const expr_t *e, operand_t **op) { if (!e->block.result) internal_error (e, "block sub-expression without result"); - sblock = statement_slist (sblock, &e->block.list); + sblock = expr_slist (sblock, &e->block.list, e->block.result, op); sblock = statement_subexpr (sblock, e->block.result, op); return sblock; } @@ -2389,7 +2404,7 @@ statement_assign (sblock_t *sblock, const expr_t *e) static sblock_t * statement_nonexec (sblock_t *sblock, const expr_t *e) { - if (!e->rvalue && options.warnings.executable) + if (options.warnings.executable) warning (e, "Non-executable statement; executing programmer instead."); return sblock; }