Skip to content

Commit 86fd2d5

Browse files
authored
Merge pull request github#12747 from MathiasVP/promote-new-range-analysis-out-of-experimental
C++: Promote IR-based range-analysis library out of experimental
2 parents 9612bb9 + f007083 commit 86fd2d5

36 files changed

+140
-142
lines changed
Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1 @@
1-
import cpp
2-
private import semmle.code.cpp.ir.IR
3-
private import semmle.code.cpp.ir.ValueNumbering
4-
5-
private newtype TBound =
6-
TBoundZero() or
7-
TBoundValueNumber(ValueNumber vn) {
8-
exists(Instruction i |
9-
vn.getAnInstruction() = i and
10-
(
11-
i.getResultIRType() instanceof IRIntegerType or
12-
i.getResultIRType() instanceof IRAddressType
13-
) and
14-
not vn.getAnInstruction() instanceof ConstantInstruction
15-
|
16-
i instanceof PhiInstruction
17-
or
18-
i instanceof InitializeParameterInstruction
19-
or
20-
i instanceof CallInstruction
21-
or
22-
i instanceof VariableAddressInstruction
23-
or
24-
i instanceof FieldAddressInstruction
25-
or
26-
i.(LoadInstruction).getSourceAddress() instanceof VariableAddressInstruction
27-
or
28-
i.(LoadInstruction).getSourceAddress() instanceof FieldAddressInstruction
29-
or
30-
i.getAUse() instanceof ArgumentOperand
31-
or
32-
i instanceof PointerArithmeticInstruction
33-
or
34-
i.getAUse() instanceof AddressOperand
35-
)
36-
}
37-
38-
/**
39-
* A bound that may be inferred for an expression plus/minus an integer delta.
40-
*/
41-
abstract class Bound extends TBound {
42-
abstract string toString();
43-
44-
/** Gets an expression that equals this bound plus `delta`. */
45-
abstract Instruction getInstruction(int delta);
46-
47-
/** Gets an expression that equals this bound. */
48-
Instruction getInstruction() { result = getInstruction(0) }
49-
50-
abstract Location getLocation();
51-
}
52-
53-
/**
54-
* The bound that corresponds to the integer 0. This is used to represent all
55-
* integer bounds as bounds are always accompanied by an added integer delta.
56-
*/
57-
class ZeroBound extends Bound, TBoundZero {
58-
override string toString() { result = "0" }
59-
60-
override Instruction getInstruction(int delta) {
61-
result.(ConstantValueInstruction).getValue().toInt() = delta
62-
}
63-
64-
override Location getLocation() { result instanceof UnknownDefaultLocation }
65-
}
66-
67-
/**
68-
* A bound corresponding to the value of an `Instruction`.
69-
*/
70-
class ValueNumberBound extends Bound, TBoundValueNumber {
71-
ValueNumber vn;
72-
73-
ValueNumberBound() { this = TBoundValueNumber(vn) }
74-
75-
/** Gets an `Instruction` that equals this bound. */
76-
override Instruction getInstruction(int delta) {
77-
this = TBoundValueNumber(valueNumber(result)) and delta = 0
78-
}
79-
80-
override string toString() { result = "ValueNumberBound" }
81-
82-
override Location getLocation() { result = vn.getLocation() }
83-
84-
/** Gets the value number that equals this bound. */
85-
ValueNumber getValueNumber() { result = vn }
86-
}
1+
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.Bound

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysis.qll

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

cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/SimpleRangeAnalysis.qll renamed to cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/SimpleRangeAnalysis.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
private import cpp
77
private import semmle.code.cpp.ir.IR
8-
private import experimental.semmle.code.cpp.semantic.SemanticBound
9-
private import experimental.semmle.code.cpp.semantic.SemanticExprSpecific
10-
private import RangeAnalysis
8+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticBound
9+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticExprSpecific
10+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeAnalysis
1111

1212
/**
1313
* Gets the lower bound of the expression.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
private import cpp as Cpp
66
private import semmle.code.cpp.ir.IR as IR
77
private import Semantic
8-
private import experimental.semmle.code.cpp.rangeanalysis.Bound as IRBound
8+
private import analysis.Bound as IRBound
99
private import semmle.code.cpp.controlflow.IRGuards as IRGuards
1010
private import semmle.code.cpp.ir.ValueNumbering
1111

0 commit comments

Comments
 (0)