GoPLS Viewer

Home|gopls/go/pointer/testdata/flow.go
1//go:build ignore
2// +build ignore
3
4package main
5
6// Demonstration of directionality of flow edges.
7
8func f1() {}
9func f2() {}
10
11var somepred bool
12
13// Tracking functions.
14func flow1() {
15    s := f1
16    p := f2
17    q := p
18    r := q
19    if somepred {
20        r = s
21    }
22    print(s// @pointsto command-line-arguments.f1
23    print(p// @pointsto command-line-arguments.f2
24    print(q// @pointsto command-line-arguments.f2
25    print(r// @pointsto command-line-arguments.f1 | command-line-arguments.f2
26}
27
28// Tracking concrete types in interfaces.
29func flow2() {
30    var s interface{} = 1
31    var p interface{} = "foo"
32    q := p
33    r := q
34    if somepred {
35        r = s
36    }
37    print(s// @types int
38    print(p// @types string
39    print(q// @types string
40    print(r// @types int | string
41}
42
43var g1g2 int
44
45// Tracking addresses of globals.
46func flow3() {
47    s := &g1
48    p := &g2
49    q := p
50    r := q
51    if somepred {
52        r = s
53    }
54    print(s// @pointsto command-line-arguments.g1
55    print(p// @pointsto command-line-arguments.g2
56    print(q// @pointsto command-line-arguments.g2
57    print(r// @pointsto command-line-arguments.g2 | command-line-arguments.g1
58}
59
60func main() {
61    flow1()
62    flow2()
63    flow3()
64}
65
MembersX
f1
f2
flow1.r
flow2
somepred
flow1.s
flow2.q
flow3
flow3.r
flow3.q
flow1.p
flow1.q
g1
g2
flow3.p
flow1
flow2.r
flow3.s
Members
X