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 55private import SemanticExpr
66private import SemanticExprSpecific:: SemanticExprConfig as Specific
77private import SemanticSSA
8+ private import semmle.code.cpp.Location // TODO: SemLocation?
89
910/**
1011 * A valid base for an expression bound.
@@ -14,6 +15,8 @@ private import SemanticSSA
1415class SemBound instanceof Specific:: Bound {
1516 final string toString ( ) { result = super .toString ( ) }
1617
18+ final Location getLocation ( ) { result = super .getLocation ( ) }
19+
1720 final SemExpr getExpr ( int delta ) { result = Specific:: getBoundExpr ( this , delta ) }
1821}
1922
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
44private import RangeUtils
55private import experimental.semmle.code.cpp.semantic.SemanticBound as SemanticBound
66private import semmle.code.cpp.ir.IR as IR
7+ private import semmle.code.cpp.Location // TODO: SemLocation?
78
89private module ConstantBounds implements BoundSig< FloatDelta > {
910 class SemBound instanceof SemanticBound:: SemBound {
@@ -15,6 +16,8 @@ private module ConstantBounds implements BoundSig<FloatDelta> {
1516
1617 string toString ( ) { result = super .toString ( ) }
1718
19+ Location getLocation ( ) { result = super .getLocation ( ) }
20+
1821 SemExpr getExpr ( float delta ) { result = super .getExpr ( delta ) }
1922 }
2023
@@ -26,9 +29,11 @@ private module ConstantBounds implements BoundSig<FloatDelta> {
2629}
2730
2831private module RelativeBounds implements BoundSig< FloatDelta > {
29- class SemBound instanceof SemanticBound:: SemSsaBound {
32+ class SemBound instanceof SemanticBound:: SemBound {
3033 string toString ( ) { result = super .toString ( ) }
3134
35+ Location getLocation ( ) { result = super .getLocation ( ) }
36+
3237 SemExpr getExpr ( float delta ) { result = super .getExpr ( delta ) }
3338 }
3439
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ import experimental.semmle.code.cpp.semantic.SemanticCFG
7373import experimental.semmle.code.cpp.semantic.SemanticType
7474import experimental.semmle.code.cpp.semantic.SemanticOpcode
7575private import ConstantAnalysis
76+ private import semmle.code.cpp.Location
7677
7778/**
7879 * Holds if `typ` is a small integral type with the given lower and upper bounds.
@@ -228,6 +229,8 @@ signature module UtilSig<DeltaSig DeltaParam> {
228229
229230signature module BoundSig< DeltaSig D> {
230231 class SemBound {
232+ string toString ( ) ;
233+ Location getLocation ( ) ;
231234 SemExpr getExpr ( D:: Delta delta ) ;
232235 }
233236
You can’t perform that action at this time.
0 commit comments