Skip to content

Commit f2322ca

Browse files
committed
Shared: Use shared SuccessorType in shared Cfg and BasicBlock libs.
1 parent bb896f0 commit f2322ca

File tree

9 files changed

+19
-96
lines changed

9 files changed

+19
-96
lines changed

actions/ql/lib/codeql/actions/controlflow/internal/Cfg.qll

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,8 @@ private module Implementation implements CfgShared::InputSig<Location> {
101101
last(scope.(CompositeAction), e, c)
102102
}
103103

104-
predicate successorTypeIsSimple(SuccessorType t) { t instanceof DirectSuccessor }
105-
106-
predicate successorTypeIsCondition(SuccessorType t) { t instanceof BooleanSuccessor }
107-
108104
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
109105

110-
predicate isAbnormalExitType(SuccessorType t) { none() }
111-
112106
int idOfAstNode(AstNode node) { none() }
113107

114108
int idOfCfgScope(CfgScope scope) { none() }

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,10 @@ private module CfgInput implements CfgShared::InputSig<Location> {
7979
Impl::scopeLast(scope, last, c)
8080
}
8181

82-
class SuccessorType = ST::SuccessorType;
82+
private class SuccessorType = ST::SuccessorType;
8383

8484
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
8585

86-
predicate successorTypeIsSimple(SuccessorType t) { t instanceof ST::DirectSuccessor }
87-
88-
predicate successorTypeIsCondition(SuccessorType t) { t instanceof ST::ConditionalSuccessor }
89-
90-
predicate isAbnormalExitType(SuccessorType t) {
91-
t instanceof ST::ExceptionSuccessor or
92-
t instanceof ST::ExitSuccessor
93-
}
94-
9586
int idOfAstNode(AstNode node) { result = node.getId() }
9687

9788
int idOfCfgScope(CfgScope node) { result = idOfAstNode(node) }

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ module;
77
import java
88
import Dominance
99
private import codeql.controlflow.BasicBlock as BB
10+
private import codeql.controlflow.SuccessorType
1011

