Skip to content

Commit d65bb3b

Browse files
committed
C++: Make basic block information available from dataflow nodes.
1 parent be6af4b commit d65bb3b

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -897,23 +897,6 @@ private class MyConsistencyConfiguration extends Consistency::ConsistencyConfigu
897897
}
898898
}
899899

900-
/**
901-
* Gets the basic block of `node`.
902-
*/
903-
IRBlock getBasicBlock(Node node) {
904-
node.asInstruction().getBlock() = result
905-
or
906-
node.asOperand().getUse().getBlock() = result
907-
or
908-
node.(SsaPhiNode).getPhiNode().getBasicBlock() = result
909-
or
910-
node.(RawIndirectOperand).getOperand().getUse().getBlock() = result
911-
or
912-
node.(RawIndirectInstruction).getInstruction().getBlock() = result
913-
or
914-
result = getBasicBlock(node.(PostUpdateNode).getPreUpdateNode())
915-
}
916-
917900
/**
918901
* A local flow relation that includes both local steps, read steps and
919902
* argument-to-return flow through summarized functions.
@@ -999,7 +982,8 @@ private int countNumberOfBranchesUsingParameter(SwitchInstruction switch, Parame
999982
// we pick the one with the highest edge count.
1000983
result =
1001984
max(SsaPhiNode phi |
1002-
switch.getSuccessor(caseOrDefaultEdge()).getBlock().dominanceFrontier() = getBasicBlock(phi) and
985+
switch.getSuccessor(caseOrDefaultEdge()).getBlock().dominanceFrontier() =
986+
phi.getBasicBlock() and
1003987
phi.getSourceVariable() = sv
1004988
|
1005989
strictcount(phi.getAnInput())

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,24 @@ class Node extends TIRDataFlowNode {
160160
/** Gets the operands corresponding to this node, if any. */
161161
Operand asOperand() { result = this.(OperandNode).getOperand() }
162162

163+
/** Holds if this node is at index `i` in basic block `block`. */
164+
final predicate hasIndexInBlock(IRBlock block, int i) {
165+
this.asInstruction() = block.getInstruction(i)
166+
or
167+
this.asOperand().getUse() = block.getInstruction(i)
168+
or
169+
this.(SsaPhiNode).getPhiNode().getBasicBlock() = block and i = -1
170+
or
171+
this.(RawIndirectOperand).getOperand().getUse() = block.getInstruction(i)
172+
or
173+
this.(RawIndirectInstruction).getInstruction() = block.getInstruction(i)
174+
or
175+
this.(PostUpdateNode).getPreUpdateNode().hasIndexInBlock(block, i)
176+
}
177+
178+
/** Gets the basic block of this node, if any. */
179+
final IRBlock getBasicBlock() { this.hasIndexInBlock(result, _) }
180+
163181
/**
164182
* Gets the non-conversion expression corresponding to this node, if any.
165183
* This predicate only has a result on nodes that represent the value of
@@ -530,7 +548,7 @@ class SsaPhiNode extends Node, TSsaPhiNode {
530548
*/
531549
final Node getAnInput(boolean fromBackEdge) {
532550
localFlowStep(result, this) and
533-
if phi.getBasicBlock().dominates(getBasicBlock(result))
551+
if phi.getBasicBlock().dominates(result.getBasicBlock())
534552
then fromBackEdge = true
535553
else fromBackEdge = false
536554
}
@@ -1887,7 +1905,7 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
18871905
e = value.getAnInstruction().getConvertedResultExpression() and
18881906
result.getConvertedExpr() = e and
18891907
guardChecks(g, value.getAnInstruction().getConvertedResultExpression(), edge) and
1890-
g.controls(getBasicBlock(result), edge)
1908+
g.controls(result.getBasicBlock(), edge)
18911909
)
18921910
}
18931911
}

0 commit comments

Comments
 (0)