Debian Codegraph @

cmd/deadcode/testdata/whylive.txtar

raw
1 # Test of -whylive flag.
2
3 # The -whylive argument must be live.
4
5 !deadcode -whylive=example.com.d example.com
6 want "function example.com.d is dead code"
7
8 # A fully static path is preferred, even if longer.
9
10 deadcode -whylive=example.com.c example.com
11 want " example.com.main"
12 want " static@L0004 --> example.com.a"
13 want " static@L0009 --> example.com.b"
14 want " static@L0012 --> example.com.c"
15
16 # Dynamic edges are followed if necessary.
17 # (Note that main is preferred over init.)
18
19 deadcode -whylive=example.com.f example.com
20 want " example.com.main"
21 want "dynamic@L0006 --> example.com.e"
22 want " static@L0017 --> example.com.f"
23
24 # Degenerate case where target is itself a root.
25
26 !deadcode -whylive=example.com.main example.com
27 want "example.com.main is a root"
28
29 # Test of path through (*T).m method wrapper.
30
31 deadcode -whylive=example.com/p.live example.com/p
32 want " example.com/p.main"
33 want "static@L0006 --> example.com/p.E.Error"
34 want "static@L0010 --> example.com/p.live"
35
36 # Test of path through (I).m interface method wrapper (thunk).
37
38 deadcode -whylive=example.com/q.live example.com/q
39 want " example.com/q.main"
40 want "static@L0006 --> example.com/q.E.Error"
41 want "static@L0010 --> example.com/q.live"
42
43 # Test of path through synthetic package initializer,
44 # a declared package initializer, and its anonymous function.
45
46 deadcode -whylive=example.com/q.live2 example.com/q
47 want " example.com/q.init"
48 want "static@L0000 --> example.com/q.init#1"
49 want "static@L0016 --> example.com/q.init#1$1"
50 want "static@L0015 --> example.com/q.live2"
51
52 # Test of path through synthetic package initializer,
53 # and a global var initializer.
54
55 deadcode -whylive=example.com/r.live example.com/r
56 want " example.com/r.init"
57 want "static@L0007 --> example.com/r.init$1"
58 want "static@L0006 --> example.com/r.live"
59
60 -- go.mod --
61 module example.com
62 go 1.18
63
64 -- main.go --
65 package main
66
67 func main() {
68 a()
69 println(c, e) // c, e are address-taken
70 (func ())(nil)() // potential dynamic call to c, e
71 }
72 func a() {
73 b()
74 }
75 func b() {
76 c()
77 }
78 func c()
79 func d()
80 func e() {
81 f()
82 }
83 func f()
84
85 func init() {
86 (func ())(nil)() // potential dynamic call to c, e
87 }
88
89 -- p/p.go --
90 package main
91
92 func main() {
93 f := (*E).Error
94 var e E
95 f(&e)
96 }
97
98 type E int
99 func (E) Error() string { return live() }
100
101 func live() string
102
103 -- q/q.go --
104 package main
105
106 func main() {
107 f := error.Error
108 var e E
109 f(e)
110 }
111
112 type E int
113 func (E) Error() string { return live() }
114
115 func live() string
116
117 func init() {
118 f := func() { live2() }
119 f()
120 }
121
122 func live2()
123
124 -- r/r.go --
125 package main
126
127 func main() {}
128
129 var x = func() int {
130 return live()
131 }()
132
133 func live() int