Skip to content

Commit db01828

Browse files
committed
Java: Deprecate redundant basic block predicates.
1 parent 13c5906 commit db01828

File tree

34 files changed

+142
-102
lines changed

34 files changed

+142
-102
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/SemanticCFG.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private import SemanticExprSpecific::SemanticExprConfig as Specific
1010
*/
1111
class SemBasicBlock extends Specific::BasicBlock {
1212
/** Holds if this block (transitively) dominates `otherblock`. */
13-
final predicate bbDominates(SemBasicBlock otherBlock) { Specific::bbDominates(this, otherBlock) }
13+
final predicate dominates(SemBasicBlock otherBlock) { Specific::bbDominates(this, otherBlock) }
1414

1515
/** Gets an expression that is evaluated in this basic block. */
1616
final SemExpr getAnExpr() { result.getBasicBlock() = this }

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,47 @@ class BasicBlock extends BbImpl::BasicBlock {
7979
/** Gets the immediately enclosing callable whose body contains this node. */
8080
Callable getEnclosingCallable() { result = this.getScope() }
8181

82-
/** Gets an immediate successor of this basic block. */
83-
BasicBlock getABBSuccessor() { result = this.getASuccessor() }
82+
/**
83+
* DEPRECATED: Use `getASuccessor` instead.
84+
*
85+
* Gets an immediate successor of this basic block.
86+
*/
87+
deprecated BasicBlock getABBSuccessor() { result = this.getASuccessor() }
8488

85-
/** Gets an immediate predecessor of this basic block. */
86-
BasicBlock getABBPredecessor() { result.getABBSuccessor() = this }
89+
/**
90+
* DEPRECATED: Use `getAPredecessor` instead.
91+
*
92+
* Gets an immediate predecessor of this basic block.
93+
*/
94+
deprecated BasicBlock getABBPredecessor() { result.getASuccessor() = this }
8795

88-
/** Holds if this basic block strictly dominates `node`. */
89-
predicate bbStrictlyDominates(BasicBlock node) { this.strictlyDominates(node) }
96+
/**
97+
* DEPRECATED: Use `strictlyDominates` instead.
98+
*
99+
* Holds if this basic block strictly dominates `node`.
100+
*/
101+
deprecated predicate bbStrictlyDominates(BasicBlock node) { this.strictlyDominates(node) }
90102

91-
/** Holds if this basic block dominates `node`. (This is reflexive.) */
92-
predicate bbDominates(BasicBlock node) { this.dominates(node) }
103+
/**
104+
* DEPRECATED: Use `dominates` instead.
105+
*
106+
* Holds if this basic block dominates `node`. (This is reflexive.)
107+
*/
108+
deprecated predicate bbDominates(BasicBlock node) { this.dominates(node) }
93109

94-
/** Holds if this basic block strictly post-dominates `node`. */
95-
predicate bbStrictlyPostDominates(BasicBlock node) { this.strictlyPostDominates(node) }
110+
/**
111+
* DEPRECATED: Use `strictlyPostDominates` instead.
112+
*
113+
* Holds if this basic block strictly post-dominates `node`.
114+
*/
115+
deprecated predicate bbStrictlyPostDominates(BasicBlock node) { this.strictlyPostDominates(node) }
96116

97-
/** Holds if this basic block post-dominates `node`. (This is reflexive.) */
98-
predicate bbPostDominates(BasicBlock node) { this.postDominates(node) }
117+
/**
118+
* DEPRECATED: Use `postDominates` instead.
119+
*
120+
* Holds if this basic block post-dominates `node`. (This is reflexive.)
121+
*/
122+
deprecated predicate bbPostDominates(BasicBlock node) { this.postDominates(node) }
99123
}
100124

101125
/** A basic block that ends in an exit node. */

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

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,72 @@ import java
88
* Predicates for basic-block-level dominance.
99
*/
1010

11-
/** The immediate dominance relation for basic blocks. */
12-
predicate bbIDominates(BasicBlock dom, BasicBlock node) { dom.immediatelyDominates(node) }
11+
/**
12+
* DEPRECATED: Use `BasicBlock::immediatelyDominates` instead.
13+
*
14+
* The immediate dominance relation for basic blocks.
15+
*/
16+
deprecated predicate bbIDominates(BasicBlock dom, BasicBlock node) {
17+
dom.immediatelyDominates(node)
18+
}
1319

1420
/** Exit points for basic-block control-flow. */
1521
private predicate bbSink(BasicBlock exit) { exit.getLastNode() instanceof ControlFlow::ExitNode }
1622

1723
/** Reversed `bbSucc`. */
18-
private predicate bbPred(BasicBlock post, BasicBlock pre) { post = pre.getABBSuccessor() }
24+
private predicate bbPred(BasicBlock post, BasicBlock pre) { post = pre.getASuccessor() }
1925

2026
/** The immediate post-dominance relation on basic blocks. */
21-
cached
22-
predicate bbIPostDominates(BasicBlock dominator, BasicBlock node) =
27+
deprecated predicate bbIPostDominates(BasicBlock dominator, BasicBlock node) =
2328
idominance(bbSink/1, bbPred/2)(_, dominator, node)
2429

25-
/** Holds if `dom` strictly dominates `node`. */
26-
predicate bbStrictlyDominates(BasicBlock dom, BasicBlock node) { bbIDominates+(dom, node) }
27-
28-
/** Holds if `dom` dominates `node`. (This is reflexive.) */
29-
predicate bbDominates(BasicBlock dom, BasicBlock node) {
30-
bbStrictlyDominates(dom, node) or dom = node
30+
/**
31+
* DEPRECATED: Use `BasicBlock::strictlyDominates` instead.
32+
*
33+
* Holds if `dom` strictly dominates `node`.
34+
*/
35+
deprecated predicate bbStrictlyDominates(BasicBlock dom, BasicBlock node) {
36+
dom.strictlyDominates(node)
3137
}
3238

33-
/** Holds if `dom` strictly post-dominates `node`. */
34-
predicate bbStrictlyPostDominates(BasicBlock dom, BasicBlock node) { bbIPostDominates+(dom, node) }
39+
/**
40+
* DEPRECATED: Use `BasicBlock::dominates` instead.
41+
*
42+
* Holds if `dom` dominates `node`. (This is reflexive.)
43+
*/
44+
deprecated predicate bbDominates(BasicBlock dom, BasicBlock node) { dom.dominates(node) }
3545

36-
/** Holds if `dom` post-dominates `node`. (This is reflexive.) */
37-
predicate bbPostDominates(BasicBlock dom, BasicBlock node) {
38-
bbStrictlyPostDominates(dom, node) or dom = node
46+
/**
47+
* DEPRECATED: Use `BasicBlock::strictlyPostDominates` instead.
48+
*
49+
* Holds if `dom` strictly post-dominates `node`.
50+
*/
51+
deprecated predicate bbStrictlyPostDominates(BasicBlock dom, BasicBlock node) {
52+
dom.strictlyPostDominates(node)
3953
}
4054

55+
/**
56+
* DEPRECATED: Use `BasicBlock::postDominates` instead.
57+
*
58+
* Holds if `dom` post-dominates `node`. (This is reflexive.)
59+
*/
60+
deprecated predicate bbPostDominates(BasicBlock dom, BasicBlock node) { dom.postDominates(node) }
61+
4162
/**
4263
* The dominance frontier relation for basic blocks.
4364
*
4465
* This is equivalent to:
4566
*
4667
* ```
47-
* bbDominates(x, w.getABBPredecessor()) and not bbStrictlyDominates(x, w)
68+
* x.dominates(w.getAPredecessor()) and not x.strictlyDominates(w)
4869
* ```
4970
*/
5071
predicate dominanceFrontier(BasicBlock x, BasicBlock w) {
51-
x = w.getABBPredecessor() and not bbIDominates(x, w)
72+
x = w.getAPredecessor() and not x.immediatelyDominates(w)
5273
or
5374
exists(BasicBlock prev | dominanceFrontier(prev, w) |
54-
bbIDominates(x, prev) and
55-
not bbIDominates(x, w)
75+
x.immediatelyDominates(prev) and
76+
not x.immediatelyDominates(w)
5677
)
5778
}
5879

@@ -65,7 +86,7 @@ predicate iDominates(ControlFlowNode dominator, ControlFlowNode node) {
6586
exists(BasicBlock bb, int i | dominator = bb.getNode(i) and node = bb.getNode(i + 1))
6687
or
6788
exists(BasicBlock dom, BasicBlock bb |
68-
bbIDominates(dom, bb) and
89+
dom.immediatelyDominates(bb) and
6990
dominator = dom.getLastNode() and
7091
node = bb.getFirstNode()
7192
)
@@ -75,7 +96,7 @@ predicate iDominates(ControlFlowNode dominator, ControlFlowNode node) {
7596
pragma[inline]
7697
predicate strictlyDominates(ControlFlowNode dom, ControlFlowNode node) {
7798
// This predicate is gigantic, so it must be inlined.
78-
bbStrictlyDominates(dom.getBasicBlock(), node.getBasicBlock())
99+
dom.getBasicBlock().strictlyDominates(node.getBasicBlock())
79100
or
80101
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i < j)
81102
}
@@ -84,7 +105,7 @@ predicate strictlyDominates(ControlFlowNode dom, ControlFlowNode node) {
84105
pragma[inline]
85106
predicate dominates(ControlFlowNode dom, ControlFlowNode node) {
86107
// This predicate is gigantic, so it must be inlined.
87-
bbStrictlyDominates(dom.getBasicBlock(), node.getBasicBlock())
108+
dom.getBasicBlock().strictlyDominates(node.getBasicBlock())
88109
or
89110
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i <= j)
90111
}
@@ -93,7 +114,7 @@ predicate dominates(ControlFlowNode dom, ControlFlowNode node) {
93114
pragma[inline]
94115
predicate strictlyPostDominates(ControlFlowNode dom, ControlFlowNode node) {
95116
// This predicate is gigantic, so it must be inlined.
96-
bbStrictlyPostDominates(dom.getBasicBlock(), node.getBasicBlock())
117+
dom.getBasicBlock().strictlyPostDominates(node.getBasicBlock())
97118
or
98119
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i > j)
99120
}
@@ -102,7 +123,7 @@ predicate strictlyPostDominates(ControlFlowNode dom, ControlFlowNode node) {
102123
pragma[inline]
103124
predicate postDominates(ControlFlowNode dom, ControlFlowNode node) {
104125
// This predicate is gigantic, so it must be inlined.
105-
bbStrictlyPostDominates(dom.getBasicBlock(), node.getBasicBlock())
126+
dom.getBasicBlock().strictlyPostDominates(node.getBasicBlock())
106127
or
107128
exists(BasicBlock b, int i, int j | dom = b.getNode(i) and node = b.getNode(j) and i >= j)
108129
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ConditionBlock extends BasicBlock {
6868
exists(BasicBlock succ |
6969
succ = this.getTestSuccessor(testIsTrue) and
7070
dominatingEdge(this, succ) and
71-
succ.bbDominates(controlled)
71+
succ.dominates(controlled)
7272
)
7373
}
7474
}
@@ -287,7 +287,7 @@ private predicate switchCaseControls(SwitchCase sc, BasicBlock bb) {
287287
// Pattern cases are handled as condition blocks
288288
not sc instanceof PatternCase and
289289
caseblock.getFirstNode() = sc.getControlFlowNode() and
290-
caseblock.bbDominates(bb) and
290+
caseblock.dominates(bb) and
291291
// Check we can't fall through from a previous block:
292292
forall(ControlFlowNode pred | pred = sc.getControlFlowNode().getAPredecessor() |
293293
isNonFallThroughPredecessor(sc, pred)
@@ -307,7 +307,7 @@ private predicate preconditionControls(MethodCall ma, BasicBlock controlled, boo
307307
exists(BasicBlock check, BasicBlock succ |
308308
preconditionBranchEdge(ma, check, succ, branch) and
309309
dominatingEdge(check, succ) and
310-
succ.bbDominates(controlled)
310+
succ.dominates(controlled)
311311
)
312312
}
313313

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private predicate callAlwaysPerformsAction(Call call, ActionConfiguration conf)
4747
private predicate actionDominatesExit(Callable callable, ActionConfiguration conf) {
4848
exists(ExitBlock exit |
4949
exit.getEnclosingCallable() = callable and
50-
actionBlock(conf).bbDominates(exit)
50+
actionBlock(conf).dominates(exit)
5151
)
5252
}
5353

@@ -56,12 +56,12 @@ private BasicBlock nonDominatingActionBlock(ActionConfiguration conf) {
5656
exists(ExitBlock exit |
5757
result = actionBlock(conf) and
5858
exit.getEnclosingCallable() = result.getEnclosingCallable() and
59-
not result.bbDominates(exit)
59+
not result.dominates(exit)
6060
)
6161
}
6262

6363
private class JoinBlock extends BasicBlock {
64-
JoinBlock() { 2 <= strictcount(this.getABBPredecessor()) }
64+
JoinBlock() { 2 <= strictcount(this.getAPredecessor()) }
6565
}
6666

6767
/**
@@ -72,8 +72,8 @@ private predicate postActionBlock(BasicBlock bb, ActionConfiguration conf) {
7272
bb = nonDominatingActionBlock(conf)
7373
or
7474
if bb instanceof JoinBlock
75-
then forall(BasicBlock pred | pred = bb.getABBPredecessor() | postActionBlock(pred, conf))
76-
else postActionBlock(bb.getABBPredecessor(), conf)
75+
then forall(BasicBlock pred | pred = bb.getAPredecessor() | postActionBlock(pred, conf))
76+
else postActionBlock(bb.getAPredecessor(), conf)
7777
}
7878

7979
/** Holds if every path through `callable` goes through at least one action node. */

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class UnreachableBasicBlock extends BasicBlock {
209209
or
210210
// This block is not reachable in the CFG, and is not the entrypoint in a callable, an
211211
// expression in an assert statement, or a catch clause.
212-
forall(BasicBlock bb | bb = this.getABBPredecessor() | bb instanceof UnreachableBasicBlock) and
212+
forall(BasicBlock bb | bb = this.getAPredecessor() | bb instanceof UnreachableBasicBlock) and
213213
not exists(Callable c | c.getBody().getControlFlowNode() = this.getFirstNode()) and
214214
not this.getFirstNode().asExpr().getEnclosingStmt() instanceof AssertStmt and
215215
not this.getFirstNode().asStmt() instanceof CatchClause
@@ -219,11 +219,10 @@ class UnreachableBasicBlock extends BasicBlock {
219219
// Not accessible from the switch expression
220220
unreachableCaseBlock = constSwitchStmt.getAFailingCase().getBasicBlock() and
221221
// Not accessible from the successful case
222-
not constSwitchStmt.getMatchingCase().getBasicBlock().getABBSuccessor*() =
223-
unreachableCaseBlock
222+
not constSwitchStmt.getMatchingCase().getBasicBlock().getASuccessor*() = unreachableCaseBlock
224223
|
225224
// Blocks dominated by an unreachable case block are unreachable
226-
unreachableCaseBlock.bbDominates(this)
225+
unreachableCaseBlock.dominates(this)
227226
)
228227
}
229228
}

java/ql/lib/semmle/code/java/controlflow/internal/GuardsLogic.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ SsaVariable getADefinition(SsaVariable v, boolean fromBackEdge) {
239239
exists(SsaVariable inp, BasicBlock bb, boolean fbe |
240240
v.(SsaPhiNode).hasInputFromBlock(inp, bb) and
241241
result = getADefinition(inp, fbe) and
242-
(if v.getBasicBlock().bbDominates(bb) then fromBackEdge = true else fromBackEdge = fbe)
242+
(if v.getBasicBlock().dominates(bb) then fromBackEdge = true else fromBackEdge = fbe)
243243
)
244244
}
245245

@@ -306,7 +306,7 @@ private predicate guardControlsPhiBranch(
306306
guard.directlyControls(upd.getBasicBlock(), branch) and
307307
upd.getDefiningExpr().(VariableAssign).getSource() = e and
308308
upd = phi.getAPhiInput() and
309-
guard.getBasicBlock().bbStrictlyDominates(phi.getBasicBlock())
309+
guard.getBasicBlock().strictlyDominates(phi.getBasicBlock())
310310
}
311311

312312
/**
@@ -331,7 +331,7 @@ private predicate conditionalAssign(SsaVariable v, Guard guard, boolean branch,
331331
forall(SsaVariable other | other != upd and other = phi.getAPhiInput() |
332332
guard.directlyControls(other.getBasicBlock(), branch.booleanNot())
333333
or
334-
other.getBasicBlock().bbDominates(guard.getBasicBlock()) and
334+
other.getBasicBlock().dominates(guard.getBasicBlock()) and
335335
not other.isLiveAtEndOfBlock(getAGuardBranchSuccessor(guard, branch))
336336
)
337337
)

java/ql/lib/semmle/code/java/dataflow/Nullness.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private predicate impossibleEdge(BasicBlock bb1, BasicBlock bb2) {
298298
private predicate leavingFinally(BasicBlock bb1, BasicBlock bb2, boolean normaledge) {
299299
exists(TryStmt try, BlockStmt finally |
300300
try.getFinally() = finally and
301-
bb1.getABBSuccessor() = bb2 and
301+
bb1.getASuccessor() = bb2 and
302302
bb1.getFirstNode().getEnclosingStmt().getEnclosingStmt*() = finally and
303303
not bb2.getFirstNode().getEnclosingStmt().getEnclosingStmt*() = finally and
304304
if bb1.getLastNode().getANormalSuccessor() = bb2.getFirstNode()
@@ -339,7 +339,7 @@ private predicate nullVarStep(
339339
midssa.isLiveAtEndOfBlock(mid) and
340340
not ensureNotNull(midssa).getBasicBlock() = mid and
341341
not assertFail(mid, _) and
342-
bb = mid.getABBSuccessor() and
342+
bb = mid.getASuccessor() and
343343
not impossibleEdge(mid, bb) and
344344
not exists(boolean branch | nullGuard(midssa, branch, false).hasBranchEdge(mid, bb, branch)) and
345345
not (leavingFinally(mid, bb, true) and midstoredcompletion = true) and

java/ql/lib/semmle/code/java/dataflow/RangeAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ module Sem implements Semantic<Location> {
209209

210210
class BasicBlock = J::BasicBlock;
211211

212-
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getABBSuccessor() }
212+
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
213213

214214
private predicate id(ExprParent x, ExprParent y) { x = y }
215215

java/ql/lib/semmle/code/java/dataflow/TypeFlow.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ private module Input implements TypeFlowInput<Location> {
321321
*/
322322
private predicate instanceofDisjunct(InstanceOfExpr ioe, BasicBlock bb, BaseSsaVariable v) {
323323
ioe.getExpr() = v.getAUse() and
324-
strictcount(bb.getABBPredecessor()) > 1 and
324+
strictcount(bb.getAPredecessor()) > 1 and
325325
exists(ConditionBlock cb | cb.getCondition() = ioe and cb.getTestSuccessor(true) = bb)
326326
}
327327

328328
/** Holds if `bb` is disjunctively guarded by multiple `instanceof` tests on `v`. */
329329
private predicate instanceofDisjunction(BasicBlock bb, BaseSsaVariable v) {
330330
strictcount(InstanceOfExpr ioe | instanceofDisjunct(ioe, bb, v)) =
331-
strictcount(bb.getABBPredecessor())
331+
strictcount(bb.getAPredecessor())
332332
}
333333

334334
/**
@@ -338,7 +338,7 @@ private module Input implements TypeFlowInput<Location> {
338338
predicate instanceofDisjunctionGuarded(TypeFlowNode n, RefType t) {
339339
exists(BasicBlock bb, InstanceOfExpr ioe, BaseSsaVariable v, VarAccess va |
340340
instanceofDisjunction(bb, v) and
341-
bb.bbDominates(va.getBasicBlock()) and
341+
bb.dominates(va.getBasicBlock()) and
342342
va = v.getAUse() and
343343
instanceofDisjunct(ioe, bb, v) and
344344
t = ioe.getSyntacticCheckedType() and

0 commit comments

Comments
 (0)