1112
private module Input implements BB::InputSig<Location> {
12-
import codeql.controlflow.SuccessorType
13-
14-
/** Hold if `t` represents a conditional successor type. */
15-
predicate successorTypeIsCondition(SuccessorType t) { none() }
16-
1713
/** A delineated part of the AST with its own CFG. */
1814
class CfgScope = Callable;
1915

@@ -96,7 +92,7 @@ class BasicBlock extends BbImpl::BasicBlock {
9692
predicate strictlyDominates(BasicBlock bb) { super.strictlyDominates(bb) }
9793

9894
/** Gets an immediate successor of this basic block of a given type, if any. */
99-
BasicBlock getASuccessor(Input::SuccessorType t) { result = super.getASuccessor(t) }
95+
BasicBlock getASuccessor(SuccessorType t) { result = super.getASuccessor(t) }
10096

10197
/**
10298
* DEPRECATED: Use `getASuccessor` instead.

ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,10 @@ private module CfgInput implements CfgShared::InputSig<Location> {
4646
scope.(Impl::CfgScopeImpl).exit(last, c)
4747
}
4848

49-
class SuccessorType = Cfg::SuccessorType;
49+
private class SuccessorType = Cfg::SuccessorType;
5050

5151
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
5252

53-
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::DirectSuccessor }
54-
55-
predicate successorTypeIsCondition(SuccessorType t) { t instanceof Cfg::ConditionalSuccessor }
56-
57-
predicate isAbnormalExitType(SuccessorType t) {
58-
t instanceof Cfg::ExceptionSuccessor or
59-
t instanceof Cfg::ExitSuccessor
60-
}
61-
6253
private predicate id(Ruby::AstNode node1, Ruby::AstNode node2) { node1 = node2 }
6354

6455
private predicate idOf(Ruby::AstNode node, int id) = equivalenceRelation(id/2)(node, id)

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,11 @@ private module CfgInput implements InputSig<Location> {
2929
Stages::CfgStage::ref()
3030
}
3131

32-
class SuccessorType = Cfg::SuccessorType;
32+
private class SuccessorType = Cfg::SuccessorType;
3333

3434
/** Gets a successor type that matches completion `c`. */
3535
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
3636

37-
/**
38-
* Hold if `c` represents simple (normal) evaluation of a statement or an expression.
39-
*/
40-
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::DirectSuccessor }
41-
42-
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
43-
predicate isAbnormalExitType(SuccessorType t) { none() }
44-
45-
/** Hold if `t` represents a conditional successor type. */
46-
predicate successorTypeIsCondition(SuccessorType t) { t instanceof Cfg::BooleanSuccessor }
47-
4837
/** Holds if `first` is first executed when entering `scope`. */
4938
predicate scopeFirst(CfgScope scope, AstNode first) { scope.scopeFirst(first) }
5039

shared/controlflow/codeql/controlflow/BasicBlock.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@ overlay[local?]
99
module;
1010

1111
private import codeql.util.Location
12+
private import SuccessorType
1213

1314
/** Provides the language-specific input specification. */
1415
signature module InputSig<LocationSig Location> {
15-
class SuccessorType;
16-
17-
/** Hold if `t` represents a conditional successor type. */
18-
predicate successorTypeIsCondition(SuccessorType t);
19-
2016
/** A delineated part of the AST with its own CFG. */
2117
class CfgScope;
2218

@@ -320,7 +316,7 @@ module Make<LocationSig Location, InputSig<Location> Input> {
320316
// --true--> [true] x and y --true--> foo
321317
//
322318
// and we want to ensure that both `foo` and `bar` start a new basic block.
323-
exists(nodeGetAPredecessor(cfn, any(SuccessorType s | successorTypeIsCondition(s))))
319+
exists(nodeGetAPredecessor(cfn, any(ConditionalSuccessor s)))
324320
}
325321

326322
/**

shared/controlflow/codeql/controlflow/Cfg.qll

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module;
88
private import codeql.util.Location
99
private import codeql.util.FileSystem
1010
private import codeql.util.Void
11+
private import SuccessorType
1112

1213
/** Provides the language-specific input specification. */
1314
signature module InputSig<LocationSig Location> {
@@ -59,27 +60,9 @@ signature module InputSig<LocationSig Location> {
5960
/** Holds if `scope` is exited when `last` finishes with completion `c`. */
6061
predicate scopeLast(CfgScope scope, AstNode last, Completion c);
6162

62-
/** A type of a control flow successor. */
63-
class SuccessorType {
64-
/** Gets a textual representation of this successor type. */
65-
string toString();
66-
}
67-
6863
/** Gets a successor type that matches completion `c`. */
6964
SuccessorType getAMatchingSuccessorType(Completion c);
7065

71-
/**
72-
* Hold if `t` represents simple (normal) evaluation of a statement or an
73-
* expression.
74-
*/
75-
predicate successorTypeIsSimple(SuccessorType t);
76-
77-
/** Hold if `t` represents a conditional successor type. */
78-
predicate successorTypeIsCondition(SuccessorType t);
79-
80-
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
81-
predicate isAbnormalExitType(SuccessorType t);
82-
8366
/**
8467
* Gets an `id` of `node`. This is used to order the predecessors of a join
8568
* basic block.
@@ -522,7 +505,7 @@ module MakeWithSplitting<
522505
private predicate succEntrySplits(CfgScope pred, AstNode succ, Splits succSplits, SuccessorType t) {
523506
exists(int rnk |
524507
scopeFirst(pred, succ) and
525-
successorTypeIsSimple(t) and
508+
t instanceof DirectSuccessor and
526509
succEntrySplitsFromRank(pred, succ, succSplits, rnk)
527510
|
528511
rnk = 0 and
@@ -1016,7 +999,7 @@ module MakeWithSplitting<
1016999
exists(CfgScope scope |
10171000
pred = TAnnotatedExitNode(scope, _) and
10181001
result = TExitNode(scope) and
1019-
successorTypeIsSimple(t)
1002+
t instanceof DirectSuccessor
10201003
)
10211004
}
10221005

@@ -1117,9 +1100,7 @@ module MakeWithSplitting<
11171100
abstract Location getLocation();
11181101

11191102
/** Holds if this control flow node has conditional successors. */
1120-
predicate isCondition() {
1121-
exists(this.getASuccessor(any(SuccessorType t | successorTypeIsCondition(t))))
1122-
}
1103+
predicate isCondition() { exists(this.getASuccessor(any(ConditionalSuccessor t))) }
11231104

11241105
/** Gets the scope of this node. */
11251106
CfgScope getScope() { result = getNodeCfgScope(this) }
@@ -1320,7 +1301,7 @@ module MakeWithSplitting<
13201301
label =
13211302
strictconcat(SuccessorType t, string s |
13221303
succ = getASuccessor(pred, t) and
1323-
if successorTypeIsSimple(t) then s = "" else s = t.toString()
1304+
if t instanceof DirectSuccessor then s = "" else s = t.toString()
13241305
|
13251306
s, ", " order by s
13261307
)
@@ -1590,10 +1571,6 @@ module MakeWithSplitting<
15901571
private class NodeAlias = Node;
15911572

15921573
private module BasicBlockInputSig implements BB::InputSig<Location> {
1593-
class SuccessorType = Input::SuccessorType;
1594-
1595-
predicate successorTypeIsCondition = Input::successorTypeIsCondition/1;
1596-
15971574
class CfgScope = CfgScopeAlias;
15981575

15991576
class Node = NodeAlias;

shared/controlflow/codeql/controlflow/SuccessorType.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,9 @@ class ExitSuccessor extends AbruptSuccessor, TExitSuccessor {
296296
class JumpSuccessor extends AbruptSuccessor, TJumpSuccessor {
297297
override string toString() { result = "jump" }
298298
}
299+
300+
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
301+
predicate isAbnormalExitType(SuccessorType t) {
302+
t instanceof ExceptionSuccessor or
303+
t instanceof ExitSuccessor
304+
}

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImplSpecific.qll

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,11 @@ module CfgInput implements InputSig<Location> {
4848

4949
CfgScope getCfgScope(AstNode n) { result = scopeOfAst(n.asAstNode()) }
5050

51-
class SuccessorType = Cfg::SuccessorType;
51+
private class SuccessorType = Cfg::SuccessorType;
5252

5353
/** Gets a successor type that matches completion `c`. */
5454
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
5555

56-
/**
57-
* Hold if `c` represents simple (normal) evaluation of a statement or an
58-
* expression.
59-
*/
60-
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::DirectSuccessor }
61-
62-
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
63-
predicate isAbnormalExitType(SuccessorType t) { t instanceof Cfg::ExceptionSuccessor }
64-
65-
/** Hold if `t` represents a conditional successor type. */
66-
predicate successorTypeIsCondition(SuccessorType t) {
67-
t instanceof Cfg::BooleanSuccessor or
68-
t instanceof Cfg::JumpSuccessor or
69-
t instanceof Cfg::MatchingSuccessor or
70-
t instanceof Cfg::EmptinessSuccessor
71-
}
72-
7356
/** Holds if `first` is first executed when entering `scope`. */
7457
predicate scopeFirst(CfgScope scope, AstNode first) {
7558
scope.(Impl::CfgScope::Range_).entry(first)

0 commit comments

Comments
 (0)