Skip to content

Commit b8e7e1d

Browse files
committed
Java/C++: Share ssaUpdateStep.
1 parent daffae0 commit b8e7e1d

File tree

6 files changed

+31
-49
lines changed

6 files changed

+31
-49
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ private import RangeAnalysisImpl
99
private import ConstantAnalysis
1010

1111
module RangeUtil<DeltaSig D, LangSig<Sem, D> Lang> implements UtilSig<Sem, D> {
12-
/**
13-
* Holds if `v` is an `SsaExplicitUpdate` that equals `e + delta`.
14-
*/
15-
predicate semSsaUpdateStep(SemSsaExplicitUpdate v, SemExpr e, D::Delta delta) {
16-
exists(SemExpr defExpr | defExpr = v.getSourceExpr() |
17-
defExpr.(SemCopyValueExpr).getOperand() = e and delta = D::fromFloat(0)
18-
or
19-
defExpr.(SemStoreExpr).getOperand() = e and delta = D::fromFloat(0)
20-
or
21-
defExpr.(SemAddOneExpr).getOperand() = e and delta = D::fromFloat(1)
22-
or
23-
defExpr.(SemSubOneExpr).getOperand() = e and delta = D::fromFloat(-1)
24-
or
25-
e = defExpr and
26-
not (
27-
defExpr instanceof SemCopyValueExpr or
28-
defExpr instanceof SemStoreExpr or
29-
defExpr instanceof SemAddOneExpr or
30-
defExpr instanceof SemSubOneExpr
31-
) and
32-
delta = D::fromFloat(0)
33-
)
34-
}
35-
3612
/**
3713
* Holds if `e1 + delta` equals `e2`.
3814
*/

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,6 @@ module JavaLangImpl implements LangSig<Sem, IntDelta> {
372372
module Utils implements UtilSig<Sem, IntDelta> {
373373
private import RangeUtils as RU
374374

375-
predicate semSsaUpdateStep(Sem::SsaExplicitUpdate v, Sem::Expr e, int delta) {
376-
RU::ssaUpdateStep(v, e, delta)
377-
}
378-
379375
predicate semValueFlowStep = RU::valueFlowStep/3;
380376

381377
Sem::Type getTrackedTypeForSsaVariable(Sem::SsaVariable var) {

java/ql/lib/semmle/code/java/dataflow/RangeUtils.qll

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ private predicate backEdge = U::backEdge/3;
1515

1616
predicate ssaRead = U::ssaRead/2;
1717

18+
predicate ssaUpdateStep = U::ssaUpdateStep/3;
19+
1820
predicate guardDirectlyControlsSsaRead = U::guardDirectlyControlsSsaRead/3;
1921

2022
predicate guardControlsSsaRead = U::guardControlsSsaRead/3;
@@ -158,23 +160,6 @@ class ConstantStringExpr extends Expr {
158160
string getStringValue() { constantStringExpr(this, result) }
159161
}
160162

161-
/**
162-
* Holds if `v` is an `SsaExplicitUpdate` that equals `e + delta`.
163-
*/
164-
predicate ssaUpdateStep(SsaExplicitUpdate v, Expr e, int delta) {
165-
v.getDefiningExpr().(VariableAssign).getSource() = e and delta = 0
166-
or
167-
v.getDefiningExpr().(PostIncExpr).getExpr() = e and delta = 1
168-
or
169-
v.getDefiningExpr().(PreIncExpr).getExpr() = e and delta = 1
170-
or
171-
v.getDefiningExpr().(PostDecExpr).getExpr() = e and delta = -1
172-
or
173-
v.getDefiningExpr().(PreDecExpr).getExpr() = e and delta = -1
174-
or
175-
v.getDefiningExpr().(AssignOp) = e and delta = 0
176-
}
177-
178163
/**
179164
* Holds if `e1 + delta` equals `e2`.
180165
*/

shared/rangeanalysis/codeql/rangeanalysis/ModulusAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module ModulusAnalysis<
3030
*/
3131
pragma[nomagic]
3232
private predicate valueFlowStepSsa(Sem::SsaVariable v, SsaReadPosition pos, Sem::Expr e, int delta) {
33-
U::semSsaUpdateStep(v, e, D::fromInt(delta)) and pos.hasReadOfVar(v)
33+
ssaUpdateStep(v, e, D::fromInt(delta)) and pos.hasReadOfVar(v)
3434
or
3535
exists(Sem::Guard guard, boolean testIsTrue |
3636
hasReadOfVarInlineLate(pos, v) and

shared/rangeanalysis/codeql/rangeanalysis/RangeAnalysis.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,6 @@ signature module LangSig<Semantic Sem, DeltaSig D> {
304304
}
305305

306306
signature module UtilSig<Semantic Sem, DeltaSig DeltaParam> {
307-
predicate semSsaUpdateStep(Sem::SsaExplicitUpdate v, Sem::Expr e, DeltaParam::Delta delta);
308-
309307
predicate semValueFlowStep(Sem::Expr e2, Sem::Expr e1, DeltaParam::Delta delta);
310308

311309
/**
@@ -671,7 +669,7 @@ module RangeStage<
671669
Sem::SsaVariable v, SsaReadPosition pos, Sem::Expr e, D::Delta delta, boolean upper,
672670
SemReason reason
673671
) {
674-
semSsaUpdateStep(v, e, delta) and
672+
ssaUpdateStep(v, e, delta) and
675673
pos.hasReadOfVar(v) and
676674
(upper = true or upper = false) and
677675
reason = TSemNoReason()

shared/rangeanalysis/codeql/rangeanalysis/internal/RangeUtils.qll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,33 @@ module MakeUtils<Semantic Lang, DeltaSig D> {
5757
)
5858
}
5959

60+
/**
61+
* Holds if `v` is an `SsaExplicitUpdate` that equals `e + delta`.
62+
*/
63+
predicate ssaUpdateStep(SsaExplicitUpdate v, Expr e, D::Delta delta) {
64+
exists(Expr defExpr | defExpr = v.getDefiningExpr() |
65+
defExpr.(CopyValueExpr).getOperand() = e and delta = D::fromFloat(0)
66+
or
67+
defExpr.(PostIncExpr).getOperand() = e and delta = D::fromFloat(1)
68+
or
69+
defExpr.(PreIncExpr).getOperand() = e and delta = D::fromFloat(1)
70+
or
71+
defExpr.(PostDecExpr).getOperand() = e and delta = D::fromFloat(-1)
72+
or
73+
defExpr.(PreDecExpr).getOperand() = e and delta = D::fromFloat(-1)
74+
or
75+
e = defExpr and
76+
not (
77+
defExpr instanceof CopyValueExpr or
78+
defExpr instanceof PostIncExpr or
79+
defExpr instanceof PreIncExpr or
80+
defExpr instanceof PostDecExpr or
81+
defExpr instanceof PreDecExpr
82+
) and
83+
delta = D::fromFloat(0)
84+
)
85+
}
86+
6087
private newtype TSsaReadPosition =
6188
TSsaReadPositionBlock(BasicBlock bb) {
6289
exists(SsaVariable v | v.getAUse().getBasicBlock() = bb)

0 commit comments

Comments
 (0)