Skip to content

Commit 700a566

Browse files
author
Robert Marsh
committed
Merge branch 'rdmarsh2/stageify-range-analysis' into rdmarsh2/range-analysis-overflow
2 parents 6cef4cc + 726f999 commit 700a566

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticBound.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
private import SemanticExpr
66
private import SemanticExprSpecific::SemanticExprConfig as Specific
77
private import SemanticSSA
8-
private import semmle.code.cpp.Location // TODO: SemLocation?
8+
private import SemanticLocation // TODO: SemLocation?
99

1010
/**
1111
* A valid base for an expression bound.
@@ -15,7 +15,7 @@ private import semmle.code.cpp.Location // TODO: SemLocation?
1515
class SemBound instanceof Specific::Bound {
1616
final string toString() { result = super.toString() }
1717

18-
final Location getLocation() { result = super.getLocation() }
18+
final SemLocation getLocation() { result = super.getLocation() }
1919

2020
final SemExpr getExpr(int delta) { result = Specific::getBoundExpr(this, delta) }
2121
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
private import semmle.code.cpp.Location
2+
3+
class SemLocation instanceof Location {
4+
/**
5+
* Gets a textual representation of this element.
6+
*
7+
* The format is "file://filePath:startLine:startColumn:endLine:endColumn".
8+
*/
9+
string toString() { result = super.toString() }
10+
11+
/**
12+
* Holds if this element is at the specified location.
13+
* The location spans column `startcolumn` of line `startline` to
14+
* column `endcolumn` of line `endline` in file `filepath`.
15+
* For more information, see
16+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
17+
*/
18+
predicate hasLocationInfo(
19+
string filepath, int startline, int startcolumn, int endline, int endcolumn
20+
) {
21+
super.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
22+
}
23+
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ private import RangeAnalysisSpecific
33
private import experimental.semmle.code.cpp.semantic.analysis.FloatDelta
44
private import RangeUtils
55
private import experimental.semmle.code.cpp.semantic.SemanticBound as SemanticBound
6-
private import semmle.code.cpp.ir.IR as IR
7-
private import semmle.code.cpp.Location // TODO: SemLocation?
6+
private import experimental.semmle.code.cpp.semantic.SemanticLocation
7+
private import experimental.semmle.code.cpp.semantic.SemanticSSA
88

99
module ConstantBounds implements BoundSig<FloatDelta> {
1010
class SemBound instanceof SemanticBound::SemBound {
1111
SemBound() {
1212
this instanceof SemanticBound::SemZeroBound
1313
or
14-
this.(SemanticBound::SemSsaBound).getExpr(0) instanceof IR::PhiInstruction
14+
this.(SemanticBound::SemSsaBound).getAVariable() instanceof SemSsaPhiNode
1515
}
1616

1717
string toString() { result = super.toString() }
1818

19-
Location getLocation() { result = super.getLocation() }
19+
SemLocation getLocation() { result = super.getLocation() }
2020

2121
SemExpr getExpr(float delta) { result = super.getExpr(delta) }
2222
}
@@ -30,9 +30,11 @@ module ConstantBounds implements BoundSig<FloatDelta> {
3030

3131
module RelativeBounds implements BoundSig<FloatDelta> {
3232
class SemBound instanceof SemanticBound::SemBound {
33+
SemBound() { not this instanceof SemanticBound::SemZeroBound }
34+
3335
string toString() { result = super.toString() }
3436

35-
Location getLocation() { result = super.getLocation() }
37+
SemLocation getLocation() { result = super.getLocation() }
3638

3739
SemExpr getExpr(float delta) { result = super.getExpr(delta) }
3840
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import experimental.semmle.code.cpp.semantic.SemanticCFG
7373
import experimental.semmle.code.cpp.semantic.SemanticType
7474
import experimental.semmle.code.cpp.semantic.SemanticOpcode
7575
private import ConstantAnalysis
76-
private import semmle.code.cpp.Location
76+
import experimental.semmle.code.cpp.semantic.SemanticLocation
7777

7878
/**
7979
* Holds if `typ` is a small integral type with the given lower and upper bounds.
@@ -231,7 +231,7 @@ signature module BoundSig<DeltaSig D> {
231231
class SemBound {
232232
string toString();
233233

234-
Location getLocation();
234+
SemLocation getLocation();
235235

236236
SemExpr getExpr(D::Delta delta);
237237
}

cpp/ql/test/library-tests/ir/modulus-analysis/ModulusAnalysis.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import experimental.semmle.code.cpp.semantic.analysis.RangeUtils
66
import experimental.semmle.code.cpp.semantic.analysis.FloatDelta
77
import experimental.semmle.code.cpp.semantic.analysis.RangeAnalysisSpecific
88
import experimental.semmle.code.cpp.semantic.analysis.RangeAnalysisImpl
9-
import experimental.semmle.code.cpp.semantic.analysis.RangeAnalysisStage
109
import semmle.code.cpp.ir.IR as IR
1110
import TestUtilities.InlineExpectationsTest
1211

@@ -25,7 +24,7 @@ module Bounds implements BoundSig<FloatDelta> {
2524
}
2625

2726
module ModulusAnalysisInstantiated =
28-
ModulusAnalysis<FloatDelta, Bounds, RangeUtil<FloatDelta, CppLangImpl>>;
27+
ModulusAnalysis<FloatDelta, ConstantBounds, RangeUtil<FloatDelta, CppLangImpl>>;
2928

3029
class ModulusAnalysisTest extends InlineExpectationsTest {
3130
ModulusAnalysisTest() { this = "ModulusAnalysisTest" }

0 commit comments

Comments
 (0)