1 // errorcheckwithauto -0 -l -live -wb=0 -d=ssa/insert_resched_checks/off
2 // +build !ppc64,!ppc64le,!goexperiment.regabiargs
4 // ppc64 needs a better tighten pass to make f18 pass
5 // rescheduling checks need to be turned off because there are some live variables across the inserted check call
7 // For register ABI, liveness info changes slightly. See live_regabi.go.
9 // Copyright 2014 The Go Authors. All rights reserved.
10 // Use of this source code is governed by a BSD-style
11 // license that can be found in the LICENSE file.
13 // liveness tests with inlining disabled.
21 func printpointer(**int)
24 func printintpointer(*int)
27 func printstringpointer(*string)
30 func printstring(string)
33 func printbytepointer(*byte)
38 var x *int // ERROR "stack object x \*int$"
39 printpointer(&x) // ERROR "live at call to printpointer: x$"
45 printint(0) // nothing live here
48 var x *int // ERROR "stack object x \*int$"
49 printpointer(&x) // ERROR "live at call to printpointer: x$"
53 func f3(b1, b2 bool) {
54 // Here x and y are ambiguously live. In previous go versions they
55 // were marked as live throughout the function to avoid being
56 // poisoned in GODEBUG=gcdead=1 mode; this is now no longer the
66 var x *int // ERROR "stack object x \*int$"
67 printpointer(&x) // ERROR "live at call to printpointer: x$"
70 var y *int // ERROR "stack object y \*int$"
71 printpointer(&y) // ERROR "live at call to printpointer: y$"
74 printint(0) // nothing is live here
77 // The old algorithm treated x as live on all code that
78 // could flow to a return statement, so it included the
79 // function entry and code above the declaration of x
80 // but would not include an indirect use of x in an infinite loop.
81 // Check that these cases are handled correctly.
83 func f4(b1, b2 bool) { // x not live here
85 printint(0) // x not live here
89 x := new(int) // ERROR "stack object x \*int$"
92 printint(**z) // ERROR "live at call to printint: x$"
94 printint(1) // x not live here
98 printint(**z) // ERROR "live at call to printint: x$"
105 x := new(int) // ERROR "stack object x \*int$"
109 y := new(int) // ERROR "stack object y \*int$"
113 printint(**z) // nothing live here
116 // confusion about the _ result used to cause spurious "live at entry to f6: _".
118 func f6() (_, y string) {
123 // confusion about addressed results used to cause "live at entry to f7: x".
125 func f7() (x string) { // ERROR "stack object x string"
131 // ignoring block returns used to cause "live at entry to f8: x, y".
133 func f8() (x, y string) {
137 func g8() (string, string)
139 // ignoring block assignments used to cause "live at entry to f9: x"
147 y := interface{}(g18()) // ERROR "live at call to convT: x.data$" "live at call to g18: x.data$" "stack object .autotmp_[0-9]+ \[2\]string$"
148 i9 = y // make y escape so the line above has to call convT
152 // liveness formerly confused by UNDEF followed by RET,
153 // leading to "live at entry to f10: ~r1" (unnamed result).
159 // liveness formerly confused by select, thinking runtime.selectgo
160 // can return to next instruction; it always jumps elsewhere.
161 // note that you have to use at least two cases in the select
162 // to get a true select; smaller selects compile to optimized helper functions.
167 // this used to have a spurious "live at entry to f11a: ~r0"
169 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]struct"
180 // At this point p is dead: the code here cannot
181 // get to the bottom of the function.
182 // This used to have a spurious "live at call to printint: p".
183 printint(1) // nothing live here!
184 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]struct"
199 sink = p // prevent stack allocation, otherwise p is rematerializeable
201 // Unlike previous, the cases in this select fall through,
202 // so we can get to the println, so p is not dead.
203 printint(1) // ERROR "live at call to printint: p$"
204 select { // ERROR "live at call to selectgo: p$" "stack object .autotmp_[0-9]+ \[2\]struct"
213 // similarly, select{} does not fall through.
214 // this used to have a spurious "live at entry to f12: ~r0".
224 // incorrectly placed VARDEF annotations can cause missing liveness annotations.
225 // this used to be missing the fact that s is live during the call to g13 (because it is
226 // needed for the call to h13).
230 s = h13(s, g13(s)) // ERROR "live at call to g13: s.ptr$"
233 func g13(string) string
234 func h13(string, string) string
236 // more incorrectly placed VARDEF.
239 x := g14() // ERROR "stack object x string$"
240 printstringpointer(&x)
245 // Checking that various temporaries do not persist or cause
246 // ambiguously live values that must be zeroed.
247 // The exact temporary names are inconsequential but we are
248 // trying to check that there is only one at any given site,
249 // and also that none show up in "ambiguously live" messages.
252 var mi map[interface{}]int
254 // str and iface are used to ensure that a temp is required for runtime calls below.
256 func iface() interface{}
260 delete(mi, iface()) // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
266 var m2s map[string]*byte
267 var m2 map[[2]string]*byte
271 func f17a(p *byte) { // ERROR "live at entry to f17a: p$"
273 m2[x2] = p // ERROR "live at call to mapassign: p$"
275 m2[x2] = p // ERROR "live at call to mapassign: p$"
276 m2[x2] = p // ERROR "live at call to mapassign: p$"
279 func f17b(p *byte) { // ERROR "live at entry to f17b: p$"
282 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
284 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
285 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
289 // key and value temporaries
291 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
293 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
294 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
302 // key temporary for mapaccess.
303 // temporary introduced by orderexpr.
306 z = m2[g18()] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
315 // byteptr is used to ensure that a temp is required for runtime calls below.
319 // dest temporary for channel receive.
323 z = <-ch // ERROR "stack object .autotmp_[0-9]+ \*byte$"
326 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
331 // src temporary for channel send
333 ch <- byteptr() // ERROR "stack object .autotmp_[0-9]+ \*byte$"
340 // key temporary for mapaccess using array literal key.
343 z = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
345 z = m2[[2]string{"x", "y"}]
346 z = m2[[2]string{"x", "y"}]
351 // key temporary for two-result map access using array literal key.
355 z, ok = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
357 z, ok = m2[[2]string{"x", "y"}]
358 z, ok = m2[[2]string{"x", "y"}]
364 // key temporary for map access using array literal key.
365 // value temporary too.
367 m2[[2]string{"x", "y"}] = nil // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
369 m2[[2]string{"x", "y"}] = nil
370 m2[[2]string{"x", "y"}] = nil
373 // Non-open-coded defers should not cause autotmps. (Open-coded defers do create extra autotmps).
375 for i := 0; i < 2; i++ {
376 // Put in loop to make sure defer is not open-coded
390 // non-escaping ... slices passed to function call should die on return,
391 // so that the temporaries do not stack and do not cause ambiguously
396 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "stack object .autotmp_[0-9]+ \[3\]interface \{\}$"
398 print26((*int)(nil), (*int)(nil), (*int)(nil))
399 print26((*int)(nil), (*int)(nil), (*int)(nil))
404 func print26(...interface{})
406 // non-escaping closures passed to function call should die on return
411 call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
413 call27(func() { x++ })
414 call27(func() { x++ })
418 // but defer does escape to later execution in the function
420 func f27defer(b bool) {
423 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
425 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
426 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ .autotmp_[0-9]+"
427 return // ERROR "live at indirect call: .autotmp_[0-9]+"
430 // and newproc (go) escapes to the heap
435 go call27(func() { x++ }) // ERROR "live at call to newobject: &x$" "live at call to newobject: &x .autotmp_[0-9]+$" "live at call to newproc: &x$" // allocate two closures, the func literal, and the wrapper for go
437 go call27(func() { x++ }) // ERROR "live at call to newobject: &x$" "live at call to newobject: .autotmp_[0-9]+$" // allocate two closures, the func literal, and the wrapper for go
444 // concatstring slice should die on return
446 var s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 string
450 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "stack object .autotmp_[0-9]+ \[10\]string$"
452 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
453 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
456 // map iterator should die on end of range loop
460 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$"
461 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]+$"
467 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$"
468 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
472 // copy of array of pointers should die at end of range loop
473 var pstructarr [10]pstruct
475 // Struct size chosen to make pointer to element in pstructarr
476 // not computable by strength reduction.
477 type pstruct struct {
483 // live temp during printintpointer(p):
484 // the internal iterator pointer if a pointer to pstruct in pstructarr
485 // can not be easily computed by strength reduction.
487 for _, p := range pstructarr { // ERROR "stack object .autotmp_[0-9]+ \[10\]pstruct$"
488 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]+$"
494 for _, p := range pstructarr {
495 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
499 // conversion to interface should not leave temporary behind
501 func f31(b1, b2, b3 bool) {
503 g31(g18()) // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
506 h31(g18()) // ERROR "live at call to convT: .autotmp_[0-9]+$" "live at call to newobject: .autotmp_[0-9]+$"
514 func g31(interface{})
515 func h31(...interface{})
517 // non-escaping partial functions passed to function call should die on return
521 func (t *T32) Inc() { // ERROR "live at entry to \(\*T32\).Inc: t$"
529 call32(t32.Inc) // ERROR "stack object .autotmp_[0-9]+ struct \{"
538 // temporaries introduced during if conditions and && || expressions
539 // should die once the condition has been acted upon.
541 var m33 map[interface{}]int
544 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
554 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
562 if m33[byteptr()] == 0 && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
563 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
571 if m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
572 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
580 if (m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
581 m33[byteptr()] == 0) && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
582 m33[byteptr()] == 0 {
589 // select temps should disappear in the case bodies
593 func fc38() chan string
594 func fi38(int) *string
598 // we don't care what temps are printed on the lines with output.
599 // we care that the println lines have no live variables
600 // and therefore no output.
602 select { // ERROR "live at call to selectgo:( .autotmp_[0-9]+)+$" "stack object .autotmp_[0-9]+ \[4\]struct \{"
605 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$"
607 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$"
609 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]+)+$"
617 // issue 8097: mishandling of x = x during return.
619 func f39() (x []int) {
621 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
625 func f39a() (x []int) {
627 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
631 func f39b() (x [10]*int) {
633 x[0] = new(int) // ERROR "live at call to newobject: x$"
634 printnl() // ERROR "live at call to printnl: x$"
638 func f39c() (x [10]*int) {
640 x[0] = new(int) // ERROR "live at call to newobject: x$"
641 printnl() // ERROR "live at call to printnl: x$"
645 // issue 8142: lost 'addrtaken' bit on inlined variables.
646 // no inlining in this test, so just checking that non-inlined works.
657 ret.m = make(map[int]int, 42) // ERROR "live at call to makemap: &ret$"
668 ret := T40{} // ERROR "stack object ret T40$"
669 ret.m = make(map[int]int) // ERROR "live at call to fastrand: .autotmp_[0-9]+$" "stack object .autotmp_[0-9]+ map.hdr\[int\]int$"
671 printnl() // ERROR "live at call to printnl: ret$"
672 // Note: ret is live at the printnl because the compiler moves &ret
673 // from before the printnl to after.
677 func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"
678 ddd2(x, y) // ERROR "stack object .autotmp_[0-9]+ \[2\]\*int$"
680 // Note: no .?autotmp live at printnl. See issue 16996.
682 func ddd2(a ...*int) { // ERROR "live at entry to ddd2: a$"
686 // issue 16016: autogenerated wrapper should have arguments live
689 func (*T) Foo(ptr *int) {}
693 // issue 18860: output arguments must be live all the time if there is a defer.
694 // In particular, at printint r must be live.
695 func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
700 printint(0) // ERROR "live at call to printint: q r .autotmp_[0-9]+$"
702 return // ERROR "live at call to f41.func1: r .autotmp_[0-9]+$"
707 f43([]*int{&p, &q, &r}) // ERROR "stack object .autotmp_[0-9]+ \[3\]\*int$"
708 f43([]*int{&p, &r, &q})
709 f43([]*int{&q, &p, &r})
715 // Assigning to a sub-element that makes up an entire local variable
716 // should clobber that variable.
717 func f44(f func() [2]*int) interface{} { // ERROR "live at entry to f44: f"
723 return ret // ERROR "stack object .autotmp_[0-9]+ T"