Skip to content

Commit 6d7a75d

Browse files
authored
Merge pull request github#13931 from MathiasVP/revert-constant-bounds-and-prep
C++: Revert constant bounds for new range analysis
2 parents 6e8f600 + acd16af commit 6d7a75d

File tree

10 files changed

+71
-272
lines changed

10 files changed

+71
-272
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,3 @@ class SemConditionalExpr extends SemKnownExpr {
307307
branch = false and result = falseResult
308308
}
309309
}
310-
311-
/** Holds if `upper = true` and `e <= bound` or `upper = false` and `e >= bound`. */
312-
predicate semHasConstantBoundConstantSpecific(SemExpr e, float bound, boolean upper) {
313-
Specific::hasConstantBoundConstantSpecific(e, bound, upper)
314-
}

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -434,50 +434,6 @@ module SemanticExprConfig {
434434

435435
/** Gets the expression associated with `instr`. */
436436
SemExpr getSemanticExpr(IR::Instruction instr) { result = Equiv::getEquivalenceClass(instr) }
437-
438-
private predicate typeBounds(SemType t, float lb, float ub) {
439-
exists(SemIntegerType integralType, float limit |
440-
integralType = t and limit = 2.pow(8 * integralType.getByteSize())
441-
|
442-
if integralType instanceof SemBooleanType
443-
then lb = 0 and ub = 1
444-
else
445-
if integralType.isSigned()
446-
then (
447-
lb = -(limit / 2) and ub = (limit / 2) - 1
448-
) else (
449-
lb = 0 and ub = limit - 1
450-
)
451-
)
452-
or
453-
// This covers all floating point types. The range is (-Inf, +Inf).
454-
t instanceof SemFloatingPointType and lb = -(1.0 / 0.0) and ub = 1.0 / 0.0
455-
}
456-
457-
/**
458-
* Holds if `upper = true` and `e <= bound` or `upper = false` and `e >= bound` based
459-
* only on type information.
460-
*/
461-
predicate hasConstantBoundConstantSpecific(Expr e, float bound, boolean upper) {
462-
exists(
463-
SemType converted, SemType unconverted, float unconvertedLb, float convertedLb,
464-
float unconvertedUb, float convertedUb
465-
|
466-
unconverted = getSemanticType(e.getUnconverted().getResultIRType()) and
467-
converted = getSemanticType(e.getConverted().getResultIRType()) and
468-
typeBounds(unconverted, unconvertedLb, unconvertedUb) and
469-
typeBounds(converted, convertedLb, convertedUb) and
470-
(
471-
upper = true and
472-
unconvertedUb < convertedUb and
473-
bound = unconvertedUb
474-
or
475-
upper = false and
476-
unconvertedLb > convertedLb and
477-
bound = unconvertedLb
478-
)
479-
)
480-
}
481437
}
482438

483439
predicate getSemanticExpr = SemanticExprConfig::getSemanticExpr/1;
@@ -501,5 +457,3 @@ IRBound::Bound getCppBound(SemBound bound) { bound = result }
501457
SemGuard getSemanticGuard(IRGuards::IRGuardCondition guard) { result = guard }
502458

503459
IRGuards::IRGuardCondition getCppGuard(SemGuard guard) { guard = result }
504-
505-
predicate hasConstantBoundConstantSpecific = SemanticExprConfig::hasConstantBoundConstantSpecific/3;

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

Lines changed: 1 addition & 18 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
*
@@ -74,10 +60,7 @@ module CppLangImplConstant implements LangSig<FloatDelta> {
7460
/**
7561
* Holds if `e >= bound` (if `upper = false`) or `e <= bound` (if `upper = true`).
7662
*/
77-
predicate hasConstantBound(SemExpr e, float bound, boolean upper, SemReason reason) {
78-
semHasConstantBoundConstantSpecific(e, bound, upper) and
79-
reason instanceof SemTypeReason
80-
}
63+
predicate hasConstantBound(SemExpr e, float bound, boolean upper) { none() }
8164

8265
/**
8366
* Holds if `e >= bound + delta` (if `upper = false`) or `e <= bound + delta` (if `upper = true`).

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: 1 addition & 17 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
*
@@ -110,7 +94,7 @@ module CppLangImplRelative implements LangSig<FloatDelta> {
11094
/**
11195
* Holds if `e >= bound` (if `upper = false`) or `e <= bound` (if `upper = true`).
11296
*/
113-
predicate hasConstantBound(SemExpr e, float bound, boolean upper, SemReason reason) { none() }
97+
predicate hasConstantBound(SemExpr e, float bound, boolean upper) { none() }
11498

11599
/**
116100
* Holds if `e >= bound + delta` (if `upper = false`) or `e <= bound + delta` (if `upper = true`).

0 commit comments

Comments
 (0)