Skip to content

Commit 7631a01

Browse files
committed
Add test for goto targeting stacked label
1 parent 88df73a commit 7631a01

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎go/ql/test/library-tests/semmle/go/controlflow/GotoTarget/GotoTarget.expected‎

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import go
2+
import utils.test.InlineExpectationsTest
3+
4+
module GotoTargetTest implements TestSig {
5+
string getARelevantTag() { result = "gotoTarget" }
6+
7+
predicate hasActualResult(Location location, string element, string tag, string value) {
8+
exists(GotoStmt jump, LabeledStmt target |
9+
jump.getLocation() = location and
10+
jump.getLabel() = target.getLabel() and
11+
target.getStmt().getFirstControlFlowNode() = jump.getFirstControlFlowNode().getASuccessor+() and
12+
element = jump.toString() and
13+
tag = "gotoTarget" and
14+
value = target.getLabel()
15+
)
16+
}
17+
}
18+
19+
import MakeTest<GotoTargetTest>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
func gotoStackedLabelTarget(flag bool) {
4+
outer:
5+
inner:
6+
{
7+
if flag {
8+
goto back // $ gotoTarget=back
9+
}
10+
goto done // $ gotoTarget=done
11+
12+
back:
13+
goto inner // $ MISSING: gotoTarget=inner
14+
done:
15+
flag = false
16+
}
17+
goto outer // $ gotoTarget=outer
18+
}
19+
20+
func gotoDirectStackedLabelTarget() {
21+
goto outer // $ gotoTarget=outer
22+
outer:
23+
inner:
24+
goto inner // $ gotoTarget=inner
25+
}

0 commit comments

Comments
 (0)