| # Test of -whylive flag. |
| |
| # The -whylive argument must be live. |
| |
| !deadcode -whylive=example.com.d example.com |
| want "function example.com.d is dead code" |
| |
| # A fully static path is preferred, even if longer. |
| |
| deadcode -whylive=example.com.c example.com |
| want " example.com.main" |
| want " static@L0004 --> example.com.a" |
| want " static@L0009 --> example.com.b" |
| want " static@L0012 --> example.com.c" |
| |
| # Dynamic edges are followed if necessary. |
| # (Note that main is preferred over init.) |
| |
| deadcode -whylive=example.com.f example.com |
| want " example.com.main" |
| want "dynamic@L0006 --> example.com.e" |
| want " static@L0017 --> example.com.f" |
| |
| # Degenerate case where target is itself a root. |
| |
| !deadcode -whylive=example.com.main example.com |
| want "example.com.main is a root" |
| |
| -- go.mod -- |
| module example.com |
| go 1.18 |
| |
| -- main.go -- |
| package main |
| |
| func main() { |
| a() |
| println(c, e) // c, e are address-taken |
| (func ())(nil)() // potential dynamic call to c, e |
| } |
| func a() { |
| b() |
| } |
| func b() { |
| c() |
| } |
| func c() |
| func d() |
| func e() { |
| f() |
| } |
| func f() |
| |
| func init() { |
| (func ())(nil)() // potential dynamic call to c, e |
| } |