From a39d8b7c7c430b7cdff16769be84f2e217f84d2e Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Tue, 23 Apr 2024 09:44:30 +0100 Subject: [PATCH] C++: Ensure that each node type gets mapped to an instruction by 'getAnInstruction'. --- .../ir/dataflow/internal/DataFlowPrivate.qll | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll index 11127e021c0c..e6ad9c86c9bd 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll @@ -1596,12 +1596,23 @@ private Cpp::Stmt getAChainedBranch(Cpp::IfStmt s) { ) } -private Instruction getInstruction(Node n) { - result = n.asInstruction() or - result = n.asOperand().getUse() or - result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction() or - n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _) or - result = getInstruction(n.(PostUpdateNode).getPreUpdateNode()) +private Instruction getAnInstruction(Node n) { + result = n.asInstruction() + or + not n instanceof InstructionNode and + result = n.asOperand().getUse() + or + result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction() + or + n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _) + or + not n instanceof IndirectInstruction and + exists(Operand operand | + n.(IndirectOperand).hasOperandAndIndirectionIndex(operand, _) and + result = operand.getUse() + ) + or + result = getAnInstruction(n.(PostUpdateNode).getPreUpdateNode()) } private newtype TDataFlowSecondLevelScope = @@ -1647,7 +1658,7 @@ class DataFlowSecondLevelScope extends TDataFlowSecondLevelScope { /** Gets a data-flow node nested within this scope. */ Node getANode() { - getInstruction(result).getAst().(Cpp::ControlFlowNode).getEnclosingStmt().getParentStmt*() = + getAnInstruction(result).getAst().(Cpp::ControlFlowNode).getEnclosingStmt().getParentStmt*() = this.getAStmt() } }