File tree Expand file tree Collapse file tree
lib/semmle/go/controlflow
test/library-tests/semmle/go/controlflow/GotoTarget Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -836,13 +836,23 @@ module CfgImpl {
836836 n .isAdditional ( fd .getBody ( ) , "result-read:0" )
837837 )
838838 or
839- // Function bodies are excluded from `Ast::BlockStmt`, so handle goto
840- // targets among their top-level statements here.
841- exists ( Go:: FuncDef fd , Go:: Stmt target , Label l |
842- ast = fd .getBody ( ) and
843- target = fd .getBody ( ) .getAStmt ( ) and
839+ // Handle goto targets that the shared block logic cannot see: top-level
840+ // statements of function bodies and labels enclosing the current node.
841+ exists ( Go:: Stmt target , Label l |
842+ (
843+ exists ( Go:: FuncDef fd |
844+ ast = fd .getBody ( ) and
845+ target = fd .getBody ( ) .getAStmt ( ) and
846+ hasLabel ( target , l )
847+ )
848+ or
849+ exists ( Go:: LabeledStmt lbl |
850+ ast = lbl .getStmt ( ) and
851+ target = lbl and
852+ l = lbl .getLabel ( )
853+ )
854+ ) and
844855 not target instanceof Go:: GotoStmt and
845- hasLabel ( target , l ) and
846856 n .isBefore ( target ) and
847857 c .getSuccessorType ( ) instanceof GotoSuccessor and
848858 c .hasLabel ( l )
Original file line number Diff line number Diff line change 1010 goto done // $ gotoTarget=done
1111
1212 back:
13- goto inner // $ MISSING: gotoTarget=inner
13+ goto inner // $ gotoTarget=inner
1414 done:
1515 flag = false
1616 }
You can’t perform that action at this time.
0 commit comments