Skip to content

Commit acd16af

Browse files
committed
Revert "Merge pull request github#13880 from MathiasVP/type-bounds-preparation"
This reverts commit 3e9d9e7, reversing changes made to 877ee70.
1 parent cb1076c commit acd16af

File tree

5 files changed

+51
-195
lines changed

5 files changed

+51
-195
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,10 @@
33
*/
44

55
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
6-
private import codeql.util.Unit
7-
private import Reason as Reason
86
private import RangeAnalysisStage
97
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
108

119
module CppLangImplConstant implements LangSig<FloatDelta> {
12-
private module Param implements Reason::ParamSig {
13-
class TypeReasonImpl = Unit;
14-
}
15-
16-
class SemReason = Reason::Make<Param>::SemReason;
17-
18-
class SemNoReason = Reason::Make<Param>::SemNoReason;
19-
20-
class SemCondReason = Reason::Make<Param>::SemCondReason;
21-
22-
class SemTypeReason = Reason::Make<Param>::SemTypeReason;
23-
2410
/**
2511
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
2612
*

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,18 @@ private newtype TSemReason =
6161
guard = any(ConstantStage::SemCondReason reason).getCond()
6262
or
6363
guard = any(RelativeStage::SemCondReason reason).getCond()
64-
} or
65-
TSemTypeReason()
64+
}
6665

67-
private ConstantStage::SemReason constantReason(SemReason reason) {
66+
ConstantStage::SemReason constantReason(SemReason reason) {
6867
result instanceof ConstantStage::SemNoReason and reason instanceof SemNoReason
6968
or
7069
result.(ConstantStage::SemCondReason).getCond() = reason.(SemCondReason).getCond()
71-
or
72-
result instanceof ConstantStage::SemTypeReason and reason instanceof SemTypeReason
7370
}
7471

75-
private RelativeStage::SemReason relativeReason(SemReason reason) {
72+
RelativeStage::SemReason relativeReason(SemReason reason) {
7673
result instanceof RelativeStage::SemNoReason and reason instanceof SemNoReason
7774
or
7875
result.(RelativeStage::SemCondReason).getCond() = reason.(SemCondReason).getCond()
79-
or
80-
result instanceof RelativeStage::SemTypeReason and reason instanceof SemTypeReason
8176
}
8277

8378
import Public
@@ -116,12 +111,4 @@ module Public {
116111

117112
override string toString() { result = this.getCond().toString() }
118113
}
119-
120-
/**
121-
* A reason for an inferred bound that indicates that the bound is inferred
122-
* based on type-information.
123-
*/
124-
class SemTypeReason extends SemReason, TSemTypeReason {
125-
override string toString() { result = "TypeReason" }
126-
}
127114
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,9 @@ private import RangeAnalysisStage
77
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
88
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.IntDelta
99
private import RangeAnalysisImpl
10-
private import codeql.util.Unit
11-
private import Reason as Reason
1210
private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
1311

1412
module CppLangImplRelative implements LangSig<FloatDelta> {
15-
private module Param implements Reason::ParamSig {
16-
class TypeReasonImpl extends Unit {
17-
TypeReasonImpl() { none() }
18-
}
19-
}
20-
21-
class SemReason = Reason::Make<Param>::SemReason;
22-
23-
class SemNoReason = Reason::Make<Param>::SemNoReason;
24-
25-
class SemCondReason = Reason::Make<Param>::SemCondReason;
26-
27-
class SemTypeReason = Reason::Make<Param>::SemTypeReason;
28-
2913
/**
3014
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
3115
*

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

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,6 @@ signature module DeltaSig {
113113
}
114114

115115
signature module LangSig<DeltaSig D> {
116-
/** A reason for an inferred bound. */
117-
class SemReason {
118-
/**
119-
* Returns `this` if `reason` is not a `SemTypeReason`. Otherwise,
120-
* this predicate returns `SemTypeReason`.
121-
*
122-
* This predicate ensures that we propagate `SemTypeReason` all the way
123-
* to the top-level of a call to `semBounded` if the inferred bound is
124-
* based on type-information.
125-
*/
126-
bindingset[this, reason]
127-
SemReason combineWith(SemReason reason);
128-
}
129-
130-
/**
131-
* A reason for an inferred bound that indicates that the bound is inferred
132-
* without going through a bounding condition.
133-
*/
134-
class SemNoReason extends SemReason;
135-
136-
/** A reason for an inferred bound pointing to a condition. */
137-
class SemCondReason extends SemReason {
138-
SemGuard getCond();
139-
}
140-
141-
/**
142-
* A reason for an inferred bound that indicates that the bound is inferred
143-
* based on type-information.
144-
*/
145-
class SemTypeReason extends SemReason;
146-
147116
/**
148117
* Holds if the specified expression should be excluded from the result of `ssaRead()`.
149118
*
@@ -280,14 +249,6 @@ module RangeStage<
280249
DeltaSig D, BoundSig<D> Bounds, OverflowSig<D> OverflowParam, LangSig<D> LangParam,
281250
UtilSig<D> UtilParam>
282251
{
283-
class SemReason = LangParam::SemReason;
284-
285-
class SemCondReason = LangParam::SemCondReason;
286-
287-
class SemNoReason = LangParam::SemNoReason;
288-
289-
class SemTypeReason = LangParam::SemTypeReason;
290-
291252
private import Bounds
292253
private import LangParam
293254
private import UtilParam
@@ -548,6 +509,36 @@ module RangeStage<
548509
)
549510
}
550511

512+
private newtype TSemReason =
513+
TSemNoReason() or
514+
TSemCondReason(SemGuard guard) { possibleReason(guard) }
515+
516+
/**
517+
* A reason for an inferred bound. This can either be `CondReason` if the bound
518+
* is due to a specific condition, or `NoReason` if the bound is inferred
519+
* without going through a bounding condition.
520+
*/
521+
abstract class SemReason extends TSemReason {
522+
/** Gets a textual representation of this reason. */
523+
abstract string toString();
524+
}
525+
526+
/**
527+
* A reason for an inferred bound that indicates that the bound is inferred
528+
* without going through a bounding condition.
529+
*/
530+
class SemNoReason extends SemReason, TSemNoReason {
531+
override string toString() { result = "NoReason" }
532+
}
533+
534+
/** A reason for an inferred bound pointing to a condition. */
535+
class SemCondReason extends SemReason, TSemCondReason {
536+
/** Gets the condition that is the reason for the bound. */
537+
SemGuard getCond() { this = TSemCondReason(result) }
538+
539+
override string toString() { result = this.getCond().toString() }
540+
}
541+
551542
/**
552543
* Holds if `e + delta` is a valid bound for `v` at `pos`.
553544
* - `upper = true` : `v <= e + delta`
@@ -560,13 +551,13 @@ module RangeStage<
560551
semSsaUpdateStep(v, e, delta) and
561552
pos.hasReadOfVar(v) and
562553
(upper = true or upper = false) and
563-
reason instanceof SemNoReason
554+
reason = TSemNoReason()
564555
or
565556
exists(SemGuard guard, boolean testIsTrue |
566557
pos.hasReadOfVar(v) and
567558
guard = boundFlowCond(v, e, delta, upper, testIsTrue) and
568559
semGuardDirectlyControlsSsaRead(guard, pos, testIsTrue) and
569-
reason.(SemCondReason).getCond() = guard
560+
reason = TSemCondReason(guard)
570561
)
571562
}
572563

@@ -579,7 +570,7 @@ module RangeStage<
579570
pos.hasReadOfVar(v) and
580571
guard = semEqFlowCond(v, e, delta, false, testIsTrue) and
581572
semGuardDirectlyControlsSsaRead(guard, pos, testIsTrue) and
582-
reason.(SemCondReason).getCond() = guard
573+
reason = TSemCondReason(guard)
583574
)
584575
}
585576

@@ -709,7 +700,7 @@ module RangeStage<
709700
// upper = true: v <= mid + d1 <= b + d1 + d2 = b + delta
710701
// upper = false: v >= mid + d1 >= b + d1 + d2 = b + delta
711702
delta = D::fromFloat(D::toFloat(d1) + D::toFloat(d2)) and
712-
(if r1 instanceof SemNoReason then reason = r2 else reason = r1.combineWith(r2))
703+
(if r1 instanceof SemNoReason then reason = r2 else reason = r1)
713704
)
714705
or
715706
exists(D::Delta d, SemReason r1, SemReason r2 |
@@ -723,9 +714,9 @@ module RangeStage<
723714
upper = false and delta = D::fromFloat(D::toFloat(d) + 1)
724715
) and
725716
(
726-
reason = r1.combineWith(r2)
717+
reason = r1
727718
or
728-
reason = r2.combineWith(r1) and not r2 instanceof SemNoReason
719+
reason = r2 and not r2 instanceof SemNoReason
729720
)
730721
)
731722
}
@@ -795,7 +786,7 @@ module RangeStage<
795786
(upper = true or upper = false) and
796787
fromBackEdge0 = false and
797788
origdelta = D::fromFloat(0) and
798-
reason instanceof SemNoReason
789+
reason = TSemNoReason()
799790
|
800791
if semBackEdge(phi, inp, edge)
801792
then
@@ -1053,13 +1044,13 @@ module RangeStage<
10531044
(upper = true or upper = false) and
10541045
fromBackEdge = false and
10551046
origdelta = delta and
1056-
reason instanceof SemNoReason
1047+
reason = TSemNoReason()
10571048
or
10581049
baseBound(e, delta, upper) and
10591050
b instanceof SemZeroBound and
10601051
fromBackEdge = false and
10611052
origdelta = delta and
1062-
reason instanceof SemNoReason
1053+
reason = TSemNoReason()
10631054
or
10641055
exists(SemSsaVariable v, SemSsaReadPositionBlock bb |
10651056
boundedSsa(v, bb, b, delta, upper, fromBackEdge, origdelta, reason) and
@@ -1113,9 +1104,9 @@ module RangeStage<
11131104
boundedConditionalExpr(cond, b, upper, true, d1, fbe1, od1, r1) and
11141105
boundedConditionalExpr(cond, b, upper, false, d2, fbe2, od2, r2) and
11151106
(
1116-
delta = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1.combineWith(r2)
1107+
delta = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1
11171108
or
1118-
delta = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2.combineWith(r1)
1109+
delta = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2
11191110
)
11201111
|
11211112
upper = true and delta = D::fromFloat(D::toFloat(d1).maximum(D::toFloat(d2)))
@@ -1141,15 +1132,9 @@ module RangeStage<
11411132
delta = D::fromFloat(D::toFloat(dLeft) + D::toFloat(dRight)) and
11421133
fromBackEdge = fbeLeft.booleanOr(fbeRight)
11431134
|
1144-
b = bLeft and
1145-
origdelta = odLeft and
1146-
reason = rLeft.combineWith(rRight) and
1147-
bRight instanceof SemZeroBound
1135+
b = bLeft and origdelta = odLeft and reason = rLeft and bRight instanceof SemZeroBound
11481136
or
1149-
b = bRight and
1150-
origdelta = odRight and
1151-
reason = rRight.combineWith(rLeft) and
1152-
bLeft instanceof SemZeroBound
1137+
b = bRight and origdelta = odRight and reason = rRight and bLeft instanceof SemZeroBound
11531138
)
11541139
or
11551140
exists(
@@ -1165,9 +1150,9 @@ module RangeStage<
11651150
(
11661151
if D::toFloat(d1).abs() > D::toFloat(d2).abs()
11671152
then (
1168-
d_max = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1.combineWith(r2)
1153+
d_max = d1 and fromBackEdge = fbe1 and origdelta = od1 and reason = r1
11691154
) else (
1170-
d_max = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2.combineWith(r1)
1155+
d_max = d2 and fromBackEdge = fbe2 and origdelta = od2 and reason = r2
11711156
)
11721157
)
11731158
|
@@ -1183,14 +1168,11 @@ module RangeStage<
11831168
boundedMulOperand(e, upper, true, dLeft, fbeLeft, odLeft, rLeft) and
11841169
boundedMulOperand(e, upper, false, dRight, fbeRight, odRight, rRight) and
11851170
delta = D::fromFloat(D::toFloat(dLeft) * D::toFloat(dRight)) and
1186-
fromBackEdge = fbeLeft.booleanOr(fbeRight) and
1187-
b instanceof SemZeroBound
1171+
fromBackEdge = fbeLeft.booleanOr(fbeRight)
11881172
|
1189-
origdelta = odLeft and
1190-
reason = rLeft.combineWith(rRight)
1173+
b instanceof SemZeroBound and origdelta = odLeft and reason = rLeft
11911174
or
1192-
origdelta = odRight and
1193-
reason = rRight.combineWith(rLeft)
1175+
b instanceof SemZeroBound and origdelta = odRight and reason = rRight
11941176
)
11951177
)
11961178
}

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

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)