Skip to content

Commit ef1fba1

Browse files
committed
wip
1 parent 7fdc09c commit ef1fba1

File tree

20 files changed

+694
-205
lines changed

20 files changed

+694
-205
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ module IteratorFlow {
18091809
* Holds if `(bb, i)` contains a write to an iterator that may have been obtained
18101810
* by calling `begin` (or related functions) on the variable `v`.
18111811
*/
1812-
predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) {
1812+
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
18131813
certain = false and
18141814
exists(GetsIteratorCall beginCall, Instruction writeToDeref, IRBlock bbQual, int iQual |
18151815
isIteratorStoreInstruction(beginCall, writeToDeref) and
@@ -1820,7 +1820,7 @@ module IteratorFlow {
18201820
}
18211821

18221822
/** Holds if `(bb, i)` reads the container variable `v`. */
1823-
predicate variableRead(IRBlock bb, int i, SourceVariable v, boolean certain) {
1823+
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
18241824
Ssa::variableRead(bb, i, v, certain)
18251825
}
18261826
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
981981
* Holds if the `i`'th write in block `bb` writes to the variable `v`.
982982
* `certain` is `true` if the write is guaranteed to overwrite the entire variable.
983983
*/
984-
predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) {
984+
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
985985
DataFlowImplCommon::forceCachingInSameStage() and
986986
(
987987
exists(DefImpl def | def.hasIndexInBlock(bb, i, v) |
@@ -999,7 +999,7 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
999999
* Holds if the `i`'th read in block `bb` reads to the variable `v`.
10001000
* `certain` is `true` if the read is guaranteed. For C++, this is always the case.
10011001
*/
1002-
predicate variableRead(IRBlock bb, int i, SourceVariable v, boolean certain) {
1002+
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
10031003
exists(UseImpl use | use.hasIndexInBlock(bb, i, v) |
10041004
if use.isCertain() then certain = true else certain = false
10051005
)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,17 @@ import Cached
757757
* between the SSA pruning stage, and the final SSA stage.
758758
*/
759759
module InputSigCommon {
760-
class BasicBlock = IRBlock;
760+
class BasicBlock extends IRBlock {
761+
Location getLocation(int i) { result = this.getInstruction(i).getLocation() }
762+
763+
int length() { result = this.getInstructionCount() }
764+
}
761765

762766
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
763767

764768
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
765769

766-
class ExitBasicBlock extends IRBlock {
770+
class ExitBasicBlock extends BasicBlock {
767771
ExitBasicBlock() { this.getLastInstruction() instanceof ExitFunctionInstruction }
768772
}
769773
}

csharp/ql/lib/semmle/code/cil/Ssa.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ deprecated module Ssa {
3535
}
3636

3737
/** Gets the location of this SSA definition. */
38-
Location getLocation() { result = this.getVariableUpdate().getLocation() }
38+
override Location getLocation() { result = this.getVariableUpdate().getLocation() }
3939
}
4040

4141
/** A phi node. */

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
private import cil
2+
private import CIL
23
private import codeql.ssa.Ssa as SsaImplCommon
34

45
deprecated private module SsaInput implements SsaImplCommon::InputSig<CIL::Location> {
5-
class BasicBlock = CIL::BasicBlock;
6+
class BasicBlock extends CIL::BasicBlock {
7+
Location getLocation(int i) { result = this.getNode(i).getLocation() }
8+
}
69

710
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
811

912
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
1013

11-
class ExitBasicBlock = CIL::ExitBasicBlock;
14+
class ExitBasicBlock extends BasicBlock, CIL::ExitBasicBlock { }
1215

1316
class SourceVariable = CIL::StackVariable;
1417

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ module PreSsa {
8080
}
8181

8282
module SsaInput implements SsaImplCommon::InputSig<Location> {
83-
class BasicBlock = PreBasicBlocks::PreBasicBlock;
83+
class BasicBlock extends PreBasicBlocks::PreBasicBlock {
84+
Location getLocation(int i) { result = this.getElement(i).getLocation() }
85+
}
8486

8587
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
8688

@@ -192,7 +194,7 @@ module PreSsa {
192194
SsaImpl::ssaDefReachesEndOfBlock(bb, this, _)
193195
}
194196

195-
Location getLocation() {
197+
override Location getLocation() {
196198
result = this.getDefinition().getLocation()
197199
or
198200
exists(Callable c, SsaInput::BasicBlock bb, SsaInput::SourceVariable v |

csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ module Ssa {
427427
}
428428

429429
/** Gets the location of this SSA definition. */
430-
Location getLocation() { none() }
430+
override Location getLocation() { none() }
431431
}
432432

433433
/**

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ module BaseSsa {
3434
private module SsaInput implements SsaImplCommon::InputSig<Location> {
3535
private import semmle.code.csharp.controlflow.internal.PreSsa
3636

37-
class BasicBlock = ControlFlow::BasicBlock;
37+
class BasicBlock extends ControlFlow::BasicBlock {
38+
Location getLocation(int i) { result = this.getNode(i).getLocation() }
39+
}
3840

3941
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
4042
result = bb.getImmediateDominator()
4143
}
4244

4345
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
4446

45-
class ExitBasicBlock = ControlFlow::BasicBlocks::ExitBlock;
47+
class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }
4648

4749
class SourceVariable = PreSsa::SimpleLocalScopeVariable;
4850

@@ -93,7 +95,7 @@ module BaseSsa {
9395
not result instanceof PhiNode
9496
}
9597

96-
Location getLocation() {
98+
override Location getLocation() {
9799
result = this.getDefinition().getLocation()
98100
or
99101
exists(Callable c, SsaInput::BasicBlock bb, SsaInput::SourceVariable v |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ module VariableCapture {
268268
private import TaintTrackingPrivate as TaintTrackingPrivate
269269

270270
class BasicBlock extends BasicBlocks::BasicBlock {
271+
Location getLocation(int i) { result = this.getNode(i).getLocation() }
272+
271273
Callable getEnclosingCallable() { result = super.getCallable() }
272274
}
273275

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ private import AssignableDefinitions
88
private import semmle.code.csharp.controlflow.internal.PreSsa
99

1010
private module SsaInput implements SsaImplCommon::InputSig<Location> {
11-
class BasicBlock = ControlFlow::BasicBlock;
11+
class BasicBlock extends ControlFlow::BasicBlock {
12+
Location getLocation(int i) { result = this.getNode(i).getLocation() }
13+
}
1214

1315
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
1416

1517
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
1618

17-
class ExitBasicBlock = ControlFlow::BasicBlocks::ExitBlock;
19+
class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }
1820

1921
class SourceVariable = Ssa::SourceVariable;
2022

@@ -24,7 +26,7 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
2426
*
2527
* This includes implicit writes via calls.
2628
*/
27-
predicate variableWrite(ControlFlow::BasicBlock bb, int i, Ssa::SourceVariable v, boolean certain) {
29+
predicate variableWrite(BasicBlock bb, int i, Ssa::SourceVariable v, boolean certain) {
2830
variableWriteDirect(bb, i, v, certain)
2931
or
3032
variableWriteQualifier(bb, i, v, certain)
@@ -38,7 +40,7 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
3840
*
3941
* This includes implicit reads via calls.
4042
*/
41-
predicate variableRead(ControlFlow::BasicBlock bb, int i, Ssa::SourceVariable v, boolean certain) {
43+
predicate variableRead(BasicBlock bb, int i, Ssa::SourceVariable v, boolean certain) {
4244
variableReadActual(bb, i, v) and
4345
certain = true
4446
or
@@ -1089,7 +1091,7 @@ class DefinitionExt extends Impl::DefinitionExt {
10891091
override string toString() { result = this.(Ssa::Definition).toString() }
10901092

10911093
/** Gets the location of this definition. */
1092-
Location getLocation() { result = this.(Ssa::Definition).getLocation() }
1094+
override Location getLocation() { result = this.(Ssa::Definition).getLocation() }
10931095

10941096
/** Gets the enclosing callable of this definition. */
10951097
Callable getEnclosingCallable() { result = this.(Ssa::Definition).getEnclosingCallable() }

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ private module CaptureInput implements VariableCapture::InputSig<Location> {
7272
class BasicBlock instanceof J::BasicBlock {
7373
string toString() { result = super.toString() }
7474

75+
Location getLocation(int i) { result = super.getNode(i).getLocation() }
76+
77+
int length() { result = super.length() }
78+
7579
Callable getEnclosingCallable() { result = super.getEnclosingCallable() }
7680

7781
Location getLocation() { result = super.getLocation() }

python/ql/lib/semmle/python/dataflow/new/internal/VariableCapture.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ private module CaptureInput implements Shared::InputSig<Location> {
2424
}
2525

2626
class BasicBlock extends PY::BasicBlock {
27+
Location getLocation(int i) { result = this.getNode(i).getLocation() }
28+
29+
int length() { result = count(int i | exists(this.getNode(i))) }
30+
2731
Callable getEnclosingCallable() { result = this.getScope() }
2832

2933
// Note `PY:BasicBlock` does not have a `getLocation`.

ruby/ql/lib/codeql/ruby/dataflow/SSA.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ module Ssa {
176176

177177
override string toString() { result = this.getControlFlowNode().toString() }
178178

179-
/** Gets the location of this SSA definition. */
180-
Location getLocation() { result = this.getControlFlowNode().getLocation() }
181-
182179
/** Gets the scope of this SSA definition. */
183180
CfgScope getScope() { result = this.getBasicBlock().getScope() }
184181
}

0 commit comments

Comments
 (0)