Convert post-update logic to IR (part 2)

Note that we don't create post-update nodes for method receivers if the
call to the method is indirect, via a function variable. We could aim to
do this in future.
This commit is contained in:
Owen Mansel-Chan
2025-09-10 22:06:08 +01:00
parent c8b8e25fbb
commit 203952fa47

View File

@@ -815,15 +815,28 @@ module Public {
e = any(DerefExpr ae).getOperand() or
e = any(IR::EvalImplicitDerefInstruction eidi).getOperand()
)
or
exists(CallExpr ce |
ce.getArgument(0).getType() instanceof TupleType and
insn = IR::extractTupleElement(IR::evalExprInstruction(ce.getArgument(0)), _)
or
not ce.getArgument(0).getType() instanceof TupleType and
insn = IR::evalExprInstruction(ce.getAnArgument())
or
// Receiver of a method call
exists(IR::MethodReadInstruction mri |
ce.getTarget() instanceof Method and
mri = IR::evalExprInstruction(ce.getCalleeExpr()) and
insn = mri.getReceiver()
)
) and
mutableType(insn.getResultType())
}
predicate hasPostUpdateNode(Node preupd) {
insnHasPostUpdateNode(preupd.asInstruction())
or
preupd = getAWrittenNode()
or
preupd = any(ArgumentNode arg).getACorrespondingSyntacticArgument() and
mutableType(preupd.getType())
}
private class DefaultPostUpdateNode extends PostUpdateNode {