1 // errorcheckwithauto -0 -l -live -wb=0 -d=ssa/insert_resched_checks/off
2 //go:build !ppc64 && !ppc64le && !goexperiment.regabiargs
3 // +build !ppc64,!ppc64le,!goexperiment.regabiargs
5 // ppc64 needs a better tighten pass to make f18 pass
6 // rescheduling checks need to be turned off because there are some live variables across the inserted check call
8 // For register ABI, liveness info changes slightly. See live_regabi.go.
10 // Copyright 2014 The Go Authors. All rights reserved.
11 // Use of this source code is governed by a BSD-style
12 // license that can be found in the LICENSE file.
14 // liveness tests with inlining disabled.
22 func printpointer(**int)
25 func printintpointer(*int)
28 func printstringpointer(*string)
31 func printstring(string)
34 func printbytepointer(*byte)
39 var x *int // ERROR "stack object x \*int$"
40 printpointer(&x) // ERROR "live at call to printpointer: x$"
46 printint(0) // nothing live here
49 var x *int // ERROR "stack object x \*int$"
50 printpointer(&x) // ERROR "live at call to printpointer: x$"
54 func f3(b1, b2 bool) {
55 // Here x and y are ambiguously live. In previous go versions they
56 // were marked as live throughout the function to avoid being
57 // poisoned in GODEBUG=gcdead=1 mode; this is now no longer the
67 var x *int // ERROR "stack object x \*int$"
68 printpointer(&x) // ERROR "live at call to printpointer: x$"
71 var y *int // ERROR "stack object y \*int$"
72 printpointer(&y) // ERROR "live at call to printpointer: y$"
75 printint(0) // nothing is live here
78 // The old algorithm treated x as live on all code that
79 // could flow to a return statement, so it included the
80 // function entry and code above the declaration of x
81 // but would not include an indirect use of x in an infinite loop.
82 // Check that these cases are handled correctly.
84 func f4(b1, b2 bool) { // x not live here
86 printint(0) // x not live here
90 x := new(int) // ERROR "stack object x \*int$"
93 printint(**z) // ERROR "live at call to printint: x$"
95 printint(1) // x not live here
99 printint(**z) // ERROR "live at call to printint: x$"
106 x := new(int) // ERROR "stack object x \*int$"
110 y := new(int) // ERROR "stack object y \*int$"
114 printint(**z) // nothing live here
117 // confusion about the _ result used to cause spurious "live at entry to f6: _".
119 func f6() (_, y string) {
124 // confusion about addressed results used to cause "live at entry to f7: x".
126 func f7() (x string) { // ERROR "stack object x string"
132 // ignoring block returns used to cause "live at entry to f8: x, y".
134 func f8() (x, y string) {
138 func g8() (string, string)
140 // ignoring block assignments used to cause "live at entry to f9: x"
148 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$"
149 i9 = y // make y escape so the line above has to call convT
153 // liveness formerly confused by UNDEF followed by RET,
154 // leading to "live at entry to f10: ~r1" (unnamed result).
160 // liveness formerly confused by select, thinking runtime.selectgo
161 // can return to next instruction; it always jumps elsewhere.
162 // note that you have to use at least two cases in the select
163 // to get a true select; smaller selects compile to optimized helper functions.
168 // this used to have a spurious "live at entry to f11a: ~r0"
170 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]runtime.scase$"
181 // At this point p is dead: the code here cannot
182 // get to the bottom of the function.
183 // This used to have a spurious "live at call to printint: p".
184 printint(1) // nothing live here!
185 select { // ERROR "stack object .autotmp_[0-9]+ \[2\]runtime.scase$"
200 sink = p // prevent stack allocation, otherwise p is rematerializeable
202 // Unlike previous, the cases in this select fall through,
203 // so we can get to the println, so p is not dead.
204 printint(1) // ERROR "live at call to printint: p$"
205 select { // ERROR "live at call to selectgo: p$" "stack object .autotmp_[0-9]+ \[2\]runtime.scase$"
214 // similarly, select{} does not fall through.
215 // this used to have a spurious "live at entry to f12: ~r0".
225 // incorrectly placed VARDEF annotations can cause missing liveness annotations.
226 // this used to be missing the fact that s is live during the call to g13 (because it is
227 // needed for the call to h13).
231 s = h13(s, g13(s)) // ERROR "live at call to g13: s.ptr$"
234 func g13(string) string
235 func h13(string, string) string
237 // more incorrectly placed VARDEF.
240 x := g14() // ERROR "stack object x string$"
241 printstringpointer(&x)
246 // Checking that various temporaries do not persist or cause
247 // ambiguously live values that must be zeroed.
248 // The exact temporary names are inconsequential but we are
249 // trying to check that there is only one at any given site,
250 // and also that none show up in "ambiguously live" messages.
253 var mi map[interface{}]int
255 // str and iface are used to ensure that a temp is required for runtime calls below.
257 func iface() interface{}
261 delete(mi, iface()) // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
267 var m2s map[string]*byte
268 var m2 map[[2]string]*byte
272 func f17a(p *byte) { // ERROR "live at entry to f17a: p$"
274 m2[x2] = p // ERROR "live at call to mapassign: p$"
276 m2[x2] = p // ERROR "live at call to mapassign: p$"
277 m2[x2] = p // ERROR "live at call to mapassign: p$"
280 func f17b(p *byte) { // ERROR "live at entry to f17b: p$"
283 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$"
286 m2s[str()] = p // ERROR "live at call to mapassign_faststr: p$" "live at call to str: p$"
290 // key and value temporaries
292 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]+$"
295 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign_faststr: .autotmp_[0-9]+$"
303 // key temporary for mapaccess.
304 // temporary introduced by orderexpr.
307 z = m2[g18()] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
316 // byteptr is used to ensure that a temp is required for runtime calls below.
320 // dest temporary for channel receive.
324 z = <-ch // ERROR "stack object .autotmp_[0-9]+ \*byte$"
327 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
332 // src temporary for channel send
334 ch <- byteptr() // ERROR "stack object .autotmp_[0-9]+ \*byte$"
341 // key temporary for mapaccess using array literal key.
344 z = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
346 z = m2[[2]string{"x", "y"}]
347 z = m2[[2]string{"x", "y"}]
352 // key temporary for two-result map access using array literal key.
356 z, ok = m2[[2]string{"x", "y"}] // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
358 z, ok = m2[[2]string{"x", "y"}]
359 z, ok = m2[[2]string{"x", "y"}]
365 // key temporary for map access using array literal key.
366 // value temporary too.
368 m2[[2]string{"x", "y"}] = nil // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
370 m2[[2]string{"x", "y"}] = nil
371 m2[[2]string{"x", "y"}] = nil
374 // Non-open-coded defers should not cause autotmps. (Open-coded defers do create extra autotmps).
376 for i := 0; i < 2; i++ {
377 // Put in loop to make sure defer is not open-coded
391 // non-escaping ... slices passed to function call should die on return,
392 // so that the temporaries do not stack and do not cause ambiguously
397 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "stack object .autotmp_[0-9]+ \[3\]interface \{\}$"
399 print26((*int)(nil), (*int)(nil), (*int)(nil))
400 print26((*int)(nil), (*int)(nil), (*int)(nil))
405 func print26(...interface{})
407 // non-escaping closures passed to function call should die on return
412 call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
414 call27(func() { x++ })
415 call27(func() { x++ })
419 // but defer does escape to later execution in the function
421 func f27defer(b bool) {
424 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
426 defer call27(func() { x++ }) // ERROR "stack object .autotmp_[0-9]+ struct \{"
427 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ .autotmp_[0-9]+"
428 return // ERROR "live at indirect call: .autotmp_[0-9]+"
431 // and newproc (go) escapes to the heap
436 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
438 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
445 // concatstring slice should die on return
447 var s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 string
451 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "stack object .autotmp_[0-9]+ \[10\]string$"
453 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
454 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10)
457 // map iterator should die on end of range loop
461 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]+ runtime.hiter$"
462 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
465 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$"
466 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
468 for k := range m { // ERROR "live at call to mapiterinit: .autotmp_[0-9]+$" "live at call to mapiternext: .autotmp_[0-9]+$"
469 printstring(k) // ERROR "live at call to printstring: .autotmp_[0-9]+$"
473 // copy of array of pointers should die at end of range loop
474 var pstructarr [10]pstruct
476 // Struct size chosen to make pointer to element in pstructarr
477 // not computable by strength reduction.
478 type pstruct struct {
484 // live temp during printintpointer(p):
485 // the internal iterator pointer if a pointer to pstruct in pstructarr
486 // can not be easily computed by strength reduction.
488 for _, p := range pstructarr { // ERROR "stack object .autotmp_[0-9]+ \[10\]pstruct$"
489 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
492 for _, p := range pstructarr {
493 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
495 for _, p := range pstructarr {
496 printintpointer(p.intp) // ERROR "live at call to printintpointer: .autotmp_[0-9]+$"
500 // conversion to interface should not leave temporary behind
502 func f31(b1, b2, b3 bool) {
504 g31(g18()) // ERROR "stack object .autotmp_[0-9]+ \[2\]string$"
507 h31(g18()) // ERROR "live at call to convT: .autotmp_[0-9]+$" "live at call to newobject: .autotmp_[0-9]+$"
515 func g31(interface{})
516 func h31(...interface{})
518 // non-escaping partial functions passed to function call should die on return
522 func (t *T32) Inc() { // ERROR "live at entry to \(\*T32\).Inc: t$"
530 call32(t32.Inc) // ERROR "stack object .autotmp_[0-9]+ struct \{"
539 // temporaries introduced during if conditions and && || expressions
540 // should die once the condition has been acted upon.
542 var m33 map[interface{}]int
545 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
555 if m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}$"
563 if m33[byteptr()] == 0 && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
564 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
572 if m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
573 m33[byteptr()] == 0 { // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
581 if (m33[byteptr()] == 0 || // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
582 m33[byteptr()] == 0) && // ERROR "stack object .autotmp_[0-9]+ interface \{\}"
583 m33[byteptr()] == 0 {
590 // select temps should disappear in the case bodies
594 func fc38() chan string
595 func fi38(int) *string
599 // we don't care what temps are printed on the lines with output.
600 // we care that the println lines have no live variables
601 // and therefore no output.
603 select { // ERROR "live at call to selectgo:( .autotmp_[0-9]+)+$" "stack object .autotmp_[0-9]+ \[4\]runtime.scase$"
606 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$"
608 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$"
610 case *fi38(3), *fb38() = <-fc38(): // ERROR "stack object .autotmp_[0-9]+ string$" "live at call to f[ibc]38:( .autotmp_[0-9]+)+$"
618 // issue 8097: mishandling of x = x during return.
620 func f39() (x []int) {
622 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
626 func f39a() (x []int) {
628 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
632 func f39b() (x [10]*int) {
634 x[0] = new(int) // ERROR "live at call to newobject: x$"
635 printnl() // ERROR "live at call to printnl: x$"
639 func f39c() (x [10]*int) {
641 x[0] = new(int) // ERROR "live at call to newobject: x$"
642 printnl() // ERROR "live at call to printnl: x$"
646 // issue 8142: lost 'addrtaken' bit on inlined variables.
647 // no inlining in this test, so just checking that non-inlined works.
658 ret.m = make(map[int]int, 42) // ERROR "live at call to makemap: &ret$"
669 ret := T40{} // ERROR "stack object ret T40$"
670 ret.m = make(map[int]int) // ERROR "live at call to fastrand: .autotmp_[0-9]+$" "stack object .autotmp_[0-9]+ runtime.hmap$"
672 printnl() // ERROR "live at call to printnl: ret$"
673 // Note: ret is live at the printnl because the compiler moves &ret
674 // from before the printnl to after.
678 func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"
679 ddd2(x, y) // ERROR "stack object .autotmp_[0-9]+ \[2\]\*int$"
681 // Note: no .?autotmp live at printnl. See issue 16996.
683 func ddd2(a ...*int) { // ERROR "live at entry to ddd2: a$"
687 // issue 16016: autogenerated wrapper should have arguments live
690 func (*T) Foo(ptr *int) {}
694 // issue 18860: output arguments must be live all the time if there is a defer.
695 // In particular, at printint r must be live.
696 func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
701 printint(0) // ERROR "live at call to printint: .autotmp_[0-9]+ q r$"
703 return // ERROR "live at call to f41.func1: .autotmp_[0-9]+ r$"
708 f43([]*int{&p, &q, &r}) // ERROR "stack object .autotmp_[0-9]+ \[3\]\*int$"
709 f43([]*int{&p, &r, &q})
710 f43([]*int{&q, &p, &r})
716 // Assigning to a sub-element that makes up an entire local variable
717 // should clobber that variable.
718 func f44(f func() [2]*int) interface{} { // ERROR "live at entry to f44: f"
722 ret := T{} // ERROR "stack object ret T"