Skip to contentSkip to conversation

unop: fix access to defining instruction in simplify_unop()

PATCH New Luc Van Oostenryck 1 participant 1 message Oct 6, 2020 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unop: fix access to defining instruction in simplify_unop()

Only pseudos of type PSEUDO_REG have a defining instruction.

However, in commit 5425db10d4d3 ("simplify '~(~x)' and '-(-x)' to 'x'"), this defining instruction of the 'src' of the outer unop
was accessed without checking the type.

Fixes 5425db10d4d35895ba3ca390478c624233ec027d
---
 simplify.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
simplify.c +2 -4
index 76c0558855a2..15452a585598 100644
@@ -1311,13 +1311,11 @@ static int simplify_unop(struct instruction *insn)
 		struct instruction *def;
 
 	case OP_NOT:
-		def = insn->src->def;
-		if (def && def->opcode == OP_NOT)
+		if (DEF_OPCODE(def, insn->src) == OP_NOT)
 			return replace_with_pseudo(insn, def->src);
 		break;
 	case OP_NEG:
-		def = insn->src->def;
-		if (def && def->opcode == OP_NEG)
+		if (DEF_OPCODE(def, insn->src) == OP_NEG)
 			return replace_with_pseudo(insn, def->src);
 		break;
 	default:
Signature · 1 line
2.28.0