Skip to content

Commit b263132

Browse files
authored
Merge pull request #17998 from yoff/shared/locations-in-range-analysis
2 parents 0957113 + 21e7a0e commit b263132

File tree

11 files changed

+36
-27
lines changed

11 files changed

+36
-27
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
private import Semantic
6+
private import SemanticLocation
67
private import SemanticExprSpecific::SemanticExprConfig as Specific
78
private import SemanticType
89

@@ -15,7 +16,7 @@ private import SemanticType
1516
class SemExpr instanceof Specific::Expr {
1617
final string toString() { result = super.toString() }
1718

18-
final Specific::Location getLocation() { result = super.getLocation() }
19+
SemLocation getLocation() { result = super.getLocation() }
1920

2021
Opcode getOpcode() { result instanceof Opcode::Unknown }
2122

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ private import RangeAnalysisImpl
22
private import codeql.rangeanalysis.RangeAnalysis
33
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticExpr
44
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticType
5+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticLocation
56

67
module FloatDelta implements DeltaSig {
78
class Delta = float;
@@ -22,7 +23,7 @@ module FloatDelta implements DeltaSig {
2223
Delta fromFloat(float f) { result = f }
2324
}
2425

25-
module FloatOverflow implements OverflowSig<Sem, FloatDelta> {
26+
module FloatOverflow implements OverflowSig<SemLocation, Sem, FloatDelta> {
2627
predicate semExprDoesNotOverflow(boolean positively, SemExpr expr) {
2728
exists(float lb, float ub, float delta |
2829
typeBounds(expr.getSemType(), lb, ub) and

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
*/
44

55
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
6+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticLocation
67
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
78
private import RangeAnalysisImpl
89
private import codeql.rangeanalysis.RangeAnalysis
910

10-
module CppLangImplConstant implements LangSig<Sem, FloatDelta> {
11+
module CppLangImplConstant implements LangSig<SemLocation, Sem, FloatDelta> {
1112
/**
1213
* Ignore the bound on this expression.
1314
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private import SemanticType
1212
private import codeql.rangeanalysis.RangeAnalysis
1313
private import ConstantAnalysis as ConstantAnalysis
1414

15-
module Sem implements Semantic {
15+
module Sem implements Semantic<SemLocation> {
1616
class Expr = SemExpr;
1717

1818
class ConstantIntegerExpr = ConstantAnalysis::SemConstantIntegerExpr;
@@ -104,7 +104,7 @@ module Sem implements Semantic {
104104
}
105105
}
106106

107-
module SignAnalysis implements SignAnalysisSig<Sem> {
107+
module SignAnalysis implements SignAnalysisSig<SemLocation, Sem> {
108108
private import SignAnalysisCommon as SA
109109
import SA::SignAnalysis<FloatDelta>
110110
}
@@ -165,7 +165,7 @@ module AllBounds implements BoundSig<SemLocation, Sem, FloatDelta> {
165165
}
166166
}
167167

168-
private module ModulusAnalysisInstantiated implements ModulusAnalysisSig<Sem> {
168+
private module ModulusAnalysisInstantiated implements ModulusAnalysisSig<SemLocation, Sem> {
169169
class ModBound = AllBounds::SemBound;
170170

171171
private import codeql.rangeanalysis.ModulusAnalysis as MA

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
*/
44

55
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
6+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticLocation
67
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
78
private import RangeAnalysisImpl
89
private import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
910
private import codeql.rangeanalysis.RangeAnalysis
1011

11-
module CppLangImplRelative implements LangSig<Sem, FloatDelta> {
12+
module CppLangImplRelative implements LangSig<SemLocation, Sem, FloatDelta> {
1213
/**
1314
* Ignore the bound on this expression.
1415
*

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ private import codeql.rangeanalysis.RangeAnalysis
1010
private import RangeAnalysisImpl
1111
private import SignAnalysisSpecific as Specific
1212
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
13+
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticLocation
1314
private import ConstantAnalysis
1415
private import Sign
1516

1617
module SignAnalysis<DeltaSig D> {
17-
private import codeql.rangeanalysis.internal.RangeUtils::MakeUtils<Sem, D>
18+
private import codeql.rangeanalysis.internal.RangeUtils::MakeUtils<SemLocation, Sem, D>
1819

1920
/**
2021
* An SSA definition for which the analysis can compute the sign.

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private import semmle.code.java.Maps
7575
import Bound
7676
private import codeql.rangeanalysis.RangeAnalysis
7777

78-
module Sem implements Semantic {
78+
module Sem implements Semantic<Location> {
7979
private import java as J
8080
private import SSA as SSA
8181
private import RangeUtils as RU
@@ -266,7 +266,7 @@ module Sem implements Semantic {
266266
predicate conversionCannotOverflow = safeCast/2;
267267
}
268268

269-
module SignInp implements SignAnalysisSig<Sem> {
269+
module SignInp implements SignAnalysisSig<Location, Sem> {
270270
private import SignAnalysis
271271
private import internal.rangeanalysis.Sign
272272

@@ -283,7 +283,7 @@ module SignInp implements SignAnalysisSig<Sem> {
283283
predicate semMayBeNegative(Sem::Expr e) { exprSign(e) = TNeg() }
284284
}
285285

286-
module Modulus implements ModulusAnalysisSig<Sem> {
286+
module Modulus implements ModulusAnalysisSig<Location, Sem> {
287287
class ModBound = Bound;
288288

289289
private import codeql.rangeanalysis.ModulusAnalysis as Mod
@@ -309,7 +309,7 @@ module IntDelta implements DeltaSig {
309309
Delta fromFloat(float f) { result = f }
310310
}
311311

312-
module JavaLangImpl implements LangSig<Sem, IntDelta> {
312+
module JavaLangImpl implements LangSig<Location, Sem, IntDelta> {
313313
/**
314314
* Holds if `e >= bound` (if `upper = false`) or `e <= bound` (if `upper = true`).
315315
*/
@@ -381,7 +381,7 @@ module Bounds implements BoundSig<Location, Sem, IntDelta> {
381381
}
382382
}
383383

384-
module Overflow implements OverflowSig<Sem, IntDelta> {
384+
module Overflow implements OverflowSig<Location, Sem, IntDelta> {
385385
predicate semExprDoesNotOverflow(boolean positively, Sem::Expr expr) {
386386
positively = [true, false] and exists(expr)
387387
}

java/ql/lib/semmle/code/java/dataflow/RangeUtils.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private import semmle.code.java.Constants
99
private import semmle.code.java.dataflow.RangeAnalysis
1010
private import codeql.rangeanalysis.internal.RangeUtils
1111

12-
private module U = MakeUtils<Sem, IntDelta>;
12+
private module U = MakeUtils<Location, Sem, IntDelta>;
1313

1414
private predicate backEdge = U::backEdge/3;
1515

shared/rangeanalysis/codeql/rangeanalysis/ModulusAnalysis.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ private import codeql.util.Location
1414
private import RangeAnalysis
1515

1616
module ModulusAnalysis<
17-
LocationSig Location, Semantic Sem, DeltaSig D, BoundSig<Location, Sem, D> Bounds>
17+
LocationSig Location, Semantic<Location> Sem, DeltaSig D, BoundSig<Location, Sem, D> Bounds>
1818
{
19-
private import internal.RangeUtils::MakeUtils<Sem, D>
19+
private import internal.RangeUtils::MakeUtils<Location, Sem, D>
2020

2121
bindingset[pos, v]
2222
pragma[inline_late]

shared/rangeanalysis/codeql/rangeanalysis/RangeAnalysis.qll

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@
6565

6666
private import codeql.util.Location
6767

68-
signature module Semantic {
68+
signature module Semantic<LocationSig Location> {
6969
class Expr {
7070
string toString();
7171

7272
BasicBlock getBasicBlock();
73+
74+
Location getLocation();
7375
}
7476

7577
class ConstantIntegerExpr extends Expr {
@@ -294,7 +296,7 @@ signature module Semantic {
294296
predicate conversionCannotOverflow(Type fromType, Type toType);
295297
}
296298

297-
signature module SignAnalysisSig<Semantic Sem> {
299+
signature module SignAnalysisSig<LocationSig Location, Semantic<Location> Sem> {
298300
/** Holds if `e` can be positive and cannot be negative. */
299301
predicate semPositive(Sem::Expr e);
300302

@@ -320,7 +322,7 @@ signature module SignAnalysisSig<Semantic Sem> {
320322
predicate semMayBeNegative(Sem::Expr e);
321323
}
322324

323-
signature module ModulusAnalysisSig<Semantic Sem> {
325+
signature module ModulusAnalysisSig<LocationSig Location, Semantic<Location> Sem> {
324326
class ModBound;
325327

326328
predicate exprModulus(Sem::Expr e, ModBound b, int val, int mod);
@@ -346,7 +348,7 @@ signature module DeltaSig {
346348
Delta fromFloat(float f);
347349
}
348350

349-
signature module LangSig<Semantic Sem, DeltaSig D> {
351+
signature module LangSig<LocationSig Location, Semantic<Location> Sem, DeltaSig D> {
350352
/**
351353
* Holds if `e >= bound` (if `upper = false`) or `e <= bound` (if `upper = true`).
352354
*/
@@ -372,7 +374,7 @@ signature module LangSig<Semantic Sem, DeltaSig D> {
372374
default predicate includeRelativeBounds() { any() }
373375
}
374376

375-
signature module BoundSig<LocationSig Location, Semantic Sem, DeltaSig D> {
377+
signature module BoundSig<LocationSig Location, Semantic<Location> Sem, DeltaSig D> {
376378
/**
377379
* A bound that the range analysis can infer for a variable. This includes
378380
* constant bounds represented by the abstract value zero, SSA bounds for when
@@ -409,22 +411,23 @@ signature module BoundSig<LocationSig Location, Semantic Sem, DeltaSig D> {
409411
}
410412
}
411413

412-
signature module OverflowSig<Semantic Sem, DeltaSig D> {
414+
signature module OverflowSig<LocationSig Location, Semantic<Location> Sem, DeltaSig D> {
413415
predicate semExprDoesNotOverflow(boolean positively, Sem::Expr expr);
414416
}
415417

416418
module RangeStage<
417-
LocationSig Location, Semantic Sem, DeltaSig D, BoundSig<Location, Sem, D> Bounds,
418-
OverflowSig<Sem, D> OverflowParam, LangSig<Sem, D> LangParam, SignAnalysisSig<Sem> SignAnalysis,
419-
ModulusAnalysisSig<Sem> ModulusAnalysisParam>
419+
LocationSig Location, Semantic<Location> Sem, DeltaSig D, BoundSig<Location, Sem, D> Bounds,
420+
OverflowSig<Location, Sem, D> OverflowParam, LangSig<Location, Sem, D> LangParam,
421+
SignAnalysisSig<Location, Sem> SignAnalysis,
422+
ModulusAnalysisSig<Location, Sem> ModulusAnalysisParam>
420423
{
421424
private import Bounds
422425
private import LangParam
423426
private import D
424427
private import OverflowParam
425428
private import SignAnalysis
426429
private import ModulusAnalysisParam
427-
private import internal.RangeUtils::MakeUtils<Sem, D>
430+
private import internal.RangeUtils::MakeUtils<Location, Sem, D>
428431

429432
/**
430433
* An expression that does conversion, boxing, or unboxing

0 commit comments

Comments
 (0)