Skip to content

Commit e04847a

Browse files
committed
wip
1 parent 1557b86 commit e04847a

File tree

22 files changed

+823
-348
lines changed

22 files changed

+823
-348
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,19 @@ 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+
ControlFlowNode getNode(int i) { result = this.getInstruction(i) }
762+
763+
int length() { result = this.getInstructionCount() }
764+
}
765+
766+
class ControlFlowNode = Instruction;
761767

762768
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
763769

764770
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
765771

766-
class ExitBasicBlock extends IRBlock {
772+
class ExitBasicBlock extends BasicBlock {
767773
ExitBasicBlock() { this.getLastInstruction() instanceof ExitFunctionInstruction }
768774
}
769775
}

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: 4 additions & 1 deletion
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> {
56
class BasicBlock = CIL::BasicBlock;
67

8+
class ControlFlowNode = CIL::ControlFlowNode;
9+
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ module PreSsa {
8080
}
8181

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

8589
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
8690

@@ -192,7 +196,7 @@ module PreSsa {
192196
SsaImpl::ssaDefReachesEndOfBlock(bb, this, _)
193197
}
194198

195-
Location getLocation() {
199+
override Location getLocation() {
196200
result = this.getDefinition().getLocation()
197201
or
198202
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
@@ -444,7 +444,7 @@ module Ssa {
444444
}
445445

446446
/** Gets the location of this SSA definition. */
447-
Location getLocation() { none() }
447+
override Location getLocation() { none() }
448448
}
449449

450450
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ module BaseSsa {
4747

4848
class BasicBlock = ControlFlow::BasicBlock;
4949

50+
class ControlFlowNode = ControlFlow::Node;
51+
5052
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
5153
result = bb.getImmediateDominator()
5254
}
5355

5456
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
5557

56-
class ExitBasicBlock = ControlFlow::BasicBlocks::ExitBlock;
58+
class ExitBasicBlock extends BasicBlock, ControlFlow::BasicBlocks::ExitBlock { }
5759

5860
class SourceVariable = PreSsa::SimpleLocalScopeVariable;
5961

@@ -111,7 +113,7 @@ module BaseSsa {
111113
not result instanceof PhiNode
112114
}
113115

114-
Location getLocation() {
116+
override Location getLocation() {
115117
result = this.getDefinition().getLocation()
116118
or
117119
exists(Callable c, SsaInput::BasicBlock bb, SsaInput::SourceVariable v |

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,16 @@ module VariableCapture {
264264

265265
private module CaptureInput implements Shared::InputSig<Location> {
266266
private import csharp as Cs
267-
private import semmle.code.csharp.controlflow.ControlFlowGraph
267+
private import semmle.code.csharp.controlflow.ControlFlowGraph as Cfg
268268
private import semmle.code.csharp.controlflow.BasicBlocks as BasicBlocks
269269
private import TaintTrackingPrivate as TaintTrackingPrivate
270270

271271
class BasicBlock extends BasicBlocks::BasicBlock {
272272
Callable getEnclosingCallable() { result = super.getCallable() }
273273
}
274274

275+
class ControlFlowNode = Cfg::ControlFlow::Node;
276+
275277
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
276278
result = bb.getImmediateDominator()
277279
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ private import semmle.code.csharp.controlflow.internal.PreSsa
1010
private module SsaInput implements SsaImplCommon::InputSig<Location> {
1111
class BasicBlock = ControlFlow::BasicBlock;
1212

13+
class ControlFlowNode = ControlFlow::Node;
14+
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
@@ -1094,7 +1096,7 @@ class DefinitionExt extends Impl::DefinitionExt {
10941096
override string toString() { result = this.(Ssa::Definition).toString() }
10951097

10961098
/** Gets the location of this definition. */
1097-
Location getLocation() { result = this.(Ssa::Definition).getLocation() }
1099+
override Location getLocation() { result = this.(Ssa::Definition).getLocation() }
10981100

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

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

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

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

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

84+
class ControlFlowNode = J::ControlFlowNode;
85+
8086
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { bbIDominates(result, bb) }
8187

8288
BasicBlock getABasicBlockSuccessor(BasicBlock bb) {

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,8 @@ private module CaptureInput implements Shared::InputSig<Location> {
2424
}
2525

2626
class BasicBlock extends PY::BasicBlock {
27+
int length() { result = count(int i | exists(this.getNode(i))) }
28+
2729
Callable getEnclosingCallable() { result = this.getScope() }
2830

2931
// Note `PY:BasicBlock` does not have a `getLocation`.
@@ -34,6 +36,8 @@ private module CaptureInput implements Shared::InputSig<Location> {
3436
Location getLocation() { result = super.getNode(0).getLocation() }
3537
}
3638

39+
class ControlFlowNode = PY::ControlFlowNode;
40+
3741
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
3842

3943
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }

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
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,7 @@ private module TrackSingletonMethodOnInstanceInput implements CallGraphConstruct
10931093
singletonMethodOnInstance(_, _, nodeFromPreExpr.getExpr())
10941094
)
10951095
|
1096-
nodeFromPreExpr =
1097-
LocalFlow::getParameterDefNode(p.getParameter()).getDefinitionExt().getARead()
1096+
nodeFromPreExpr = getParameterDef(p.getParameter()).getARead()
10981097
or
10991098
nodeFromPreExpr = p.(SelfParameterNodeImpl).getSelfDefinition().getARead()
11001099
)

0 commit comments

Comments
 (0)