Debian Codegraph @

go/ssa/testdata/valueforexpr.go

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