Skip to content

Commit d42e892

Browse files
committed
Fix more joins.
Before: ``` Tuple counts for valueFlowStepSsa#4#ffff/4@2cddce6j after 11.4s: 11571217 ~3% {3} r1 = SCAN semSsaUpdateStep#3#fff OUTPUT In.0 'v', In.1 'e', f2i(In.2) 11992425 ~0% {4} r2 = JOIN r1 WITH SemanticSSA#aa9d1d08::SemSsaReadPosition::hasReadOfVar#1#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.0 'v', Rhs.1 'pos', Lhs.1 'e', Lhs.2 'delta' 869481225 ~2% {4} r3 = JOIN SemanticGuard#7b46a302::semGuardDirectlyControlsSsaRead#3#fff_102#join_rhs WITH SemanticSSA#aa9d1d08::SemSsaReadPosition::hasReadOfVar#1#dispred#ff ON FIRST 1 OUTPUT Rhs.1 'v', Lhs.2, Lhs.1, Lhs.0 'pos' 5749 ~0% {4} r4 = JOIN r3 WITH semEqFlowCond#5#fffbff#cpe#12356_03412#join_rhs ON FIRST 3 OUTPUT Lhs.3 'pos', Lhs.0 'v', Rhs.3 'e', Rhs.4 5749 ~1% {4} r5 = SCAN r4 OUTPUT In.0 'pos', In.1 'v', In.2 'e', f2i(In.3) 5749 ~0% {4} r6 = SCAN r5 OUTPUT In.1 'v', In.0 'pos', In.2 'e', In.3 'delta' 11998174 ~0% {4} r7 = r2 UNION r6 return r7 ``` After: ``` Tuple counts for valueFlowStepSsaEqFlowCond#4#ffff/4@f196e4ok after 37ms: 59567 ~0% {5} r1 = JOIN const_true WITH semEqFlowCond#5#ffffff_301245#join_rhs ON FIRST 1 OUTPUT Rhs.1 'v', Rhs.2 'e', Rhs.4, Rhs.5, Rhs.3 59567 ~0% {5} r2 = SCAN r1 OUTPUT In.0 'v', In.1 'e', In.2, In.3, f2i(In.4) 59567 ~4% {5} r3 = SCAN r2 OUTPUT In.3, In.2, In.0 'v', In.1 'e', In.4 'delta' 176881 ~0% {4} r4 = JOIN r3 WITH SemanticGuard#7b46a302::semGuardDirectlyControlsSsaRead#3#fff_021#join_rhs ON FIRST 2 OUTPUT Rhs.2 'pos', Lhs.2 'v', Lhs.3 'e', Lhs.4 'delta' return r4 Tuple counts for valueFlowStepSsa#4#ffff/4@e22d39v5 after 1s: 5749 ~0% {4} r1 = JOIN SemanticSSA#aa9d1d08::SemSsaReadPosition::hasReadOfVar#1#dispred#ff WITH valueFlowStepSsaEqFlowCond#4#ffff ON FIRST 2 OUTPUT Lhs.1 'v', Lhs.0 'pos', Rhs.2 'e', Rhs.3 'delta' 11571217 ~0% {3} r2 = SCAN semSsaUpdateStep#3#fff OUTPUT In.0 'v', In.1 'e', f2i(In.2) 11992425 ~0% {4} r3 = JOIN r2 WITH SemanticSSA#aa9d1d08::SemSsaReadPosition::hasReadOfVar#1#dispred#ff_10#join_rhs ON FIRST 1 OUTPUT Lhs.0 'v', Rhs.1 'pos', Lhs.1 'e', Lhs.2 'delta' 11998174 ~0% {4} r4 = r1 UNION r3 return r4 ```
1 parent 4e6707f commit d42e892

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ predicate semImplies_v2(SemGuard g1, boolean b1, SemGuard g2, boolean b2) {
3939
* Holds if `guard` directly controls the position `controlled` with the
4040
* value `testIsTrue`.
4141
*/
42+
pragma[nomagic]
4243
predicate semGuardDirectlyControlsSsaRead(
4344
SemGuard guard, SemSsaReadPosition controlled, boolean testIsTrue
4445
) {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,25 @@ private import RangeUtils
1717
private import RangeAnalysisStage
1818

1919
module ModulusAnalysis<DeltaSig D, BoundSig<D> Bounds, UtilSig<D> U> {
20+
pragma[nomagic]
21+
private predicate valueFlowStepSsaEqFlowCond(
22+
SemSsaReadPosition pos, SemSsaVariable v, SemExpr e, int delta
23+
) {
24+
exists(SemGuard guard, boolean testIsTrue |
25+
guard = U::semEqFlowCond(v, e, D::fromInt(delta), true, testIsTrue) and
26+
semGuardDirectlyControlsSsaRead(guard, pos, testIsTrue)
27+
)
28+
}
29+
2030
/**
2131
* Holds if `e + delta` equals `v` at `pos`.
2232
*/
33+
pragma[nomagic]
2334
private predicate valueFlowStepSsa(SemSsaVariable v, SemSsaReadPosition pos, SemExpr e, int delta) {
2435
U::semSsaUpdateStep(v, e, D::fromInt(delta)) and pos.hasReadOfVar(v)
2536
or
26-
exists(SemGuard guard, boolean testIsTrue |
27-
pos.hasReadOfVar(v) and
28-
guard = U::semEqFlowCond(v, e, D::fromInt(delta), true, testIsTrue) and
29-
semGuardDirectlyControlsSsaRead(guard, pos, testIsTrue)
30-
)
37+
pos.hasReadOfVar(v) and
38+
valueFlowStepSsaEqFlowCond(pos, v, e, delta)
3139
}
3240

3341
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module RangeUtil<Range::DeltaSig D, Range::LangSig<D> Lang> implements Range::Ut
4949
* - `isEq = true` : `v == e + delta`
5050
* - `isEq = false` : `v != e + delta`
5151
*/
52+
pragma[nomagic]
5253
SemGuard semEqFlowCond(
5354
SemSsaVariable v, SemExpr e, D::Delta delta, boolean isEq, boolean testIsTrue
5455
) {

0 commit comments

Comments
 (0)