Skip to content

Commit 979bcf4

Browse files
authored
Merge pull request github#14868 from hvitved/ssa/locations
SSA: Add locations to ease debugging
2 parents 3dee16c + 1a6886c commit 979bcf4

File tree

15 files changed

+61
-42
lines changed

15 files changed

+61
-42
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ private module SourceVariables {
5959
then result = base.getType()
6060
else result = getTypeImpl(base.getType(), ind - 1)
6161
}
62+
63+
/** Gets the location of this variable. */
64+
Location getLocation() { result = this.getBaseVariable().getLocation() }
6265
}
6366
}
6467

@@ -869,7 +872,7 @@ private predicate sourceVariableIsGlobal(
869872
)
870873
}
871874

872-
private module SsaInput implements SsaImplCommon::InputSig {
875+
private module SsaInput implements SsaImplCommon::InputSig<Location> {
873876
import InputSigCommon
874877
import SourceVariables
875878

@@ -1092,7 +1095,7 @@ class Def extends DefOrUse {
10921095
predicate isCertain() { defOrUse.isCertain() }
10931096
}
10941097

1095-
private module SsaImpl = SsaImplCommon::Make<SsaInput>;
1098+
private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
10961099

10971100
class PhiNode extends SsaImpl::DefinitionExt {
10981101
PhiNode() {

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ abstract private class AbstractBaseSourceVariable extends TBaseSourceVariable {
377377
/** Gets a textual representation of this element. */
378378
abstract string toString();
379379

380+
/** Gets the location of this variable. */
381+
abstract Location getLocation();
382+
380383
/** Gets the type of this base source variable. */
381384
final DataFlowType getType() { this.getLanguageType().hasUnspecifiedType(result, _) }
382385

@@ -395,6 +398,8 @@ class BaseIRVariable extends AbstractBaseSourceVariable, TBaseIRVariable {
395398

396399
override string toString() { result = var.toString() }
397400

401+
override Location getLocation() { result = var.getLocation() }
402+
398403
override CppType getLanguageType() { result = var.getLanguageType() }
399404
}
400405

@@ -407,6 +412,8 @@ class BaseCallVariable extends AbstractBaseSourceVariable, TBaseCallVariable {
407412

408413
override string toString() { result = call.toString() }
409414

415+
override Location getLocation() { result = call.getLocation() }
416+
410417
override CppType getLanguageType() { result = getResultLanguageType(call) }
411418
}
412419

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/ssa0/SsaInternals.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private class FinalParameterUse extends UseImpl, TFinalParameterUse {
229229
override predicate isCertain() { any() }
230230
}
231231

232-
private module SsaInput implements SsaImplCommon::InputSig {
232+
private module SsaInput implements SsaImplCommon::InputSig<Location> {
233233
import InputSigCommon
234234
import SourceVariables
235235

@@ -335,7 +335,7 @@ class Def extends DefOrUse {
335335
predicate isIteratorDef() { defOrUse instanceof IteratorDef }
336336
}
337337

338-
private module SsaImpl = SsaImplCommon::Make<SsaInput>;
338+
private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
339339

340340
class PhiNode extends SsaImpl::DefinitionExt {
341341
PhiNode() {

csharp/ql/lib/semmle/code/cil/internal/SsaImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
private import cil
22
private import codeql.ssa.Ssa as SsaImplCommon
33

4-
private module SsaInput implements SsaImplCommon::InputSig {
4+
private module SsaInput implements SsaImplCommon::InputSig<CIL::Location> {
55
class BasicBlock = CIL::BasicBlock;
66

77
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
@@ -29,7 +29,7 @@ private module SsaInput implements SsaImplCommon::InputSig {
2929
}
3030
}
3131

32-
import SsaImplCommon::Make<SsaInput>
32+
import SsaImplCommon::Make<CIL::Location, SsaInput>
3333

3434
cached
3535
private module Cached {

csharp/ql/lib/semmle/code/csharp/controlflow/internal/PreSsa.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module PreSsa {
3636
scopeFirst(c, bb)
3737
}
3838

39-
module SsaInput implements SsaImplCommon::InputSig {
39+
module SsaInput implements SsaImplCommon::InputSig<Location> {
4040
class BasicBlock = PreBasicBlocks::PreBasicBlock;
4141

4242
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
@@ -137,7 +137,7 @@ module PreSsa {
137137
}
138138
}
139139

140-
private module SsaImpl = SsaImplCommon::Make<SsaInput>;
140+
private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
141141

142142
class Definition extends SsaImpl::Definition {
143143
final AssignableRead getARead() {

csharp/ql/lib/semmle/code/csharp/dataflow/internal/BaseSSA.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module BaseSsa {
2424
)
2525
}
2626

27-
private module SsaInput implements SsaImplCommon::InputSig {
27+
private module SsaInput implements SsaImplCommon::InputSig<Location> {
2828
class BasicBlock = ControlFlow::BasicBlock;
2929

3030
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
@@ -60,7 +60,7 @@ module BaseSsa {
6060
}
6161
}
6262

63-
private module SsaImpl = SsaImplCommon::Make<SsaInput>;
63+
private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
6464

6565
class Definition extends SsaImpl::Definition {
6666
final AssignableRead getARead() {

csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import csharp
66
private import codeql.ssa.Ssa as SsaImplCommon
77
private import AssignableDefinitions
88

9-
private module SsaInput implements SsaImplCommon::InputSig {
9+
private module SsaInput implements SsaImplCommon::InputSig<Location> {
1010
class BasicBlock = ControlFlow::BasicBlock;
1111

1212
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
@@ -49,7 +49,7 @@ private module SsaInput implements SsaImplCommon::InputSig {
4949
}
5050
}
5151

52-
private import SsaImplCommon::Make<SsaInput> as Impl
52+
private import SsaImplCommon::Make<Location, SsaInput> as Impl
5353

5454
class Definition = Impl::Definition;
5555

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ private predicate closureFlowStep(Expr e1, Expr e2) {
6161
)
6262
}
6363

64-
private module CaptureInput implements VariableCapture::InputSig {
64+
private module CaptureInput implements VariableCapture::InputSig<Location> {
6565
private import java as J
6666

67-
class Location = J::Location;
68-
6967
class BasicBlock instanceof J::BasicBlock {
7068
string toString() { result = super.toString() }
7169

@@ -146,7 +144,7 @@ class CapturedVariable = CaptureInput::CapturedVariable;
146144

147145
class CapturedParameter = CaptureInput::CapturedParameter;
148146

149-
module CaptureFlow = VariableCapture::Flow<CaptureInput>;
147+
module CaptureFlow = VariableCapture::Flow<Location, CaptureInput>;
150148

151149
private CaptureFlow::ClosureNode asClosureNode(Node n) {
152150
result = n.(CaptureNode).getSynthesizedCaptureNode()

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,12 @@ module VariableCapture {
278278
)
279279
}
280280

281-
private module CaptureInput implements Shared::InputSig {
281+
private module CaptureInput implements Shared::InputSig<Location> {
282282
private import ruby as R
283283
private import codeql.ruby.controlflow.ControlFlowGraph
284284
private import codeql.ruby.controlflow.BasicBlocks as BasicBlocks
285285
private import TaintTrackingPrivate as TaintTrackingPrivate
286286

287-
class Location = R::Location;
288-
289287
class BasicBlock extends BasicBlocks::BasicBlock {
290288
Callable getEnclosingCallable() { result = this.getScope() }
291289
}
@@ -366,7 +364,7 @@ module VariableCapture {
366364

367365
class ClosureExpr = CaptureInput::ClosureExpr;
368366

369-
module Flow = Shared::Flow<CaptureInput>;
367+
module Flow = Shared::Flow<Location, CaptureInput>;
370368

371369
private Flow::ClosureNode asClosureNode(Node n) {
372370
result = n.(CaptureNode).getSynthesizedCaptureNode()

ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private import codeql.ruby.dataflow.SSA
66
private import codeql.ruby.ast.Variable
77
private import Cfg::CfgNodes::ExprNodes
88

9-
private module SsaInput implements SsaImplCommon::InputSig {
9+
private module SsaInput implements SsaImplCommon::InputSig<Location> {
1010
private import codeql.ruby.controlflow.BasicBlocks as BasicBlocks
1111

1212
class BasicBlock = BasicBlocks::BasicBlock;
@@ -62,7 +62,7 @@ private module SsaInput implements SsaImplCommon::InputSig {
6262
}
6363
}
6464

65-
private import SsaImplCommon::Make<SsaInput> as Impl
65+
private import SsaImplCommon::Make<Location, SsaInput> as Impl
6666

6767
class Definition = Impl::Definition;
6868

0 commit comments

Comments
 (0)