File tree Expand file tree Collapse file tree 4 files changed +41
-1
lines changed
cpp/ql/lib/experimental/semmle/code/cpp/semantic Expand file tree Collapse file tree 4 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 5
5
private import SemanticExpr
6
6
private import SemanticExprSpecific:: SemanticExprConfig as Specific
7
7
private import SemanticSSA
8
+ private import semmle.code.cpp.Location // TODO: SemLocation?
8
9
9
10
/**
10
11
* A valid base for an expression bound.
@@ -14,6 +15,8 @@ private import SemanticSSA
14
15
class SemBound instanceof Specific:: Bound {
15
16
final string toString ( ) { result = super .toString ( ) }
16
17
18
+ final Location getLocation ( ) { result = super .getLocation ( ) }
19
+
17
20
final SemExpr getExpr ( int delta ) { result = Specific:: getBoundExpr ( this , delta ) }
18
21
}
19
22
Original file line number Diff line number Diff line change
1
+ private import RangeAnalysisStage
2
+
3
+ module IntDelta implements DeltaSig {
4
+ class Delta = int ;
5
+
6
+ bindingset [ d]
7
+ bindingset [ result ]
8
+ float toFloat ( Delta d ) { result = d }
9
+
10
+ bindingset [ d]
11
+ bindingset [ result ]
12
+ int toInt ( Delta d ) { result = d }
13
+
14
+ bindingset [ n]
15
+ bindingset [ result ]
16
+ Delta fromInt ( int n ) { result = n }
17
+
18
+ bindingset [ f]
19
+ Delta fromFloat ( float f ) {
20
+ result =
21
+ min ( float diff , float res |
22
+ diff = ( res - f ) and res = f .ceil ( )
23
+ or
24
+ diff = ( f - res ) and res = f .floor ( )
25
+ |
26
+ res order by diff
27
+ )
28
+ }
29
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ private import experimental.semmle.code.cpp.semantic.analysis.FloatDelta
4
4
private import RangeUtils
5
5
private import experimental.semmle.code.cpp.semantic.SemanticBound as SemanticBound
6
6
private import semmle.code.cpp.ir.IR as IR
7
+ private import semmle.code.cpp.Location // TODO: SemLocation?
7
8
8
9
private module ConstantBounds implements BoundSig< FloatDelta > {
9
10
class SemBound instanceof SemanticBound:: SemBound {
@@ -15,6 +16,8 @@ private module ConstantBounds implements BoundSig<FloatDelta> {
15
16
16
17
string toString ( ) { result = super .toString ( ) }
17
18
19
+ Location getLocation ( ) { result = super .getLocation ( ) }
20
+
18
21
SemExpr getExpr ( float delta ) { result = super .getExpr ( delta ) }
19
22
}
20
23
@@ -26,9 +29,11 @@ private module ConstantBounds implements BoundSig<FloatDelta> {
26
29
}
27
30
28
31
private module RelativeBounds implements BoundSig< FloatDelta > {
29
- class SemBound instanceof SemanticBound:: SemSsaBound {
32
+ class SemBound instanceof SemanticBound:: SemBound {
30
33
string toString ( ) { result = super .toString ( ) }
31
34
35
+ Location getLocation ( ) { result = super .getLocation ( ) }
36
+
32
37
SemExpr getExpr ( float delta ) { result = super .getExpr ( delta ) }
33
38
}
34
39
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import experimental.semmle.code.cpp.semantic.SemanticCFG
73
73
import experimental.semmle.code.cpp.semantic.SemanticType
74
74
import experimental.semmle.code.cpp.semantic.SemanticOpcode
75
75
private import ConstantAnalysis
76
+ private import semmle.code.cpp.Location
76
77
77
78
/**
78
79
* Holds if `typ` is a small integral type with the given lower and upper bounds.
@@ -228,6 +229,8 @@ signature module UtilSig<DeltaSig DeltaParam> {
228
229
229
230
signature module BoundSig< DeltaSig D> {
230
231
class SemBound {
232
+ string toString ( ) ;
233
+ Location getLocation ( ) ;
231
234
SemExpr getExpr ( D:: Delta delta ) ;
232
235
}
233
236
You can’t perform that action at this time.
0 commit comments