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