[qfcc] Check for unused operands in evaluate_constexpr

Fixes a segfault when evaluating unary expressions on constants.
This commit is contained in:
Bill Currie 2025-02-04 07:39:30 +09:00
parent 3d488354b7
commit c99f8a8df4

View file

@ -204,6 +204,9 @@ get_temp_def (operand_t *op)
static def_t * static def_t *
get_def (operand_t *op) get_def (operand_t *op)
{ {
if (!op) {
return nullptr;
}
if (is_short (op->type)) { if (is_short (op->type)) {
auto def = new_def (0, &type_short, 0, sc_extern); auto def = new_def (0, &type_short, 0, sc_extern);
def->offset = op->value->short_val; def->offset = op->value->short_val;
@ -283,9 +286,9 @@ evaluate_constexpr (const expr_t *e)
auto ds = codespace_newstatement (&value_codespace); auto ds = codespace_newstatement (&value_codespace);
*ds = (dstatement_t) { *ds = (dstatement_t) {
.op = opcode_get (inst), .op = opcode_get (inst),
.a = opa->offset, .a = opa ? opa->offset : 0,
.b = opb->offset, .b = opb ? opb->offset : 0,
.c = opc->offset, .c = opc ? opc->offset : 0,
}; };
} }
options.code.progsversion = saved_version; options.code.progsversion = saved_version;