| 1 |
-- go.mod -- |
| 2 |
module example.com |
| 3 |
go 1.18 |
| 4 |
|
| 5 |
-- func.go -- |
| 6 |
package main |
| 7 |
|
| 8 |
// Test of dynamic function calls. |
| 9 |
// No interfaces, so no runtime/reflect types. |
| 10 |
|
| 11 |
func A1() { |
| 12 |
A2(0) |
| 13 |
} |
| 14 |
|
| 15 |
func A2(int) {} // not address-taken |
| 16 |
|
| 17 |
func B() {} // unreachable |
| 18 |
|
| 19 |
var ( |
| 20 |
C = func(int) {} |
| 21 |
D = func(int) {} |
| 22 |
) |
| 23 |
|
| 24 |
func main() { |
| 25 |
A1() |
| 26 |
|
| 27 |
pfn := C |
| 28 |
pfn(0) // calls C and D but not A2 (same sig but not address-taken) |
| 29 |
} |
| 30 |
|
| 31 |
// WANT: |
| 32 |
// |
| 33 |
// edge main --dynamic function call--> init$1 |
| 34 |
// edge main --dynamic function call--> init$2 |
| 35 |
// |
| 36 |
// reachable A1 |
| 37 |
// reachable A2 |
| 38 |
// reachable init$1 |
| 39 |
// reachable init$2 |
| 40 |
// !reachable B |
| 41 |
// reachable main |