1// Copyright 2023 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// DO NOT EDIT (use 'go test -v -update-expected' instead.)
6// See cmd/compile/internal/inline/inlheur/testdata/props/README.txt
7// for more information on the format of this file.
8// <endfilepreamble>
9
10package returns1
11
12import "unsafe"
13
14// returns.go T_simple_allocmem 21 0 1
15// ResultFlags
16//   0 ResultIsAllocatedMem
17// <endpropsdump>
18// {"Flags":0,"ParamFlags":null,"ResultFlags":[2]}
19// <endcallsites>
20// <endfuncpreamble>
21func T_simple_allocmem() *Bar {
22	return &Bar{}
23}
24
25// returns.go T_allocmem_two_returns 34 0 1
26// ParamFlags
27//   0 ParamFeedsIfOrSwitch
28// ResultFlags
29//   0 ResultIsAllocatedMem
30// <endpropsdump>
31// {"Flags":0,"ParamFlags":[32],"ResultFlags":[2]}
32// <endcallsites>
33// <endfuncpreamble>
34func T_allocmem_two_returns(x int) *Bar {
35	// multiple returns
36	if x < 0 {
37		return new(Bar)
38	} else {
39		return &Bar{x: 2}
40	}
41}
42
43// returns.go T_allocmem_three_returns 52 0 1
44// ParamFlags
45//   0 ParamFeedsIfOrSwitch
46// ResultFlags
47//   0 ResultIsAllocatedMem
48// <endpropsdump>
49// {"Flags":0,"ParamFlags":[32],"ResultFlags":[2]}
50// <endcallsites>
51// <endfuncpreamble>
52func T_allocmem_three_returns(x int) []*Bar {
53	// more multiple returns
54	switch x {
55	case 10, 11, 12:
56		return make([]*Bar, 10)
57	case 13:
58		fallthrough
59	case 15:
60		return []*Bar{&Bar{x: 15}}
61	}
62	return make([]*Bar, 0, 10)
63}
64
65// returns.go T_return_nil 72 0 1
66// ResultFlags
67//   0 ResultAlwaysSameConstant
68// <endpropsdump>
69// {"Flags":0,"ParamFlags":null,"ResultFlags":[8]}
70// <endcallsites>
71// <endfuncpreamble>
72func T_return_nil() *Bar {
73	// simple case: no alloc
74	return nil
75}
76
77// returns.go T_multi_return_nil 84 0 1
78// ResultFlags
79//   0 ResultAlwaysSameConstant
80// <endpropsdump>
81// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[8]}
82// <endcallsites>
83// <endfuncpreamble>
84func T_multi_return_nil(x, y bool) *Bar {
85	if x && y {
86		return nil
87	}
88	return nil
89}
90
91// returns.go T_multi_return_nil_anomoly 98 0 1
92// ResultFlags
93//   0 ResultIsConcreteTypeConvertedToInterface
94// <endpropsdump>
95// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[4]}
96// <endcallsites>
97// <endfuncpreamble>
98func T_multi_return_nil_anomoly(x, y bool) Itf {
99	if x && y {
100		var qnil *Q
101		return qnil
102	}
103	var barnil *Bar
104	return barnil
105}
106
107// returns.go T_multi_return_some_nil 112 0 1
108// <endpropsdump>
109// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[0]}
110// <endcallsites>
111// <endfuncpreamble>
112func T_multi_return_some_nil(x, y bool) *Bar {
113	if x && y {
114		return nil
115	} else {
116		return &GB
117	}
118}
119
120// returns.go T_mixed_returns 127 0 1
121// ParamFlags
122//   0 ParamFeedsIfOrSwitch
123// <endpropsdump>
124// {"Flags":0,"ParamFlags":[32],"ResultFlags":[0]}
125// <endcallsites>
126// <endfuncpreamble>
127func T_mixed_returns(x int) *Bar {
128	// mix of alloc and non-alloc
129	if x < 0 {
130		return new(Bar)
131	} else {
132		return &GB
133	}
134}
135
136// returns.go T_mixed_returns_slice 143 0 1
137// ParamFlags
138//   0 ParamFeedsIfOrSwitch
139// <endpropsdump>
140// {"Flags":0,"ParamFlags":[32],"ResultFlags":[0]}
141// <endcallsites>
142// <endfuncpreamble>
143func T_mixed_returns_slice(x int) []*Bar {
144	// mix of alloc and non-alloc
145	switch x {
146	case 10, 11, 12:
147		return make([]*Bar, 10)
148	case 13:
149		fallthrough
150	case 15:
151		return []*Bar{&Bar{x: 15}}
152	}
153	ba := [...]*Bar{&GB, &GB}
154	return ba[:]
155}
156
157// returns.go T_maps_and_channels 167 0 1
158// ResultFlags
159//   0 ResultNoInfo
160//   1 ResultNoInfo
161//   2 ResultNoInfo
162//   3 ResultAlwaysSameConstant
163// <endpropsdump>
164// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[0,0,0,8]}
165// <endcallsites>
166// <endfuncpreamble>
167func T_maps_and_channels(x int, b bool) (bool, map[int]int, chan bool, unsafe.Pointer) {
168	// maps and channels
169	return b, make(map[int]int), make(chan bool), nil
170}
171
172// returns.go T_assignment_to_named_returns 179 0 1
173// ParamFlags
174//   0 ParamFeedsIfOrSwitch
175// <endpropsdump>
176// {"Flags":0,"ParamFlags":[32],"ResultFlags":[0,0]}
177// <endcallsites>
178// <endfuncpreamble>
179func T_assignment_to_named_returns(x int) (r1 *uint64, r2 *uint64) {
180	// assignments to named returns and then "return" not supported
181	r1 = new(uint64)
182	if x < 1 {
183		*r1 = 2
184	}
185	r2 = new(uint64)
186	return
187}
188
189// returns.go T_named_returns_but_return_explicit_values 199 0 1
190// ParamFlags
191//   0 ParamFeedsIfOrSwitch
192// ResultFlags
193//   0 ResultIsAllocatedMem
194//   1 ResultIsAllocatedMem
195// <endpropsdump>
196// {"Flags":0,"ParamFlags":[32],"ResultFlags":[2,2]}
197// <endcallsites>
198// <endfuncpreamble>
199func T_named_returns_but_return_explicit_values(x int) (r1 *uint64, r2 *uint64) {
200	// named returns ok if all returns are non-empty
201	rx1 := new(uint64)
202	if x < 1 {
203		*rx1 = 2
204	}
205	rx2 := new(uint64)
206	return rx1, rx2
207}
208
209// returns.go T_return_concrete_type_to_itf 216 0 1
210// ResultFlags
211//   0 ResultIsConcreteTypeConvertedToInterface
212// <endpropsdump>
213// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[4]}
214// <endcallsites>
215// <endfuncpreamble>
216func T_return_concrete_type_to_itf(x, y int) Itf {
217	return &Bar{}
218}
219
220// returns.go T_return_concrete_type_to_itfwith_copy 227 0 1
221// ResultFlags
222//   0 ResultIsConcreteTypeConvertedToInterface
223// <endpropsdump>
224// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[4]}
225// <endcallsites>
226// <endfuncpreamble>
227func T_return_concrete_type_to_itfwith_copy(x, y int) Itf {
228	b := &Bar{}
229	println("whee")
230	return b
231}
232
233// returns.go T_return_concrete_type_to_itf_mixed 238 0 1
234// <endpropsdump>
235// {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[0]}
236// <endcallsites>
237// <endfuncpreamble>
238func T_return_concrete_type_to_itf_mixed(x, y int) Itf {
239	if x < y {
240		b := &Bar{}
241		return b
242	}
243	return nil
244}
245
246// returns.go T_return_same_func 253 0 1
247// ResultFlags
248//   0 ResultAlwaysSameInlinableFunc
249// <endpropsdump>
250// {"Flags":0,"ParamFlags":null,"ResultFlags":[32]}
251// <endcallsites>
252// <endfuncpreamble>
253func T_return_same_func() func(int) int {
254	if G < 10 {
255		return foo
256	} else {
257		return foo
258	}
259}
260
261// returns.go T_return_different_funcs 266 0 1
262// <endpropsdump>
263// {"Flags":0,"ParamFlags":null,"ResultFlags":[0]}
264// <endcallsites>
265// <endfuncpreamble>
266func T_return_different_funcs() func(int) int {
267	if G != 10 {
268		return foo
269	} else {
270		return bar
271	}
272}
273
274// returns.go T_return_same_closure 286 0 1
275// ResultFlags
276//   0 ResultAlwaysSameInlinableFunc
277// <endpropsdump>
278// {"Flags":0,"ParamFlags":null,"ResultFlags":[32]}
279// <endcallsites>
280// <endfuncpreamble>
281// returns.go T_return_same_closure.func1 287 0 1
282// <endpropsdump>
283// {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
284// <endcallsites>
285// <endfuncpreamble>
286func T_return_same_closure() func(int) int {
287	p := func(q int) int { return q }
288	if G < 10 {
289		return p
290	} else {
291		return p
292	}
293}
294
295// returns.go T_return_different_closures 312 0 1
296// <endpropsdump>
297// {"Flags":0,"ParamFlags":null,"ResultFlags":[0]}
298// <endcallsites>
299// <endfuncpreamble>
300// returns.go T_return_different_closures.func1 313 0 1
301// <endpropsdump>
302// {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
303// <endcallsites>
304// <endfuncpreamble>
305// returns.go T_return_different_closures.func2 317 0 1
306// ResultFlags
307//   0 ResultAlwaysSameConstant
308// <endpropsdump>
309// {"Flags":0,"ParamFlags":[0],"ResultFlags":[8]}
310// <endcallsites>
311// <endfuncpreamble>
312func T_return_different_closures() func(int) int {
313	p := func(q int) int { return q }
314	if G < 10 {
315		return p
316	} else {
317		return func(q int) int { return 101 }
318	}
319}
320
321// returns.go T_return_noninlinable 339 0 1
322// ResultFlags
323//   0 ResultAlwaysSameFunc
324// <endpropsdump>
325// {"Flags":0,"ParamFlags":[0],"ResultFlags":[16]}
326// <endcallsites>
327// <endfuncpreamble>
328// returns.go T_return_noninlinable.func1 340 0 1
329// <endpropsdump>
330// {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
331// callsite: returns.go:343:4|0 flagstr "" flagval 0 score 4 mask 0 maskstr ""
332// <endcallsites>
333// <endfuncpreamble>
334// returns.go T_return_noninlinable.func1.1 341 0 1
335// <endpropsdump>
336// {"Flags":0,"ParamFlags":null,"ResultFlags":null}
337// <endcallsites>
338// <endfuncpreamble>
339func T_return_noninlinable(x int) func(int) int {
340	noti := func(q int) int {
341		defer func() {
342			println(q + x)
343		}()
344		return q
345	}
346	return noti
347}
348
349type Bar struct {
350	x int
351	y string
352}
353
354func (b *Bar) Plark() {
355}
356
357type Q int
358
359func (q *Q) Plark() {
360}
361
362func foo(x int) int { return x }
363func bar(x int) int { return -x }
364
365var G int
366var GB Bar
367
368type Itf interface {
369	Plark()
370}
371