Skip to content

Commit a39d8b7

Browse files
committed
C++: Ensure that each node type gets mapped to an instruction by 'getAnInstruction'.
1 parent 553c09a commit a39d8b7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,12 +1596,23 @@ private Cpp::Stmt getAChainedBranch(Cpp::IfStmt s) {
15961596
)
15971597
}
15981598

1599-
private Instruction getInstruction(Node n) {
1600-
result = n.asInstruction() or
1601-
result = n.asOperand().getUse() or
1602-
result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction() or
1603-
n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _) or
1604-
result = getInstruction(n.(PostUpdateNode).getPreUpdateNode())
1599+
private Instruction getAnInstruction(Node n) {
1600+
result = n.asInstruction()
1601+
or
1602+
not n instanceof InstructionNode and
1603+
result = n.asOperand().getUse()
1604+
or
1605+
result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction()
1606+
or
1607+
n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _)
1608+
or
1609+
not n instanceof IndirectInstruction and
1610+
exists(Operand operand |
1611+
n.(IndirectOperand).hasOperandAndIndirectionIndex(operand, _) and
1612+
result = operand.getUse()
1613+
)
1614+
or
1615+
result = getAnInstruction(n.(PostUpdateNode).getPreUpdateNode())
16051616
}
16061617

16071618
private newtype TDataFlowSecondLevelScope =
@@ -1647,7 +1658,7 @@ class DataFlowSecondLevelScope extends TDataFlowSecondLevelScope {
16471658

16481659
/** Gets a data-flow node nested within this scope. */
16491660
Node getANode() {
1650-
getInstruction(result).getAst().(Cpp::ControlFlowNode).getEnclosingStmt().getParentStmt*() =
1661+
getAnInstruction(result).getAst().(Cpp::ControlFlowNode).getEnclosingStmt().getParentStmt*() =
16511662
this.getAStmt()
16521663
}
16531664
}

0 commit comments

Comments
 (0)