Debian Codegraph @

go/callgraph/vta/testdata/src/dynamic_calls.go

raw symbols SCIP
1 // Copyright 2021 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // go:build ignore
6
7 package testdata
8
9 type I interface {
10 foo(I)
11 }
12
13 type A struct{}
14
15 func (a A) foo(ai I) {}
16
17 type B struct{}
18
19 func (b B) foo(bi I) {}
20
21 func doWork() I { return nil }
22 func close() I { return nil }
23
24 func Baz(x B, h func() I, i I) I {
25 i.foo(x)
26
27 return h()
28 }
29
30 var g *B = &B{} // ensure *B.foo is created.
31
32 // Relevant SSA:
33 // func Baz(x B, h func() I, i I) I:
34 // t0 = make I <- B (x)
35 // t1 = invoke i.foo(t0)
36 // t2 = h()
37 // return t2
38
39 // Local(t0) has seemingly duplicates of successors. This
40 // happens in stringification of type propagation graph.
41 // Due to CHA, we analyze A.foo and *A.foo as well as B.foo
42 // and *B.foo, which have similar bodies and hence similar
43 // type flow that gets merged together during stringification.
44
45 // WANT:
46 // Return(doWork[0]) -> Local(t2)
47 // Return(close[0]) -> Local(t2)
48 // Local(t0) -> Local(ai), Local(ai), Local(bi), Local(bi)
49 // Constant(testdata.I) -> Return(close[0]), Return(doWork[0])
50 // Local(x) -> Local(t0)