Skip to content

Commit f459ddc

Browse files
committed
Languages: Adapt to api changes.
1 parent e53b22d commit f459ddc

File tree

34 files changed

+454
-368
lines changed

34 files changed

+454
-368
lines changed

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,9 +1880,7 @@ module IteratorFlow {
18801880
}
18811881
}
18821882

1883-
private module SsaInput implements SsaImpl::InputSig<Location> {
1884-
import Ssa::InputSigCommon
1885-
1883+
private module SsaInput implements SsaImpl::InputSig<Location, IRCfg::BasicBlock> {
18861884
class SourceVariable = IteratorFlow::SourceVariable;
18871885

18881886
/** A call to function that dereferences an iterator. */
@@ -1960,7 +1958,7 @@ module IteratorFlow {
19601958
* Holds if `(bb, i)` contains a write to an iterator that may have been obtained
19611959
* by calling `begin` (or related functions) on the variable `v`.
19621960
*/
1963-
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
1961+
predicate variableWrite(IRCfg::BasicBlock bb, int i, SourceVariable v, boolean certain) {
19641962
certain = false and
19651963
exists(GetsIteratorCall beginCall, Instruction writeToDeref, IRBlock bbQual, int iQual |
19661964
isIteratorStoreInstruction(beginCall, writeToDeref) and
@@ -1971,12 +1969,12 @@ module IteratorFlow {
19711969
}
19721970

19731971
/** Holds if `(bb, i)` reads the container variable `v`. */
1974-
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
1972+
predicate variableRead(IRCfg::BasicBlock bb, int i, SourceVariable v, boolean certain) {
19751973
Ssa::variableRead(bb, i, v, certain)
19761974
}
19771975
}
19781976

1979-
private module IteratorSsa = SsaImpl::Make<Location, SsaInput>;
1977+
private module IteratorSsa = SsaImpl::Make<Location, IRCfg, SsaInput>;
19801978

19811979
private module DataFlowIntegrationInput implements IteratorSsa::DataFlowIntegrationInputSig {
19821980
private import codeql.util.Void
@@ -1989,7 +1987,7 @@ module IteratorFlow {
19891987
)
19901988
}
19911989

1992-
predicate hasCfgNode(SsaInput::BasicBlock bb, int i) { bb.getInstruction(i) = this }
1990+
predicate hasCfgNode(IRCfg::BasicBlock bb, int i) { bb.getInstruction(i) = this }
19931991
}
19941992

19951993
predicate ssaDefHasSource(IteratorSsa::WriteDefinition def) { none() }
@@ -1999,20 +1997,16 @@ module IteratorFlow {
19991997
class GuardValue = Void;
20001998

20011999
class Guard extends Void {
2002-
predicate hasValueBranchEdge(
2003-
SsaInput::BasicBlock bb1, SsaInput::BasicBlock bb2, GuardValue val
2004-
) {
2000+
predicate hasValueBranchEdge(IRCfg::BasicBlock bb1, IRCfg::BasicBlock bb2, GuardValue val) {
20052001
none()
20062002
}
20072003

2008-
predicate valueControlsBranchEdge(
2009-
SsaInput::BasicBlock bb1, SsaInput::BasicBlock bb2, GuardValue val
2010-
) {
2004+
predicate valueControlsBranchEdge(IRCfg::BasicBlock bb1, IRCfg::BasicBlock bb2, GuardValue val) {
20112005
none()
20122006
}
20132007
}
20142008

2015-
predicate guardDirectlyControlsBlock(Guard guard, SsaInput::BasicBlock bb, GuardValue val) {
2009+
predicate guardDirectlyControlsBlock(Guard guard, IRCfg::BasicBlock bb, GuardValue val) {
20162010
none()
20172011
}
20182012

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,14 @@ private predicate baseSourceVariableIsGlobal(
891891
)
892892
}
893893

894-
private module SsaInput implements Ssa::InputSig<Location> {
895-
import InputSigCommon
894+
private module SsaInput implements Ssa::InputSig<Location, IRCfg::BasicBlock> {
896895
import SourceVariables
897896

898897
/**
899898
* Holds if the `i`'th write in block `bb` writes to the variable `v`.
900899
* `certain` is `true` if the write is guaranteed to overwrite the entire variable.
901900
*/
902-
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
901+
predicate variableWrite(IRCfg::BasicBlock bb, int i, SourceVariable v, boolean certain) {
903902
DataFlowImplCommon::forceCachingInSameStage() and
904903
(
905904
exists(DefImpl def | def.hasIndexInBlock(v, bb, i) |
@@ -917,7 +916,7 @@ private module SsaInput implements Ssa::InputSig<Location> {
917916
* Holds if the `i`'th read in block `bb` reads to the variable `v`.
918917
* `certain` is `true` if the read is guaranteed. For C++, this is always the case.
919918
*/
920-
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
919+
predicate variableRead(IRCfg::BasicBlock bb, int i, SourceVariable v, boolean certain) {
921920
exists(UseImpl use | use.hasIndexInBlock(bb, i, v) |
922921
if use.isCertain() then certain = true else certain = false
923922
)
@@ -965,7 +964,7 @@ class GlobalDef extends Definition {
965964
GlobalLikeVariable getVariable() { result = impl.getVariable() }
966965
}
967966

968-
private module SsaImpl = Ssa::Make<Location, SsaInput>;
967+
private module SsaImpl = Ssa::Make<Location, IRCfg, SsaInput>;
969968

970969
private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationInputSig {
971970
private import codeql.util.Boolean
@@ -978,7 +977,7 @@ private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationI
978977
)
979978
}
980979

981-
predicate hasCfgNode(SsaInput::BasicBlock bb, int i) { bb.getInstruction(i) = this }
980+
predicate hasCfgNode(IRCfg::BasicBlock bb, int i) { bb.getInstruction(i) = this }
982981
}
983982

984983
Expr getARead(SsaImpl::Definition def) {
@@ -1006,9 +1005,7 @@ private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationI
10061005
class Guard instanceof IRGuards::IRGuardCondition {
10071006
string toString() { result = super.toString() }
10081007

1009-
predicate hasValueBranchEdge(
1010-
SsaInput::BasicBlock bb1, SsaInput::BasicBlock bb2, GuardValue branch
1011-
) {
1008+
predicate hasValueBranchEdge(IRCfg::BasicBlock bb1, IRCfg::BasicBlock bb2, GuardValue branch) {
10121009
exists(EdgeKind kind |
10131010
super.getBlock() = bb1 and
10141011
kind = getConditionalEdge(branch) and
@@ -1017,13 +1014,13 @@ private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationI
10171014
}
10181015

10191016
predicate valueControlsBranchEdge(
1020-
SsaInput::BasicBlock bb1, SsaInput::BasicBlock bb2, GuardValue branch
1017+
IRCfg::BasicBlock bb1, IRCfg::BasicBlock bb2, GuardValue branch
10211018
) {
10221019
this.hasValueBranchEdge(bb1, bb2, branch)
10231020
}
10241021
}
10251022

1026-
predicate guardDirectlyControlsBlock(Guard guard, SsaInput::BasicBlock bb, GuardValue branch) {
1023+
predicate guardDirectlyControlsBlock(Guard guard, IRCfg::BasicBlock bb, GuardValue branch) {
10271024
guard.(IRGuards::IRGuardCondition).controls(bb, branch)
10281025
}
10291026

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -768,23 +768,3 @@ private module Cached {
768768
}
769769

770770
import Cached
771-
772-
/**
773-
* Inputs to the shared SSA library's parameterized module that is shared
774-
* between the SSA pruning stage, and the final SSA stage.
775-
*/
776-
module InputSigCommon {
777-
class BasicBlock extends IRBlock {
778-
ControlFlowNode getNode(int i) { result = this.getInstruction(i) }
779-
780-
int length() { result = this.getInstructionCount() }
781-
782-
BasicBlock getASuccessor() { result = super.getASuccessor() }
783-
784-
BasicBlock getImmediateDominator() { result.immediatelyDominates(this) }
785-
786-
predicate inDominanceFrontier(BasicBlock df) { super.dominanceFrontier() = df }
787-
}
788-
789-
class ControlFlowNode = Instruction;
790-
}

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/IRBlock.qll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Instruction
77
private import internal.IRBlockImports as Imports
88
import Imports::EdgeKind
99
private import Cached
10+
private import codeql.controlflow.BasicBlock as BB
1011

1112
/**
1213
* Holds if `block` is a block in `func` and `sortOverride`, `sortKey1`, and `sortKey2` are the
@@ -263,6 +264,45 @@ private predicate isEntryBlock(TIRBlock block) {
263264
block = MkIRBlock(any(EnterFunctionInstruction enter))
264265
}
265266

267+
module IRCfg implements BB::CfgSig<Language::Location> {
268+
class ControlFlowNode = Instruction;
269+
270+
class SuccessorType = EdgeKind;
271+
272+
class BasicBlock extends IRBlock {
273+
ControlFlowNode getNode(int i) { result = this.getInstruction(i) }
274+
275+
ControlFlowNode getLastNode() { result = super.getLastInstruction() }
276+
277+
int length() { result = this.getInstructionCount() }
278+
279+
BasicBlock getASuccessor() { result = super.getASuccessor() }
280+
281+
BasicBlock getASuccessor(SuccessorType t) { result = super.getSuccessor(t) }
282+
283+
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
284+
285+
predicate dominates(BasicBlock bb) { super.dominates(bb) }
286+
287+
BasicBlock getImmediateDominator() { result.immediatelyDominates(this) }
288+
289+
predicate inDominanceFrontier(BasicBlock df) { super.dominanceFrontier() = df }
290+
291+
predicate strictlyPostDominates(BasicBlock bb) { super.strictlyPostDominates(bb) }
292+
293+
predicate postDominates(BasicBlock bb) { super.postDominates(bb) }
294+
}
295+
296+
pragma[nomagic]
297+
predicate dominatingEdge(BasicBlock bb1, BasicBlock bb2) {
298+
bb1.getASuccessor() = bb2 and
299+
bb1 = bb2.getImmediateDominator() and
300+
forall(BasicBlock pred | pred = bb2.getAPredecessor() and pred != bb1 | bb2.dominates(pred))
301+
}
302+
303+
predicate entryBlock(BasicBlock bb) { isEntryBlock(bb) }
304+
}
305+
266306
cached
267307
private module Cached {
268308
cached

csharp/ql/consistency-queries/CfgConsistency.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ predicate bbSuccInconsistency(ControlFlowElement pred, ControlFlowElement succ)
2929
succBB.getFirstNode() = succ.getAControlFlowNode()
3030
) and
3131
not exists(PreBasicBlock predBB, PreBasicBlock succBB |
32-
predBB.getLastElement() = pred and
32+
predBB.getLastNode() = pred and
3333
succBB = predBB.getASuccessor() and
3434
succBB.getFirstElement() = succ
3535
)
@@ -41,7 +41,7 @@ predicate bbIntraSuccInconsistency(ControlFlowElement pred, ControlFlowElement s
4141
succ.getAControlFlowNode() = bb.getNode(i + 1)
4242
) and
4343
not exists(PreBasicBlock bb |
44-
bb.getLastElement() = pred and
44+
bb.getLastNode() = pred and
4545
bb.getASuccessor().getFirstElement() = succ
4646
) and
4747
not exists(PreBasicBlock bb, int i |

csharp/ql/lib/semmle/code/csharp/controlflow/BasicBlocks.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import csharp
66
private import ControlFlow::SuccessorTypes
77
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl as CfgImpl
88
private import CfgImpl::BasicBlocks as BasicBlocksImpl
9+
private import codeql.controlflow.BasicBlock as BB
910

1011
/**
1112
* A basic block, that is, a maximal straight-line sequence of control flow nodes
1213
* without branches or joins.
1314
*/
1415
final class BasicBlock extends BasicBlocksImpl::BasicBlock {
1516
/** Gets an immediate successor of this basic block of a given type, if any. */
16-
BasicBlock getASuccessorByType(ControlFlow::SuccessorType t) { result = this.getASuccessor(t) }
17+
BasicBlock getASuccessor(ControlFlow::SuccessorType t) { result = super.getASuccessor(t) }
18+
19+
/** DEPRECATED: Use `getASuccessor` instead. */
20+
deprecated BasicBlock getASuccessorByType(ControlFlow::SuccessorType t) {
21+
result = this.getASuccessor(t)
22+
}
1723

1824
/** Gets an immediate predecessor of this basic block of a given type, if any. */
1925
BasicBlock getAPredecessorByType(ControlFlow::SuccessorType t) {
@@ -332,3 +338,19 @@ final class ConditionBlock extends BasicBlock, BasicBlocksImpl::ConditionBasicBl
332338
super.edgeDominates(controlled, s)
333339
}
334340
}
341+
342+
private class BasicBlockAlias = BasicBlock;
343+
344+
module Cfg implements BB::CfgSig<Location> {
345+
class ControlFlowNode = ControlFlow::Node;
346+
347+
class SuccessorType = ControlFlow::SuccessorType;
348+
349+
class BasicBlock = BasicBlockAlias;
350+
351+
predicate dominatingEdge(BasicBlock bb1, BasicBlock bb2) {
352+
BasicBlocksImpl::dominatingEdge(bb1, bb2)
353+
}
354+
355+
predicate entryBlock(BasicBlock bb) { bb instanceof EntryBasicBlock }
356+
}

csharp/ql/lib/semmle/code/csharp/controlflow/ControlFlowElement.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class ControlFlowElement extends ExprOrStmtParent, @control_flow_element {
9090
// all other nodes can use regular CFG dominance
9191
this instanceof Impl::SplitAstNode and
9292
cb.getLastNode() = this.getAControlFlowNode() and
93-
succ = cb.getASuccessorByType(s)
93+
succ = cb.getASuccessor(s)
9494
}
9595

9696
pragma[noinline]

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ module Internal {
999999
pragma[nomagic]
10001000
private predicate preControlsDirect(Guard g, PreBasicBlocks::PreBasicBlock bb, AbstractValue v) {
10011001
exists(PreBasicBlocks::ConditionBlock cb, ConditionalSuccessor s | cb.controls(bb, s) |
1002-
v.branch(cb.getLastElement(), s, g)
1002+
v.branch(cb.getLastNode(), s, g)
10031003
)
10041004
}
10051005

@@ -1146,9 +1146,9 @@ module Internal {
11461146
/** Gets the successor block that is reached when guard `g` has abstract value `v`. */
11471147
private PreBasicBlocks::PreBasicBlock getConditionalSuccessor(Guard g, AbstractValue v) {
11481148
exists(PreBasicBlocks::ConditionBlock pred, ConditionalSuccessor s |
1149-
v.branch(pred.getLastElement(), s, g)
1149+
v.branch(pred.getLastNode(), s, g)
11501150
|
1151-
result = pred.getASuccessorByType(s)
1151+
result = pred.getASuccessor(s)
11521152
)
11531153
}
11541154

0 commit comments

Comments
 (0)