Skip to content

Commit e4d22ea

Browse files
committed
C++: Add comment on why getGuardedUpperBound must have exactly one predecessor
1 parent d962fc4 commit e4d22ea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,13 @@ private float getGuardedUpperBound(VariableAccess guardedAccess) {
15401540
RangeSsaDefinition def, StackVariable v, VariableAccess guardVa, Expr guard, boolean branch
15411541
|
15421542
def.isGuardPhi(v, guardVa, guard, branch) and
1543+
// If the basic block for the variable access being examined has
1544+
// more than one predecessor, the guard phi node could originate
1545+
// from one of the predecessors. This is because the guard phi
1546+
// node is attached to the block at the end of the edge and not on
1547+
// the actual edge. It is therefore possible to determine which
1548+
// edge the guard phi node belongs to. The predicate below ensures
1549+
// that there is one predecessor, albeit somewhat conservative.
15431550
exists(unique(BasicBlock b | b = def.(BasicBlock).getAPredecessor())) and
15441551
guardedAccess = def.getAUse(v) and
15451552
result = max(float ub | upperBoundFromGuard(guard, guardVa, ub, branch))

0 commit comments

Comments
 (0)