github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gotools/go/ssa/testdata/valueforexpr.go (about) 1 //+build ignore 2 3 package main 4 5 // This file is the input to TestValueForExpr in source_test.go, which 6 // ensures that each expression e immediately following a /*@kind*/(x) 7 // annotation, when passed to Function.ValueForExpr(e), returns a 8 // non-nil Value of the same type as e and of kind 'kind'. 9 10 func f(spilled, unspilled int) { 11 _ = /*@UnOp*/ (spilled) 12 _ = /*@Parameter*/ (unspilled) 13 _ = /*@<nil>*/ (1 + 2) // (constant) 14 i := 0 15 /*@Call*/ (print( /*@BinOp*/ (i + 1))) 16 ch := /*@MakeChan*/ (make(chan int)) 17 /*@UnOp*/ (<-ch) 18 x := /*@UnOp*/ (<-ch) 19 _ = x 20 select { 21 case /*@Extract*/ (<-ch): 22 case x := /*@Extract*/ (<-ch): 23 _ = x 24 } 25 defer /*@Function*/ (func() { 26 })() 27 go /*@Function*/ (func() { 28 })() 29 y := 0 30 if true && /*@BinOp*/ (bool(y > 0)) { 31 y = 1 32 } 33 _ = /*@Phi*/ (y) 34 map1 := /*@MakeMap*/ (make(map[string]string)) 35 _ = map1 36 _ = /*@Slice*/ (make([]int, 0)) 37 _ = /*@MakeClosure*/ (func() { print(spilled) }) 38 39 sl := []int{} 40 _ = /*@Slice*/ (sl[:0]) 41 42 _ = /*@<nil>*/ (new(int)) // optimized away 43 tmp := /*@Alloc*/ (new(int)) 44 _ = tmp 45 var iface interface{} 46 _ = /*@TypeAssert*/ (iface.(int)) 47 _ = /*@UnOp*/ (sl[0]) 48 _ = /*@IndexAddr*/ (&sl[0]) 49 _ = /*@Index*/ ([2]int{}[0]) 50 var p *int 51 _ = /*@UnOp*/ (*p) 52 53 _ = /*@UnOp*/ (global) 54 /*@UnOp*/ (global)[""] = "" 55 /*@Global*/ (global) = map[string]string{} 56 57 var local t 58 /*UnOp*/ (local.x) = 1 59 60 // Exercise corner-cases of lvalues vs rvalues. 61 type N *N 62 var n N 63 /*@UnOp*/ (n) = /*@UnOp*/ (n) 64 /*@ChangeType*/ (n) = /*@Alloc*/ (&n) 65 /*@UnOp*/ (n) = /*@UnOp*/ (*n) 66 /*@UnOp*/ (n) = /*@UnOp*/ (**n) 67 } 68 69 func complit() { 70 // Composite literals. 71 // We get different results for 72 // - composite literal as value (e.g. operand to print) 73 // - composite literal initializer for addressable value 74 // - composite literal value assigned to blank var 75 76 // 1. Slices 77 print( /*@Slice*/ ([]int{})) 78 print( /*@Alloc*/ (&[]int{})) 79 print(& /*@Slice*/ ([]int{})) 80 81 sl1 := /*@Slice*/ ([]int{}) 82 sl2 := /*@Alloc*/ (&[]int{}) 83 sl3 := & /*@Slice*/ ([]int{}) 84 _, _, _ = sl1, sl2, sl3 85 86 _ = /*@Slice*/ ([]int{}) 87 _ = /*@<nil>*/ (& /*@Slice*/ ([]int{})) // & optimized away 88 _ = & /*@Slice*/ ([]int{}) 89 90 // 2. Arrays 91 print( /*@UnOp*/ ([1]int{})) 92 print( /*@Alloc*/ (&[1]int{})) 93 print(& /*@Alloc*/ ([1]int{})) 94 95 arr1 := /*@Alloc*/ ([1]int{}) 96 arr2 := /*@Alloc*/ (&[1]int{}) 97 arr3 := & /*@Alloc*/ ([1]int{}) 98 _, _, _ = arr1, arr2, arr3 99 100 _ = /*@UnOp*/ ([1]int{}) 101 _ = /*@Alloc*/ (& /*@Alloc*/ ([1]int{})) 102 _ = & /*@Alloc*/ ([1]int{}) 103 104 // 3. Maps 105 type M map[int]int 106 print( /*@MakeMap*/ (M{})) 107 print( /*@Alloc*/ (&M{})) 108 print(& /*@MakeMap*/ (M{})) 109 110 m1 := /*@MakeMap*/ (M{}) 111 m2 := /*@Alloc*/ (&M{}) 112 m3 := & /*@MakeMap*/ (M{}) 113 _, _, _ = m1, m2, m3 114 115 _ = /*@MakeMap*/ (M{}) 116 _ = /*@<nil>*/ (& /*@MakeMap*/ (M{})) // & optimized away 117 _ = & /*@MakeMap*/ (M{}) 118 119 // 4. Structs 120 print( /*@UnOp*/ (struct{}{})) 121 print( /*@Alloc*/ (&struct{}{})) 122 print(& /*@Alloc*/ (struct{}{})) 123 124 s1 := /*@Alloc*/ (struct{}{}) 125 s2 := /*@Alloc*/ (&struct{}{}) 126 s3 := & /*@Alloc*/ (struct{}{}) 127 _, _, _ = s1, s2, s3 128 129 _ = /*@UnOp*/ (struct{}{}) 130 _ = /*@Alloc*/ (& /*@Alloc*/ (struct{}{})) 131 _ = & /*@Alloc*/ (struct{}{}) 132 } 133 134 type t struct{ x int } 135 136 // Ensure we can locate methods of named types. 137 func (t) f(param int) { 138 _ = /*@Parameter*/ (param) 139 } 140 141 // Ensure we can locate init functions. 142 func init() { 143 m := /*@MakeMap*/ (make(map[string]string)) 144 _ = m 145 } 146 147 // Ensure we can locate variables in initializer expressions. 148 var global = /*@MakeMap*/ (make(map[string]string))