1 // errorcheckwithauto -0 -l -live -wb=0 -d=ssa/insert_resched_checks/off
2 // +build !ppc64,!ppc64le
3 // ppc64 needs a better tighten pass to make f18 pass
4 // rescheduling checks need to be turned off because there are some live variables across the inserted check call
6 // Copyright 2014 The Go Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style
8 // license that can be found in the LICENSE file.
10 // liveness tests with inlining disabled.
18 func printpointer(**int)
21 func printintpointer(*int)
24 func printstringpointer(*string)
27 func printstring(string)
30 func printbytepointer(*byte)
35 var x *int // ERROR "stack object x \*int$"
36 printpointer(&x) // ERROR "live at call to printpointer: x$"
42 printint(0) // nothing live here
45 var x *int // ERROR "stack object x \*int$"
46 printpointer(&x) // ERROR "live at call to printpointer: x$"
50 func f3(b1, b2 bool) {
51 // Here x and y are ambiguously live. In previous go versions they
52 // were marked as live throughout the function to avoid being
53 // poisoned in GODEBUG=gcdead=1 mode; this is now no longer the
63 var x *int // ERROR "stack object x \*int$"
64 printpointer(&x) // ERROR "live at call to printpointer: x$"
67 var y *int // ERROR "stack object y \*int$"
68 printpointer(&y) // ERROR "live at call to printpointer: y$"
71 printint(0) // nothing is live here
74 // The old algorithm treated x as live on all code that
75 // could flow to a return statement, so it included the
76 // function entry and code above the declaration of x
77 // but would not include an indirect use of x in an infinite loop.
78 // Check that these cases are handled correctly.
80 func f4(b1, b2 bool) { // x not live here
82 printint(0) // x not live here
86 x := new(int) // ERROR "stack object x \*int$"
89 printint(**z) // ERROR "live at call to printint: x$"
91 printint(1) // x not live here
95 printint(**z) // ERROR "live at call to printint: x$"
102 x := new(int) // ERROR "stack object x \*int$"
106 y := new(int) // ERROR "stack object y \*int$"
110 printint(**z) // nothing live here
113 // confusion about the _ result used to cause spurious "live at entry to f6: _".
115 func f6() (_, y string) {
120 // confusion about addressed results used to cause "live at entry to f7: x".
122 func f7() (x string) { // ERROR "stack object x string"
128 // ignoring block returns used to cause "live at entry to f8: x, y".
130 func f8() (x, y string) {
134 func g8() (string, string)
136 // ignoring block assignments used to cause "live at entry to f9: x"
144 y := interface{}(g18()) // ERROR "live at call to convT2E: x.data$" "live at call to g18: x.data$" "stack object .autotmp_[0-9]+ \[2\]string$"
145 i9 = y // make y escape so the line above has to call convT2E
149 // liveness formerly confused by UNDEF followed by RET,
150 // leading to "live at entry to f10: ~r1" (unnamed result).
156 // liveness formerly confused by select, thinking runtime.selectgo
157 // can return to next instruction; it always jumps elsewhere.
158 // note that you have to use at least two cases in the select
159 // to get a true select; smaller selects compile to optimized helper functions.
164 // this used to have a spurious "live at entry to f11a: ~r0"
166 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]struct"
177 // At this point p is dead: the code here cannot
178 // get to the bottom of the function.
179 // This used to have a spurious "live at call to printint: p".
180 printint(1) // nothing live here!
181 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]struct"
196 sink = p // prevent stack allocation, otherwise p is rematerializeable
198 // Unlike previous, the cases in this select fall through,
199 // so we can get to the println, so p is not dead.
200 printint(1) // ERROR "live at call to printint: p$"
201 select { // ERROR "live at call to selectgo: p$" "stack object .autotmp_[0-9]+ \[2\]struct"
210 // similarly, select{} does not fall through.
211 // this used to have a spurious "live at entry to f12: ~r0".
221 // incorrectly placed VARDEF annotations can cause missing liveness annotations.
222 // this used to be missing the fact that s is live during the call to g13 (because it is
223 // needed for the call to h13).
227 s = h13(s, g13(s)) // ERROR "live at call to g13: s.ptr$"
230 func g13(string) string
231 func h13(string, string) string
233 // more incorrectly placed VARDEF.
236 x := g14() // ERROR "stack object x string$"
237 printstringpointer(&x)
242 // Checking that various temporaries do not persist or cause
243 // ambiguously live values that must be zeroed.
244 // The exact temporary names are inconsequential but we are
245 // trying to check that there is only one at any given site,
246 // and also that none show up in "ambiguously live" messages.
249 var mi map[interface{}]int
251 // str and iface are used to ensure that a temp is required for runtime calls below.
253 func iface() interface{}
257 delete(mi, iface()) // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
263 var m2s map[string]*byte
264 var m2 map[[2]string]*byte
268 func f17a(p *byte) { // ERROR "live at entry to f17a: p$"
270 m2[x2] = p // ERROR "live at call to mapassign: p$"
272 m2[x2] = p // ERROR "live at call to mapassign: p$"
273 m2[x2] = p // ERROR "live at call to mapassign: p$"
276 func f17b(p *byte) { // ERROR "live at entry to f17b: p$"
279 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
281 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
282 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
286 // key and value temporaries
288 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
290 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
291 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
299 // key temporary for mapaccess.
300 // temporary introduced by orderexpr.
303 z = m2[g18()] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
312 // byteptr is used to ensure that a temp is required for runtime calls below.
316 // dest temporary for channel receive.
320 z = <-ch // ERROR "stack object .autotmp_[0-9]+ \*byte$"
323 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
328 // src temporary for channel send
330 ch <- byteptr() // ERROR "stack object .autotmp_[0-9]+ \*byte$"
337 // key temporary for mapaccess using array literal key.
340 z = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
342 z = m2[[2]string{"x", "y"}]
343 z = m2[[2]string{"x", "y"}]
348 // key temporary for two-result map access using array literal key.
352 z, ok = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
354 z, ok = m2[[2]string{"x", "y"}]
355 z, ok = m2[[2]string{"x", "y"}]
361 // key temporary for map access using array literal key.
362 // value temporary too.
364 m2[[2]string{"x", "y"}] = nil // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
366 m2[[2]string{"x", "y"}] = nil
367 m2[[2]string{"x", "y"}] = nil
370 // Non-open-coded defers should not cause autotmps. (Open-coded defers do create extra autotmps).
372 for i := 0; i < 2; i++ {
373 // Put in loop to make sure defer is not open-coded
387 // non-escaping ... slices passed to function call should die on return,
388 // so that the temporaries do not stack and do not cause ambiguously
393 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "stack object .autotmp_[0-9]+ \[3\]interface \{\}$"
395 print26((*int)(nil), (*int)(nil), (*int)(nil))
396 print26((*int)(nil), (*int)(nil), (*int)(nil))
401 func print26(...interface{})
403 // non-escaping closures passed to function call should die on return
408 call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
410 call27(func() { x++ })
411 call27(func() { x++ })
415 // but defer does escape to later execution in the function
417 func f27defer(b bool) {
420 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
422 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
423 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ .autotmp_[0-9]+"
424 return // ERROR "live at call to call27: .autotmp_[0-9]+"
427 // and newproc (go) escapes to the heap
432 go call27(func() { x++ }) // ERROR "live at call to newobject: &x$" "live at call to newproc: &x$"
434 go call27(func() { x++ }) // ERROR "live at call to newobject: &x$"
441 // concatstring slice should die on return
443 var s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 string
447 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "stack object .autotmp_[0-9]+ \[10\]string$"
449 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
450 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
453 // map iterator should die on end of range loop
457 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$" "stack object .autotmp_[0-9]+ map.iter\[string\]int$"
458 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
461 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$"
462 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
464 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$"
465 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
469 // copy of array of pointers should die at end of range loop
470 var pstructarr [10]pstruct
472 // Struct size chosen to make pointer to element in pstructarr
473 // not computable by strength reduction.
474 type pstruct struct {
480 // live temp during printintpointer(p):
481 // the internal iterator pointer if a pointer to pstruct in pstructarr
482 // can not be easily computed by strength reduction.
484 for _, p := range pstructarr { // ERROR "stack object .autotmp_[0-9]+ \[10\]pstruct$"
485 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
488 for _, p := range pstructarr {
489 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
491 for _, p := range pstructarr {
492 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
496 // conversion to interface should not leave temporary behind
498 func f31(b1, b2, b3 bool) {
500 g31(g18()) // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
503 h31(g18()) // ERROR "live at call to convT2E: .autotmp_[0-9]+$" "live at call to newobject: .autotmp_[0-9]+$"
511 func g31(interface{})
512 func h31(...interface{})
514 // non-escaping partial functions passed to function call should die on return
518 func (t *T32) Inc() { // ERROR "live at entry to \(\*T32\).Inc: t$"
526 call32(t32.Inc) // ERROR "stack object .autotmp_[0-9]+ struct \{"
535 // temporaries introduced during if conditions and && || expressions
536 // should die once the condition has been acted upon.
538 var m33 map[interface{}]int
541 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
551 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
559 if m33[byteptr()] == 0 && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
560 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
568 if m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
569 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
577 if (m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
578 m33[byteptr()] == 0) && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
579 m33[byteptr()] == 0 {
586 // select temps should disappear in the case bodies
590 func fc38() chan string
591 func fi38(int) *string
595 // we don't care what temps are printed on the lines with output.
596 // we care that the println lines have no live variables
597 // and therefore no output.
599 select { // ERROR "live at call to selectgo:( .autotmp_[0-9]+)+$" "stack object .autotmp_[0-9]+ \[4\]struct \{"
602 case fc38() <- *fi38(1): // ERROR "live at call to fc38:( .autotmp_[0-9]+)+$" "live at call to fi38:( .autotmp_[0-9]+)+$" "stack object .autotmp_[0-9]+ string$"
604 case *fi38(2) = <-fc38(): // ERROR "live at call to fc38:( .autotmp_[0-9]+)+$" "live at call to fi38:( .autotmp_[0-9]+)+$" "stack object .autotmp_[0-9]+ string$"
606 case *fi38(3), *fb38() = <-fc38(): // ERROR "stack object .autotmp_[0-9]+ string$" "live at call to fc38:( .autotmp_[0-9]+)+$" "live at call to fi38:( .autotmp_[0-9]+)+$"
614 // issue 8097: mishandling of x = x during return.
616 func f39() (x []int) {
618 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
622 func f39a() (x []int) {
624 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
628 func f39b() (x [10]*int) {
630 x[0] = new(int) // ERROR "live at call to newobject: x$"
631 printnl() // ERROR "live at call to printnl: x$"
635 func f39c() (x [10]*int) {
637 x[0] = new(int) // ERROR "live at call to newobject: x$"
638 printnl() // ERROR "live at call to printnl: x$"
642 // issue 8142: lost 'addrtaken' bit on inlined variables.
643 // no inlining in this test, so just checking that non-inlined works.
654 ret.m = make(map[int]int, 42) // ERROR "live at call to makemap: &ret$"
665 ret := T40{} // ERROR "stack object ret T40$"
666 ret.m = make(map[int]int) // ERROR "live at call to fastrand: .autotmp_[0-9]+$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
668 printnl() // ERROR "live at call to printnl: ret$"
669 // Note: ret is live at the printnl because the compiler moves &ret
670 // from before the printnl to after.
674 func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"
675 ddd2(x, y) // ERROR "stack object .autotmp_[0-9]+ \[2\]\*int$"
677 // Note: no .?autotmp live at printnl. See issue 16996.
679 func ddd2(a ...*int) { // ERROR "live at entry to ddd2: a$"
683 // issue 16016: autogenerated wrapper should have arguments live
686 func (*T) Foo(ptr *int) {}
688 type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "live at entry to R\.Foo: \.this ptr"
690 // issue 18860: output arguments must be live all the time if there is a defer.
691 // In particular, at printint r must be live.
692 func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
697 printint(0) // ERROR "live at call to printint: q r .autotmp_[0-9]+$"
699 return // ERROR "live at call to f41.func1: r .autotmp_[0-9]+$"
704 f43([]*int{&p, &q, &r}) // ERROR "stack object .autotmp_[0-9]+ \[3\]\*int$"
705 f43([]*int{&p, &r, &q})
706 f43([]*int{&q, &p, &r})
712 // Assigning to a sub-element that makes up an entire local variable
713 // should clobber that variable.
714 func f44(f func() [2]*int) interface{} { // ERROR "live at entry to f44: f"
720 return ret // ERROR "stack object .autotmp_5 T"