Skip to content

Commit 914e621

Browse files
authored
Merge pull request github#6678 from andersfugmann/refactor_use_of_isGuardPhi
C++: Refactor code to use predicate isGuardPhi/4
2 parents 06eb93d + 79549c2 commit 914e621

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/NanAnalysis.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ predicate nanExcludingComparison(ComparisonOperation guard, boolean polarity) {
2929
*/
3030
private predicate excludesNan(RangeSsaDefinition def, VariableAccess v) {
3131
exists(VariableAccess inCond, ComparisonOperation guard, boolean branch, StackVariable lsv |
32-
def.isGuardPhi(inCond, guard, branch) and
33-
inCond.getTarget() = lsv and
32+
def.isGuardPhi(lsv, inCond, guard, branch) and
3433
v = def.getAUse(lsv) and
3534
guard.getAnOperand() = inCond and
3635
nanExcludingComparison(guard, branch)

cpp/ql/lib/semmle/code/cpp/rangeanalysis/RangeSSA.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ class RangeSsaDefinition extends ControlFlowNodeBase {
9494
predicate isPhiNode(StackVariable v) { exists(RangeSSA x | x.phi_node(v, this.(BasicBlock))) }
9595

9696
/**
97+
* DEPRECATED: Use isGuardPhi/4 instead
9798
* If this definition is a phi node corresponding to a guard,
9899
* then return the variable access and the guard.
99100
*/
100-
predicate isGuardPhi(VariableAccess va, Expr guard, boolean branch) {
101+
deprecated predicate isGuardPhi(VariableAccess va, Expr guard, boolean branch) {
101102
guard_defn(va, guard, this, branch)
102103
}
103104

@@ -142,9 +143,8 @@ class RangeSsaDefinition extends ControlFlowNodeBase {
142143
// below excludes definitions which can only reach guard phi
143144
// nodes by going through the corresponding guard.
144145
not exists(VariableAccess access |
145-
v = access.getTarget() and
146146
pred.contains(access) and
147-
this.isGuardPhi(access, _, _)
147+
this.isGuardPhi(v, access, _, _)
148148
)
149149
)
150150
}

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,7 @@ private predicate exprDependsOnDef(Expr e, RangeSsaDefinition srcDef, StackVaria
433433
private predicate phiDependsOnDef(
434434
RangeSsaDefinition phi, StackVariable v, RangeSsaDefinition srcDef, StackVariable srcVar
435435
) {
436-
exists(VariableAccess access, Expr guard |
437-
access = v.getAnAccess() and
438-
phi.isGuardPhi(access, guard, _)
439-
|
436+
exists(VariableAccess access, Expr guard | phi.isGuardPhi(v, access, guard, _) |
440437
exprDependsOnDef(guard.(ComparisonOperation).getAnOperand(), srcDef, srcVar) or
441438
exprDependsOnDef(access, srcDef, srcVar)
442439
)
@@ -1204,8 +1201,7 @@ private float boolConversionUpperBound(Expr expr) {
12041201
*/
12051202
private float getPhiLowerBounds(StackVariable v, RangeSsaDefinition phi) {
12061203
exists(VariableAccess access, Expr guard, boolean branch, float defLB, float guardLB |
1207-
access = v.getAnAccess() and
1208-
phi.isGuardPhi(access, guard, branch) and
1204+
phi.isGuardPhi(v, access, guard, branch) and
12091205
lowerBoundFromGuard(guard, access, guardLB, branch) and
12101206
defLB = getFullyConvertedLowerBounds(access)
12111207
|
@@ -1230,8 +1226,7 @@ private float getPhiLowerBounds(StackVariable v, RangeSsaDefinition phi) {
12301226
/** See comment for `getPhiLowerBounds`, above. */
12311227
private float getPhiUpperBounds(StackVariable v, RangeSsaDefinition phi) {
12321228
exists(VariableAccess access, Expr guard, boolean branch, float defUB, float guardUB |
1233-
access = v.getAnAccess() and
1234-
phi.isGuardPhi(access, guard, branch) and
1229+
phi.isGuardPhi(v, access, guard, branch) and
12351230
upperBoundFromGuard(guard, access, guardUB, branch) and
12361231
defUB = getFullyConvertedUpperBounds(access)
12371232
|
@@ -1493,8 +1488,7 @@ private predicate isNEPhi(
14931488
exists(
14941489
ComparisonOperation cmp, boolean branch, Expr linearExpr, Expr rExpr, float p, float q, float r
14951490
|
1496-
access.getTarget() = v and
1497-
phi.isGuardPhi(access, cmp, branch) and
1491+
phi.isGuardPhi(v, access, cmp, branch) and
14981492
eqOpWithSwapAndNegate(cmp, linearExpr, rExpr, false, branch) and
14991493
v.getUnspecifiedType() instanceof IntegralOrEnumType and // Float `!=` is too imprecise
15001494
r = getValue(rExpr).toFloat() and
@@ -1503,8 +1497,7 @@ private predicate isNEPhi(
15031497
)
15041498
or
15051499
exists(Expr op, boolean branch, Expr linearExpr, float p, float q |
1506-
access.getTarget() = v and
1507-
phi.isGuardPhi(access, op, branch) and
1500+
phi.isGuardPhi(v, access, op, branch) and
15081501
eqZeroWithNegate(op, linearExpr, false, branch) and
15091502
v.getUnspecifiedType() instanceof IntegralOrEnumType and // Float `!` is too imprecise
15101503
linearAccess(linearExpr, access, p, q) and
@@ -1524,8 +1517,7 @@ private predicate isUnsupportedGuardPhi(Variable v, RangeSsaDefinition phi, Vari
15241517
or
15251518
eqZeroWithNegate(cmp, _, false, branch)
15261519
|
1527-
access.getTarget() = v and
1528-
phi.isGuardPhi(access, cmp, branch) and
1520+
phi.isGuardPhi(v, access, cmp, branch) and
15291521
not isNEPhi(v, phi, access, _)
15301522
)
15311523
}

0 commit comments

Comments
 (0)