Skip to content

Commit 097afec

Browse files
committed
Address review comments
1 parent 77ddd48 commit 097afec

4 files changed

Lines changed: 12 additions & 85 deletions

File tree

go/ql/lib/semmle/go/Stmt.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ class IfStmt extends @ifstmt, Stmt, ScopeNode {
717717
Expr getCondition() { result = this.getChildExpr(1) }
718718

719719
/** Gets the "then" branch of this `if` statement. */
720-
BlockStmt getThen() { result = this.getChildStmt(2) }
720+
Stmt getThen() { result = this.getChildStmt(2) }
721721

722722
/** Gets the "else" branch of this `if` statement, if any. */
723723
Stmt getElse() { result = this.getChildStmt(3) }
@@ -1085,7 +1085,7 @@ class SelectStmt extends @selectstmt, Stmt {
10851085
*/
10861086
class LoopStmt extends @loopstmt, Stmt, ScopeNode {
10871087
/** Gets the body of this loop. */
1088-
BlockStmt getBody() { none() }
1088+
Stmt getBody() { none() }
10891089
}
10901090

10911091
/**

go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ module ControlFlow {
5050
predicate isJoin() { strictcount(this.getAPredecessor()) > 1 }
5151

5252
/** Holds if this is the first control-flow node in `subtree`. */
53-
predicate isFirstNodeOf(AstNode subtree) {
54-
this.isBefore(subtree)
55-
or
56-
this.injects(subtree)
57-
}
53+
predicate isFirstNodeOf(AstNode subtree) { this.isBefore(subtree) }
5854

5955
/** Holds if this node is the unique entry node of a file or function. */
6056
predicate isEntryNode() { this instanceof CfgImpl::ControlFlow::EntryNode }

go/ql/lib/semmle/go/controlflow/ControlFlowGraphShared.qll

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ module CfgImpl {
164164
not this = any(Go::SelectStmt sel).getBody()
165165
}
166166

167-
override Stmt getStmt(int n) { result = Go::BlockStmt.super.getStmt(n) }
168-
169167
Stmt getLastStmt() {
170168
exists(int last | result = this.getStmt(last) and not exists(this.getStmt(last + 1)))
171169
}
@@ -183,23 +181,11 @@ module CfgImpl {
183181
Expr getExpr() { result = Go::ExprStmt.super.getExpr() }
184182
}
185183

186-
class IfStmt extends Stmt {
187-
IfStmt() { this instanceof Go::IfStmt }
188-
189-
Expr getCondition() { result = this.(Go::IfStmt).getCond() }
190-
191-
Stmt getThen() { result = this.(Go::IfStmt).getThen() }
192-
193-
Stmt getElse() { result = this.(Go::IfStmt).getElse() }
194-
}
184+
class IfStmt = Go::IfStmt;
195185

196186
AstNode getIfInit(IfStmt ifstmt) { result = ifstmt.(Go::IfStmt).getInit() }
197187

198-
class LoopStmt extends Stmt {
199-
LoopStmt() { this instanceof Go::LoopStmt }
200-
201-
Stmt getBody() { result = this.(Go::LoopStmt).getBody() }
202-
}
188+
class LoopStmt = Go::LoopStmt;
203189

204190
class WhileStmt extends LoopStmt {
205191
WhileStmt() { none() }
@@ -219,19 +205,15 @@ module CfgImpl {
219205
Expr getCondition() { none() }
220206
}
221207

222-
class ForStmt extends LoopStmt {
223-
ForStmt() { this instanceof Go::ForStmt }
224-
208+
class ForStmt extends LoopStmt instanceof Go::ForStmt {
225209
AstNode getInit(int index) { index = 0 and result = this.(Go::ForStmt).getInit() }
226210

227211
Expr getCondition() { result = this.(Go::ForStmt).getCond() }
228212

229213
AstNode getUpdate(int index) { index = 0 and result = this.(Go::ForStmt).getPost() }
230214
}
231215

232-
class ForeachStmt extends LoopStmt {
233-
ForeachStmt() { this instanceof Go::RangeStmt }
234-
216+
class ForeachStmt extends LoopStmt instanceof Go::RangeStmt {
235217
// Go's `range` statement binds its key and value by destructuring the
236218
// current element. The extractor synthesizes a single "range element"
237219
// node grouping the key and value (see `Go::RangeElementExpr`), which we
@@ -249,9 +231,7 @@ module CfgImpl {
249231

250232
class GotoStmt = Go::GotoStmt;
251233

252-
class ReturnStmt extends Go::ReturnStmt {
253-
override Expr getExpr() { result = Go::ReturnStmt.super.getExpr() }
254-
}
234+
class ReturnStmt = Go::ReturnStmt;
255235

256236
class Throw extends AstNode {
257237
Throw() { none() }
@@ -281,9 +261,7 @@ module CfgImpl {
281261
Stmt getBody() { none() }
282262
}
283263

284-
class Switch extends AstNode {
285-
Switch() { this instanceof Go::SwitchStmt }
286-
264+
class Switch extends AstNode instanceof Go::SwitchStmt {
287265
Expr getExpr() {
288266
result = this.(Go::ExpressionSwitchStmt).getExpr()
289267
or
@@ -837,7 +815,7 @@ module CfgImpl {
837815
PreControlFlowNode source, PreControlFlowNode target, AbruptCompletion completion
838816
) {
839817
completion.getSuccessorType() instanceof ExceptionSuccessor and
840-
isExceptionalExitNode(target) and
818+
target instanceof ExceptionalExitNodeImpl and
841819
exists(PreControlFlowNode nextDefer |
842820
deferExitStep(source, nextDefer, _) and deferInvoke(nextDefer, _)
843821
)
@@ -862,14 +840,8 @@ module CfgImpl {
862840
* Holds if `n` is the registration node of `defer` statement `s` (the
863841
* post-order node of the statement, reached once its call's arguments have
864842
* been evaluated).
865-
*
866-
* This uses the reachability-free `isInOrderNode` rather than `n.isIn(s)`
867-
* because it is referenced under negation by `succBeforeNextDeferRegistration`, and must
868-
* therefore not depend on `reachable`.
869843
*/
870-
private predicate deferRegistration(PreControlFlowNode n, Go::DeferStmt s) {
871-
isInOrderNode(n, s)
872-
}
844+
private predicate deferRegistration(PreControlFlowNode n, Go::DeferStmt s) { n.isIn(s) }
873845

874846
/**
875847
* Holds if `n` is the deferred-invocation node for `defer` statement `s`,

shared/controlflow/codeql/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,27 +1028,6 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
10281028
*/
10291029
final class PreControlFlowNode = NodeImpl;
10301030

1031-
/**
1032-
* Holds if `n` is the in-order or post-order control flow node for `ast`.
1033-
*
1034-
* Unlike the `PreControlFlowNode.isIn` member predicate, this is computed
1035-
* structurally (directly from the underlying node representation) and so
1036-
* does not give rise to a dependency on node reachability. It is intended
1037-
* for languages implementing `Input2::deferExitStep`, whose definition must
1038-
* not depend on `reachable` (see `succIgnoringDeferExit`); such languages
1039-
* can use this to identify nodes inside a negation without introducing a
1040-
* non-monotonic cycle.
1041-
*/
1042-
predicate isInOrderNode(PreControlFlowNode n, AstNode ast) { n = TAstNode(ast) }
1043-
1044-
/**
1045-
* Holds if `n` is the exceptional exit node for a callable.
1046-
*
1047-
* This is computed structurally so that it can be used while constructing
1048-
* the CFG without introducing a dependency on node reachability.
1049-
*/
1050-
predicate isExceptionalExitNode(PreControlFlowNode n) { n = TAnnotatedExitNode(_, false) }
1051-
10521031
private class BeforeNode extends NodeImpl, TBeforeNode {
10531032
private AstNode n;
10541033

@@ -1164,7 +1143,7 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
11641143
}
11651144

11661145
/** A control flow node indicating exceptional termination of a callable. */
1167-
final private class ExceptionalExitNodeImpl extends AnnotatedExitNodeImpl {
1146+
final class ExceptionalExitNodeImpl extends AnnotatedExitNodeImpl {
11681147
ExceptionalExitNodeImpl() { this = TAnnotatedExitNode(_, false) }
11691148
}
11701149

@@ -1760,26 +1739,6 @@ module Make0<LocationSig Location, AstSig<Location> Ast> {
17601739
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = true))
17611740
)
17621741
or
1763-
exists(PatternMatchExpr pme |
1764-
n1.isBefore(pme) and
1765-
n2.isBefore(pme.getExpr())
1766-
or
1767-
n1.isAfter(pme.getExpr()) and
1768-
n2.isIn(pme)
1769-
or
1770-
n1.isIn(pme) and
1771-
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = false))
1772-
or
1773-
n1.isIn(pme) and
1774-
n2.isAdditional(pme, patternMatchTrueTag())
1775-
or
1776-
n1.isAdditional(pme, patternMatchTrueTag()) and
1777-
n2.isBefore(pme.getPattern())
1778-
or
1779-
n1.isAfter(pme.getPattern()) and
1780-
n2.isAfterValue(pme, any(BooleanSuccessor s | s.getValue() = true))
1781-
)
1782-
or
17831742
exists(IfStmt ifstmt |
17841743
n1.isBefore(ifstmt) and
17851744
(

0 commit comments

Comments
 (0)