Skip to content

Commit b81f005

Browse files
committed
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.
1 parent 183b019 commit b81f005

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,28 @@ module Public {
815815
e = any(DerefExpr ae).getOperand() or
816816
e = any(IR::EvalImplicitDerefInstruction eidi).getOperand()
817817
)
818+
or
819+
exists(CallExpr ce |
820+
ce.getArgument(0).getType() instanceof TupleType and
821+
insn = IR::extractTupleElement(IR::evalExprInstruction(ce.getArgument(0)), _)
822+
or
823+
not ce.getArgument(0).getType() instanceof TupleType and
824+
insn = IR::evalExprInstruction(ce.getAnArgument())
825+
or
826+
// Receiver of a method call
827+
exists(IR::MethodReadInstruction mri |
828+
ce.getTarget() instanceof Method and
829+
mri = IR::evalExprInstruction(ce.getCalleeExpr()) and
830+
insn = mri.getReceiver()
831+
)
832+
) and
833+
mutableType(insn.getResultType())
818834
}
819835

820836
predicate hasPostUpdateNode(Node preupd) {
821837
insnHasPostUpdateNode(preupd.asInstruction())
822838
or
823839
preupd = getAWrittenNode()
824-
or
825-
preupd = any(ArgumentNode arg).getACorrespondingSyntacticArgument() and
826-
mutableType(preupd.getType())
827840
}
828841

829842
private class DefaultPostUpdateNode extends PostUpdateNode {

0 commit comments

Comments
 (0)