1 | //go:build ignore |
---|---|
2 | // +build ignore |
3 | |
4 | package main |
5 | |
6 | // Demonstration of directionality of flow edges. |
7 | |
8 | func f1() {} |
9 | func f2() {} |
10 | |
11 | var somepred bool |
12 | |
13 | // Tracking functions. |
14 | func 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. |
29 | func 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 | |
43 | var g1, g2 int |
44 | |
45 | // Tracking addresses of globals. |
46 | func 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 | |
60 | func main() { |
61 | flow1() |
62 | flow2() |
63 | flow3() |
64 | } |
65 |
Members