Skip to content

Commit bb3abc8

Browse files
committed
SSA: Update input to use member predicates.
1 parent 119837b commit bb3abc8

File tree

24 files changed

+142
-201
lines changed

24 files changed

+142
-201
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,13 @@ module InputSigCommon {
778778
ControlFlowNode getNode(int i) { result = this.getInstruction(i) }
779779

780780
int length() { result = this.getInstructionCount() }
781-
}
782781

783-
class ControlFlowNode = Instruction;
782+
BasicBlock getASuccessor() { result = super.getASuccessor() }
784783

785-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
784+
BasicBlock getImmediateDominator() { result.immediatelyDominates(this) }
786785

787-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
786+
predicate inDominanceFrontier(BasicBlock df) { super.dominanceFrontier() = df }
787+
}
788+
789+
class ControlFlowNode = Instruction;
788790
}

csharp/ql/consistency-queries/CfgConsistency.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ predicate bbIntraSuccInconsistency(ControlFlowElement pred, ControlFlowElement s
4545
bb.getASuccessor().getFirstElement() = succ
4646
) and
4747
not exists(PreBasicBlock bb, int i |
48-
bb.getElement(i) = pred and
49-
bb.getElement(i + 1) = succ
48+
bb.getNode(i) = pred and
49+
bb.getNode(i + 1) = succ
5050
)
5151
}
5252

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ final class BasicBlock extends BasicBlocksImpl::BasicBlock {
5858
result.getFirstNode() = this.getLastNode().getAFalseSuccessor()
5959
}
6060

61+
BasicBlock getASuccessor() { result = super.getASuccessor() }
62+
6163
/** Gets the control flow node at a specific (zero-indexed) position in this basic block. */
6264
ControlFlow::Node getNode(int pos) { result = super.getNode(pos) }
6365

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,20 @@ class PreBasicBlock extends ControlFlowElement {
6363

6464
PreBasicBlock getAPredecessor() { result.getASuccessor() = this }
6565

66-
ControlFlowElement getElement(int pos) { bbIndex(this, result, pos) }
66+
ControlFlowElement getNode(int pos) { bbIndex(this, result, pos) }
6767

68-
ControlFlowElement getAnElement() { result = this.getElement(_) }
68+
deprecated ControlFlowElement getElement(int pos) { result = this.getNode(pos) }
69+
70+
ControlFlowElement getAnElement() { result = this.getNode(_) }
6971

7072
ControlFlowElement getFirstElement() { result = this }
7173

72-
ControlFlowElement getLastElement() { result = this.getElement(this.length() - 1) }
74+
ControlFlowElement getLastElement() { result = this.getNode(this.length() - 1) }
7375

7476
int length() { result = strictcount(this.getAnElement()) }
7577

78+
PreBasicBlock getImmediateDominator() { bbIDominates(result, this) }
79+
7680
predicate immediatelyDominates(PreBasicBlock bb) { bbIDominates(this, bb) }
7781

7882
pragma[inline]
@@ -84,6 +88,15 @@ class PreBasicBlock extends ControlFlowElement {
8488
or
8589
this.strictlyDominates(bb)
8690
}
91+
92+
predicate inDominanceFrontier(PreBasicBlock df) {
93+
this = df.getAPredecessor() and not bbIDominates(this, df)
94+
or
95+
exists(PreBasicBlock prev | prev.inDominanceFrontier(df) |
96+
bbIDominates(this, prev) and
97+
not bbIDominates(this, df)
98+
)
99+
}
87100
}
88101

