Skip to contentSkip to conversation

linear: only allocate call instructions when needed

PATCH New Luc Van Oostenryck 1 participant 1 message Apr 10, 2021 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linear: only allocate call instructions when needed

When linearizing a call expression, the corresponding instruction is allocated very early:
- before the valdity are done
- before the linearization is handled to one of the specific methods In both case it means that the allocated instruction is not used.

Fix this by doing the allocation only once it's needed.

---
 linearize.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linearize.c +2 -1
index 7248fa56b2ef..cf87545c7a18 100644
@@ -1533,7 +1533,7 @@ static pseudo_t linearize_assignment(struct entrypoint *ep, struct expression *e
 static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expression *expr)
 {
 	struct expression *arg, *fn;
-	struct instruction *insn = alloc_typed_instruction(OP_CALL, expr->ctype);
+	struct instruction *insn;
 	pseudo_t retval, call;
 	struct ctype *ctype = NULL;
 	struct symbol *fntype;
@@ -1554,6 +1554,7 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
 
 	ctype = &fntype->ctype;
 
+	insn = alloc_typed_instruction(OP_CALL, expr->ctype);
 	add_symbol(&insn->fntypes, fntype);
 	FOR_EACH_PTR(expr->args, arg) {
 		pseudo_t new = linearize_expression(ep, arg);
Signature · 1 line
2.31.1