Skip to content

Commit 1c60ffa

Browse files
committed
Use default goto handling
1 parent 193cd99 commit 1c60ffa

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,21 @@ module GoCfg {
422422
// statement may have several labels.
423423
exists(Go::LabeledStmt ls | n = ls.getStmt() | l = ls.getLabel() or hasLabel(ls, l))
424424
or
425+
// The `LabeledStmt` wrapper itself also carries its label. Blocks contain
426+
// the wrapper (not the inner statement) as a direct child, so the shared
427+
// library's block-level `goto` target resolution -- which looks for a
428+
// labelled statement that is a direct child of a block -- matches on the
429+
// wrapper.
430+
l = n.(Go::LabeledStmt).getLabel()
431+
or
425432
l = n.(Go::BreakStmt).getLabel()
426433
or
427434
l = n.(Go::ContinueStmt).getLabel()
435+
or
436+
// A `goto` statement carries its target label, so that the shared
437+
// library's `beginAbruptCompletion` produces a *labelled* goto completion
438+
// (matching the target label) rather than an unlabelled one.
439+
l = n.(Go::GotoStmt).getLabel()
428440
}
429441

430442
predicate preOrderExpr(Ast::Expr e) {
@@ -732,12 +744,6 @@ module GoCfg {
732744
n.isIn(ast) and
733745
c.asSimpleAbruptCompletion() instanceof ExceptionSuccessor and
734746
always = false
735-
or
736-
ast instanceof Go::GotoStmt and
737-
n.injects(ast) and
738-
c.getSuccessorType() instanceof GotoSuccessor and
739-
c.hasLabel(ast.(Go::GotoStmt).getLabel()) and
740-
always = true
741747
}
742748

743749
predicate endAbruptCompletion(Ast::AstNode ast, PreControlFlowNode n, AbruptCompletion c) {
@@ -777,14 +783,6 @@ module GoCfg {
777783
exists(fd.getResultVar(0)) and
778784
n.isAdditional(fd.getBody(), "result-read:0")
779785
)
780-
or
781-
exists(Go::LabeledStmt lbl, Go::FuncDef fd |
782-
ast = fd.getBody() and
783-
n.isBefore(lbl) and
784-
fd = lbl.getEnclosingFunction() and
785-
c.getSuccessorType() instanceof GotoSuccessor and
786-
c.hasLabel(lbl.getLabel())
787-
)
788786
}
789787

790788
predicate overridesCallableEndAbruptCompletion(Ast::Callable c, AbruptCompletion completion) {

0 commit comments

Comments
 (0)