89102
private Completion getConditionalCompletion(ConditionalCompletion cc) {

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module PreSsa {
1414
private predicate definitionAt(
1515
AssignableDefinition def, SsaInput::BasicBlock bb, int i, SsaInput::SourceVariable v
1616
) {
17-
bb.getElement(i) = def.getExpr() and
17+
bb.getNode(i) = def.getExpr() and
1818
v = def.getTarget() and
1919
// In cases like `(x, x) = (0, 1)`, we discard the first (dead) definition of `x`
2020
not exists(TupleAssignmentDefinition first, TupleAssignmentDefinition second | first = def |
@@ -80,16 +80,10 @@ module PreSsa {
8080
}
8181

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

8785
class ControlFlowNode = ControlFlowElement;
8886

89-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
90-
91-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
92-
9387
private class ExitBasicBlock extends BasicBlock {
9488
ExitBasicBlock() { scopeLast(_, this.getLastElement(), _) }
9589
}
@@ -142,7 +136,7 @@ module PreSsa {
142136

143137
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
144138
exists(AssignableRead read |
145-
read = bb.getElement(i) and
139+
read = bb.getNode(i) and
146140
read.getTarget() = v and
147141
certain = true
148142
)
@@ -163,7 +157,7 @@ module PreSsa {
163157
final AssignableRead getARead() {
164158
exists(SsaInput::BasicBlock bb, int i |
165159
SsaImpl::ssaDefReachesRead(_, this, bb, i) and
166-
result = bb.getElement(i)
160+
result = bb.getNode(i)
167161
)
168162
}
169163

@@ -177,7 +171,7 @@ module PreSsa {
177171
final AssignableRead getAFirstRead() {
178172
exists(SsaInput::BasicBlock bb, int i |
179173
SsaImpl::firstUse(this, bb, i, true) and
180-
result = bb.getElement(i)
174+
result = bb.getNode(i)
181175
)
182176
}
183177

@@ -214,9 +208,9 @@ module PreSsa {
214208

215209
predicate adjacentReadPairSameVar(AssignableRead read1, AssignableRead read2) {
216210
exists(SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2 |
217-
read1 = bb1.getElement(i1) and
211+
read1 = bb1.getNode(i1) and
218212
SsaImpl::adjacentUseUse(bb1, i1, bb2, i2, _, true) and
219-
read2 = bb2.getElement(i2)
213+
read2 = bb2.getNode(i2)
220214
)
221215
}
222216
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ module BaseSsa {
4949

5050
class ControlFlowNode = ControlFlow::Node;
5151

52-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
53-
result = bb.getImmediateDominator()
54-
}
55-
56-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
57-
5852
class SourceVariable = PreSsa::SimpleLocalScopeVariable;
5953

6054
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ module VariableCapture {
283283

284284
class BasicBlock extends BasicBlocks::BasicBlock {
285285
Callable getEnclosingCallable() { result = super.getCallable() }
286-
}
287286

288-
class ControlFlowNode = Cfg::ControlFlow::Node;
287+
BasicBlock getASuccessor() { result = super.getASuccessor() }
289288

290-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) {
291-
result = bb.getImmediateDominator()
289+
BasicBlock getImmediateDominator() { result = super.getImmediateDominator() }
290+
291+
predicate inDominanceFrontier(BasicBlock df) { super.inDominanceFrontier(df) }
292292
}
293293

294-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
294+
class ControlFlowNode = Cfg::ControlFlow::Node;
295295

296296
private predicate thisAccess(ControlFlow::Node cfn, InstanceCallable c) {
297297
ThisFlow::thisAccessExpr(cfn.getAstNode()) and

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
1313

1414
class ControlFlowNode = ControlFlow::Node;
1515

16-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
17-
18-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
19-
2016
class SourceVariable = Ssa::SourceVariable;
2117

2218
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ class BasicBlock extends BbImpl::BasicBlock {
9898
/** Gets an immediate successor of this basic block of a given type, if any. */
9999
BasicBlock getASuccessor(Input::SuccessorType t) { result = super.getASuccessor(t) }
100100

101+
BasicBlock getASuccessor() { result = super.getASuccessor() }
102+
103+
BasicBlock getImmediateDominator() { result = super.getImmediateDominator() }
104+
105+
predicate inDominanceFrontier(BasicBlock df) { super.inDominanceFrontier(df) }
106+
101107
/**
102108
* DEPRECATED: Use `getASuccessor` instead.
103109
*

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ private module SsaInput implements SsaImplCommon::InputSig<Location> {
164164

165165
class ControlFlowNode = J::ControlFlowNode;
166166

167-
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result.immediatelyDominates(bb) }
168-
169-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
170-
171167
class SourceVariable = BaseSsaSourceVariable;
172168

173169
/**

0 commit comments

Comments
 (0)