Skip to content

Commit 0ed3300

Browse files
committed
Add extra CFG test for type switch
1 parent 8df2352 commit 0ed3300

File tree

2 files changed

+97
-62
lines changed

2 files changed

+97
-62
lines changed

go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/ControlFlowNode_getASuccessor.expected

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,12 +1369,11 @@
13691369
| stmts.go:107:10:107:10 | true is false | stmts.go:106:3:106:7 | skip |
13701370
| stmts.go:107:10:107:10 | true is true | stmts.go:107:2:107:11 | skip |
13711371
| stmts.go:112:1:112:1 | entry | stmts.go:112:12:112:12 | argument corresponding to x |
1372-
| stmts.go:112:1:125:1 | function declaration | stmts.go:128:6:128:11 | skip |
1373-
| stmts.go:112:6:112:10 | skip | stmts.go:112:1:125:1 | function declaration |
1372+
| stmts.go:112:1:137:1 | function declaration | stmts.go:140:6:140:11 | skip |
1373+
| stmts.go:112:6:112:10 | skip | stmts.go:112:1:137:1 | function declaration |
13741374
| stmts.go:112:12:112:12 | argument corresponding to x | stmts.go:112:12:112:12 | initialization of x |
13751375
| stmts.go:112:12:112:12 | initialization of x | stmts.go:113:9:113:9 | skip |
13761376
| stmts.go:113:9:113:9 | assignment to y | stmts.go:114:7:114:11 | case error |
1377-
| stmts.go:113:9:113:9 | assignment to y | stmts.go:121:9:121:9 | skip |
13781377
| stmts.go:113:9:113:9 | skip | stmts.go:113:14:113:14 | x |
13791378
| stmts.go:113:14:113:14 | x | stmts.go:113:14:113:21 | type assertion |
13801379
| stmts.go:113:14:113:21 | type assertion | stmts.go:113:9:113:9 | assignment to y |
@@ -1383,71 +1382,95 @@
13831382
| stmts.go:114:14:114:19 | case string | stmts.go:115:3:115:13 | selection of Println |
13841383
| stmts.go:114:14:114:19 | case string | stmts.go:116:7:116:13 | case float32 |
13851384
| stmts.go:115:3:115:13 | selection of Println | stmts.go:115:15:115:15 | y |
1386-
| stmts.go:115:3:115:16 | call to Println | stmts.go:121:9:121:9 | skip |
1387-
| stmts.go:115:3:115:16 | call to Println | stmts.go:125:1:125:1 | exit |
1385+
| stmts.go:115:3:115:16 | call to Println | stmts.go:123:9:123:9 | skip |
1386+
| stmts.go:115:3:115:16 | call to Println | stmts.go:137:1:137:1 | exit |
13881387
| stmts.go:115:15:115:15 | y | stmts.go:115:3:115:16 | call to Println |
13891388
| stmts.go:116:7:116:13 | case float32 | stmts.go:117:3:117:7 | test5 |
1390-
| stmts.go:116:7:116:13 | case float32 | stmts.go:121:9:121:9 | skip |
1389+
| stmts.go:116:7:116:13 | case float32 | stmts.go:120:3:120:3 | skip |
13911390
| stmts.go:117:3:117:7 | test5 | stmts.go:117:9:117:12 | true |
1392-
| stmts.go:117:3:117:13 | call to test5 | stmts.go:125:1:125:1 | exit |
1391+
| stmts.go:117:3:117:13 | call to test5 | stmts.go:137:1:137:1 | exit |
13931392
| stmts.go:117:9:117:12 | true | stmts.go:117:3:117:13 | call to test5 |
13941393
| stmts.go:118:3:118:7 | test5 | stmts.go:118:9:118:13 | false |
13951394
| stmts.go:118:9:118:13 | false | stmts.go:118:3:118:14 | call to test5 |
1396-
| stmts.go:121:9:121:9 | assignment to y | stmts.go:121:17:121:17 | y |
1397-
| stmts.go:121:9:121:9 | skip | stmts.go:121:14:121:14 | x |
1398-
| stmts.go:121:14:121:14 | x | stmts.go:121:9:121:9 | assignment to y |
1399-
| stmts.go:121:17:121:17 | y | stmts.go:121:17:121:24 | type assertion |
1400-
| stmts.go:121:17:121:24 | type assertion | stmts.go:123:3:123:7 | test5 |
1401-
| stmts.go:123:3:123:7 | test5 | stmts.go:123:9:123:13 | false |
1402-
| stmts.go:123:3:123:14 | call to test5 | stmts.go:125:1:125:1 | exit |
1403-
| stmts.go:123:9:123:13 | false | stmts.go:123:3:123:14 | call to test5 |
1404-
| stmts.go:128:1:128:1 | entry | stmts.go:128:13:128:13 | argument corresponding to f |
1405-
| stmts.go:128:1:130:1 | function declaration | stmts.go:133:6:133:11 | skip |
1406-
| stmts.go:128:6:128:11 | skip | stmts.go:128:1:130:1 | function declaration |
1407-
| stmts.go:128:13:128:13 | argument corresponding to f | stmts.go:128:13:128:13 | initialization of f |
1408-
| stmts.go:128:13:128:13 | initialization of f | stmts.go:129:5:129:5 | f |
1409-
| stmts.go:129:2:129:7 | go statement | stmts.go:130:1:130:1 | exit |
1410-
| stmts.go:129:5:129:5 | f | stmts.go:129:2:129:7 | go statement |
1411-
| stmts.go:133:1:133:1 | entry | stmts.go:133:13:133:14 | argument corresponding to xs |
1412-
| stmts.go:133:1:147:1 | function declaration | stmts.go:0:0:0:0 | exit |
1413-
| stmts.go:133:6:133:11 | skip | stmts.go:133:1:147:1 | function declaration |
1414-
| stmts.go:133:13:133:14 | argument corresponding to xs | stmts.go:133:13:133:14 | initialization of xs |
1415-
| stmts.go:133:13:133:14 | initialization of xs | stmts.go:134:17:134:18 | xs |
1416-
| stmts.go:134:2:139:2 | range statement[0] | stmts.go:134:6:134:6 | assignment to x |
1417-
| stmts.go:134:6:134:6 | assignment to x | stmts.go:135:6:135:6 | x |
1418-
| stmts.go:134:6:134:6 | skip | stmts.go:134:2:139:2 | range statement[0] |
1419-
| stmts.go:134:17:134:18 | next key-value pair in range | stmts.go:134:6:134:6 | skip |
1420-
| stmts.go:134:17:134:18 | next key-value pair in range | stmts.go:141:20:141:21 | xs |
1421-
| stmts.go:134:17:134:18 | xs | stmts.go:134:17:134:18 | next key-value pair in range |
1422-
| stmts.go:135:6:135:6 | x | stmts.go:135:10:135:10 | 5 |
1423-
| stmts.go:135:6:135:10 | ...>... | stmts.go:135:10:135:10 | ...>... is false |
1424-
| stmts.go:135:6:135:10 | ...>... | stmts.go:135:10:135:10 | ...>... is true |
1425-
| stmts.go:135:10:135:10 | 5 | stmts.go:135:6:135:10 | ...>... |
1426-
| stmts.go:135:10:135:10 | ...>... is false | stmts.go:138:3:138:11 | selection of Print |
1427-
| stmts.go:135:10:135:10 | ...>... is true | stmts.go:136:4:136:11 | skip |
1428-
| stmts.go:136:4:136:11 | skip | stmts.go:134:17:134:18 | next key-value pair in range |
1429-
| stmts.go:138:3:138:11 | selection of Print | stmts.go:138:13:138:13 | x |
1430-
| stmts.go:138:3:138:14 | call to Print | stmts.go:134:17:134:18 | next key-value pair in range |
1431-
| stmts.go:138:3:138:14 | call to Print | stmts.go:147:1:147:1 | exit |
1432-
| stmts.go:138:13:138:13 | x | stmts.go:138:3:138:14 | call to Print |
1433-
| stmts.go:141:2:143:2 | range statement[0] | stmts.go:141:2:143:2 | range statement[1] |
1434-
| stmts.go:141:2:143:2 | range statement[1] | stmts.go:141:6:141:6 | assignment to i |
1435-
| stmts.go:141:6:141:6 | assignment to i | stmts.go:141:9:141:9 | assignment to v |
1436-
| stmts.go:141:6:141:6 | skip | stmts.go:141:9:141:9 | skip |
1437-
| stmts.go:141:9:141:9 | assignment to v | stmts.go:142:3:142:11 | selection of Print |
1438-
| stmts.go:141:9:141:9 | skip | stmts.go:141:2:143:2 | range statement[0] |
1439-
| stmts.go:141:20:141:21 | next key-value pair in range | stmts.go:141:6:141:6 | skip |
1440-
| stmts.go:141:20:141:21 | next key-value pair in range | stmts.go:145:12:145:13 | xs |
1441-
| stmts.go:141:20:141:21 | xs | stmts.go:141:20:141:21 | next key-value pair in range |
1442-
| stmts.go:142:3:142:11 | selection of Print | stmts.go:142:13:142:13 | i |
1443-
| stmts.go:142:3:142:17 | call to Print | stmts.go:141:20:141:21 | next key-value pair in range |
1444-
| stmts.go:142:3:142:17 | call to Print | stmts.go:147:1:147:1 | exit |
1445-
| stmts.go:142:13:142:13 | i | stmts.go:142:16:142:16 | v |
1446-
| stmts.go:142:16:142:16 | v | stmts.go:142:3:142:17 | call to Print |
1447-
| stmts.go:145:12:145:13 | next key-value pair in range | stmts.go:145:15:146:2 | skip |
1448-
| stmts.go:145:12:145:13 | next key-value pair in range | stmts.go:147:1:147:1 | exit |
1449-
| stmts.go:145:12:145:13 | xs | stmts.go:145:12:145:13 | next key-value pair in range |
1450-
| stmts.go:145:15:146:2 | skip | stmts.go:145:12:145:13 | next key-value pair in range |
1395+
| stmts.go:120:3:120:3 | skip | stmts.go:120:7:120:7 | y |
1396+
| stmts.go:120:7:120:7 | y | stmts.go:123:9:123:9 | skip |
1397+
| stmts.go:123:9:123:9 | assignment to y | stmts.go:123:17:123:17 | y |
1398+
| stmts.go:123:9:123:9 | skip | stmts.go:123:14:123:14 | x |
1399+
| stmts.go:123:14:123:14 | x | stmts.go:123:9:123:9 | assignment to y |
1400+
| stmts.go:123:17:123:17 | y | stmts.go:123:17:123:24 | type assertion |
1401+
| stmts.go:123:17:123:24 | type assertion | stmts.go:124:7:124:11 | case error |
1402+
| stmts.go:124:7:124:11 | case error | stmts.go:124:14:124:19 | case string |
1403+
| stmts.go:124:7:124:11 | case error | stmts.go:125:3:125:13 | selection of Println |
1404+
| stmts.go:124:14:124:19 | case string | stmts.go:125:3:125:13 | selection of Println |
1405+
| stmts.go:124:14:124:19 | case string | stmts.go:126:7:126:13 | case float32 |
1406+
| stmts.go:125:3:125:13 | selection of Println | stmts.go:125:15:125:15 | y |
1407+
| stmts.go:125:3:125:16 | call to Println | stmts.go:133:9:133:9 | skip |
1408+
| stmts.go:125:3:125:16 | call to Println | stmts.go:137:1:137:1 | exit |
1409+
| stmts.go:125:15:125:15 | y | stmts.go:125:3:125:16 | call to Println |
1410+
| stmts.go:126:7:126:13 | case float32 | stmts.go:127:3:127:7 | test5 |
1411+
| stmts.go:126:7:126:13 | case float32 | stmts.go:130:3:130:3 | skip |
1412+
| stmts.go:127:3:127:7 | test5 | stmts.go:127:9:127:12 | true |
1413+
| stmts.go:127:3:127:13 | call to test5 | stmts.go:137:1:137:1 | exit |
1414+
| stmts.go:127:9:127:12 | true | stmts.go:127:3:127:13 | call to test5 |
1415+
| stmts.go:128:3:128:7 | test5 | stmts.go:128:9:128:13 | false |
1416+
| stmts.go:128:9:128:13 | false | stmts.go:128:3:128:14 | call to test5 |
1417+
| stmts.go:130:3:130:3 | skip | stmts.go:130:7:130:7 | y |
1418+
| stmts.go:130:7:130:7 | y | stmts.go:133:9:133:9 | skip |
1419+
| stmts.go:133:9:133:9 | assignment to y | stmts.go:133:17:133:17 | y |
1420+
| stmts.go:133:9:133:9 | skip | stmts.go:133:14:133:14 | x |
1421+
| stmts.go:133:14:133:14 | x | stmts.go:133:9:133:9 | assignment to y |
1422+
| stmts.go:133:17:133:17 | y | stmts.go:133:17:133:24 | type assertion |
1423+
| stmts.go:133:17:133:24 | type assertion | stmts.go:135:3:135:7 | test5 |
1424+
| stmts.go:135:3:135:7 | test5 | stmts.go:135:9:135:13 | false |
1425+
| stmts.go:135:3:135:14 | call to test5 | stmts.go:137:1:137:1 | exit |
1426+
| stmts.go:135:9:135:13 | false | stmts.go:135:3:135:14 | call to test5 |
1427+
| stmts.go:140:1:140:1 | entry | stmts.go:140:13:140:13 | argument corresponding to f |
1428+
| stmts.go:140:1:142:1 | function declaration | stmts.go:145:6:145:11 | skip |
1429+
| stmts.go:140:6:140:11 | skip | stmts.go:140:1:142:1 | function declaration |
1430+
| stmts.go:140:13:140:13 | argument corresponding to f | stmts.go:140:13:140:13 | initialization of f |
1431+
| stmts.go:140:13:140:13 | initialization of f | stmts.go:141:5:141:5 | f |
1432+
| stmts.go:141:2:141:7 | go statement | stmts.go:142:1:142:1 | exit |
1433+
| stmts.go:141:5:141:5 | f | stmts.go:141:2:141:7 | go statement |
1434+
| stmts.go:145:1:145:1 | entry | stmts.go:145:13:145:14 | argument corresponding to xs |
1435+
| stmts.go:145:1:159:1 | function declaration | stmts.go:0:0:0:0 | exit |
1436+
| stmts.go:145:6:145:11 | skip | stmts.go:145:1:159:1 | function declaration |
1437+
| stmts.go:145:13:145:14 | argument corresponding to xs | stmts.go:145:13:145:14 | initialization of xs |
1438+
| stmts.go:145:13:145:14 | initialization of xs | stmts.go:146:17:146:18 | xs |
1439+
| stmts.go:146:2:151:2 | range statement[0] | stmts.go:146:6:146:6 | assignment to x |
1440+
| stmts.go:146:6:146:6 | assignment to x | stmts.go:147:6:147:6 | x |
1441+
| stmts.go:146:6:146:6 | skip | stmts.go:146:2:151:2 | range statement[0] |
1442+
| stmts.go:146:17:146:18 | next key-value pair in range | stmts.go:146:6:146:6 | skip |
1443+
| stmts.go:146:17:146:18 | next key-value pair in range | stmts.go:153:20:153:21 | xs |
1444+
| stmts.go:146:17:146:18 | xs | stmts.go:146:17:146:18 | next key-value pair in range |
1445+
| stmts.go:147:6:147:6 | x | stmts.go:147:10:147:10 | 5 |
1446+
| stmts.go:147:6:147:10 | ...>... | stmts.go:147:10:147:10 | ...>... is false |
1447+
| stmts.go:147:6:147:10 | ...>... | stmts.go:147:10:147:10 | ...>... is true |
1448+
| stmts.go:147:10:147:10 | 5 | stmts.go:147:6:147:10 | ...>... |
1449+
| stmts.go:147:10:147:10 | ...>... is false | stmts.go:150:3:150:11 | selection of Print |
1450+
| stmts.go:147:10:147:10 | ...>... is true | stmts.go:148:4:148:11 | skip |
1451+
| stmts.go:148:4:148:11 | skip | stmts.go:146:17:146:18 | next key-value pair in range |
1452+
| stmts.go:150:3:150:11 | selection of Print | stmts.go:150:13:150:13 | x |
1453+
| stmts.go:150:3:150:14 | call to Print | stmts.go:146:17:146:18 | next key-value pair in range |
1454+
| stmts.go:150:3:150:14 | call to Print | stmts.go:159:1:159:1 | exit |
1455+
| stmts.go:150:13:150:13 | x | stmts.go:150:3:150:14 | call to Print |
1456+
| stmts.go:153:2:155:2 | range statement[0] | stmts.go:153:2:155:2 | range statement[1] |
1457+
| stmts.go:153:2:155:2 | range statement[1] | stmts.go:153:6:153:6 | assignment to i |
1458+
| stmts.go:153:6:153:6 | assignment to i | stmts.go:153:9:153:9 | assignment to v |
1459+
| stmts.go:153:6:153:6 | skip | stmts.go:153:9:153:9 | skip |
1460+
| stmts.go:153:9:153:9 | assignment to v | stmts.go:154:3:154:11 | selection of Print |
1461+
| stmts.go:153:9:153:9 | skip | stmts.go:153:2:155:2 | range statement[0] |
1462+
| stmts.go:153:20:153:21 | next key-value pair in range | stmts.go:153:6:153:6 | skip |
1463+
| stmts.go:153:20:153:21 | next key-value pair in range | stmts.go:157:12:157:13 | xs |
1464+
| stmts.go:153:20:153:21 | xs | stmts.go:153:20:153:21 | next key-value pair in range |
1465+
| stmts.go:154:3:154:11 | selection of Print | stmts.go:154:13:154:13 | i |
1466+
| stmts.go:154:3:154:17 | call to Print | stmts.go:153:20:153:21 | next key-value pair in range |
1467+
| stmts.go:154:3:154:17 | call to Print | stmts.go:159:1:159:1 | exit |
1468+
| stmts.go:154:13:154:13 | i | stmts.go:154:16:154:16 | v |
1469+
| stmts.go:154:16:154:16 | v | stmts.go:154:3:154:17 | call to Print |
1470+
| stmts.go:157:12:157:13 | next key-value pair in range | stmts.go:157:15:158:2 | skip |
1471+
| stmts.go:157:12:157:13 | next key-value pair in range | stmts.go:159:1:159:1 | exit |
1472+
| stmts.go:157:12:157:13 | xs | stmts.go:157:12:157:13 | next key-value pair in range |
1473+
| stmts.go:157:15:158:2 | skip | stmts.go:157:12:157:13 | next key-value pair in range |
14511474
| tst.go:0:0:0:0 | entry | tst.go:3:6:3:10 | skip |
14521475
| tst.go:3:1:3:1 | entry | tst.go:3:12:3:12 | argument corresponding to x |
14531476
| tst.go:3:1:12:1 | function declaration | tst.go:14:6:14:11 | skip |

go/ql/test/library-tests/semmle/go/controlflow/ControlFlowGraph/stmts.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ func test9(x interface{}) {
116116
case float32:
117117
test5(true)
118118
test5(false)
119+
default:
120+
_ = y
121+
}
122+
123+
switch y := x; y.(type) {
124+
case error, string:
125+
fmt.Println(y)
126+
case float32:
127+
test5(true)
128+
test5(false)
129+
default:
130+
_ = y
119131
}
120132

121133
switch y := x; y.(type) {

0 commit comments

Comments
 (0)