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)
36 printpointer(&x) // ERROR "live at call to printpointer: x$"
37 printpointer(&x) // ERROR "live at call to printpointer: x$"
42 printint(0) // nothing live here
46 printpointer(&x) // ERROR "live at call to printpointer: x$"
47 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
64 printpointer(&x) // ERROR "live at call to printpointer: x$"
65 printpointer(&x) // ERROR "live at call to printpointer: x$"
68 printpointer(&y) // ERROR "live at call to printpointer: y$"
69 printpointer(&y) // ERROR "live at call to printpointer: y$"
71 printint(0) // ERROR "f3: x \(type \*int\) is ambiguously live$" "f3: y \(type \*int\) is ambiguously live$" "live at call to printint: x y$"
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
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$"
110 printint(**z) // ERROR "f5: x \(type \*int\) is ambiguously live$" "f5: y \(type \*int\) is ambiguously live$" "live at call to printint: x y$"
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) {
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{}(str()) // ERROR "live at call to convT2E: .autotmp_[0-9]+ x.data x.type$" "live at call to str: x.data x.type$"
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 "live at call to newselect: .autotmp_[0-9]+$" "live at call to selectgo: .autotmp_[0-9]+$"
167 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+$"
169 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+$"
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 "live at call to newselect: .autotmp_[0-9]+$" "live at call to selectgo: .autotmp_[0-9]+$"
182 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+$"
184 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+$"
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 newselect: .autotmp_[0-9]+ p$" "live at call to selectgo: .autotmp_[0-9]+ p$"
202 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+ p$"
203 case <-c: // ERROR "live at call to selectrecv: .autotmp_[0-9]+ p$"
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.
237 printstringpointer(&x) // ERROR "live at call to printstringpointer: x$"
245 x = g15() // ERROR "live at call to g15: x$"
246 printstring(x) // ERROR "live at call to printstring: x$"
251 // Checking that various temporaries do not persist or cause
252 // ambiguously live values that must be zeroed.
253 // The exact temporary names are inconsequential but we are
254 // trying to check that there is only one at any given site,
255 // and also that none show up in "ambiguously live" messages.
259 // str is used to ensure that a temp is required for runtime calls below.
264 delete(m, str()) // ERROR "live at call to mapdelete: .autotmp_[0-9]+$"
266 delete(m, str()) // ERROR "live at call to mapdelete: .autotmp_[0-9]+$"
267 delete(m, str()) // ERROR "live at call to mapdelete: .autotmp_[0-9]+$"
270 var m2s map[string]*byte
271 var m2 map[[2]string]*byte
275 func f17a(p *byte) { // ERROR "live at entry to f17a: p$"
277 m2[x2] = p // ERROR "live at call to mapassign: p$"
279 m2[x2] = p // ERROR "live at call to mapassign: p$"
280 m2[x2] = p // ERROR "live at call to mapassign: p$"
283 func f17b(p *byte) { // ERROR "live at entry to f17b: p$"
286 m2s[str()] = p // ERROR "live at call to mapassign: p .autotmp_[0-9]+$" "live at call to str: p$"
288 m2s[str()] = p // ERROR "live at call to mapassign: p .autotmp_[0-9]+$" "live at call to str: p$"
289 m2s[str()] = p // ERROR "live at call to mapassign: p .autotmp_[0-9]+$" "live at call to str: p$"
293 // key and value temporaries
295 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign: .autotmp_[0-9]+ .autotmp_[0-9]+$"
297 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign: .autotmp_[0-9]+ .autotmp_[0-9]+$"
298 m2s[str()] = f17d() // ERROR "live at call to f17d: .autotmp_[0-9]+$" "live at call to mapassign: .autotmp_[0-9]+ .autotmp_[0-9]+$"
306 // key temporary for mapaccess.
307 // temporary introduced by orderexpr.
310 z = m2[g18()] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
312 z = m2[g18()] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
313 z = m2[g18()] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
319 // byteptr is used to ensure that a temp is required for runtime calls below.
323 // dest temporary for channel receive.
327 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
329 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
330 z = <-ch // ERROR "live at call to chanrecv1: .autotmp_[0-9]+$"
335 // src temporary for channel send
337 ch <- byteptr() // ERROR "live at call to chansend1: .autotmp_[0-9]+$"
339 ch <- byteptr() // ERROR "live at call to chansend1: .autotmp_[0-9]+$"
340 ch <- byteptr() // ERROR "live at call to chansend1: .autotmp_[0-9]+$"
344 // key temporary for mapaccess using array literal key.
347 z = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
349 z = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
350 z = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
355 // key temporary for two-result map access using array literal key.
359 z, ok = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess2: .autotmp_[0-9]+$"
361 z, ok = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess2: .autotmp_[0-9]+$"
362 z, ok = m2[[2]string{"x", "y"}] // ERROR "live at call to mapaccess2: .autotmp_[0-9]+$"
368 // key temporary for map access using array literal key.
369 // value temporary too.
371 m2[[2]string{"x", "y"}] = nil // ERROR "live at call to mapassign: .autotmp_[0-9]+$"
373 m2[[2]string{"x", "y"}] = nil // ERROR "live at call to mapassign: .autotmp_[0-9]+$"
374 m2[[2]string{"x", "y"}] = nil // ERROR "live at call to mapassign: .autotmp_[0-9]+$"
377 // defer should not cause spurious ambiguously live variables
386 x = g15() // ERROR "live at call to g15: x$"
387 printstring(x) // ERROR "live at call to printstring: x$"
388 } // ERROR "live at call to deferreturn: x$"
392 // non-escaping ... slices passed to function call should die on return,
393 // so that the temporaries do not stack and do not cause ambiguously
398 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "live at call to print26: .autotmp_[0-9]+$"
400 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "live at call to print26: .autotmp_[0-9]+$"
401 print26((*int)(nil), (*int)(nil), (*int)(nil)) // ERROR "live at call to print26: .autotmp_[0-9]+$"
406 func print26(...interface{})
408 // non-escaping closures passed to function call should die on return
413 call27(func() { x++ }) // ERROR "live at call to call27: .autotmp_[0-9]+$"
415 call27(func() { x++ }) // ERROR "live at call to call27: .autotmp_[0-9]+$"
416 call27(func() { x++ }) // ERROR "live at call to call27: .autotmp_[0-9]+$"
420 // but defer does escape to later execution in the function
422 func f27defer(b bool) {
425 defer call27(func() { x++ }) // ERROR "live at call to deferproc: .autotmp_[0-9]+$" "live at call to deferreturn: .autotmp_[0-9]+$"
427 defer call27(func() { x++ }) // ERROR "f27defer: .autotmp_[0-9]+ \(type struct { F uintptr; x \*int }\) is ambiguously live$" "live at call to deferproc: .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to deferreturn: .autotmp_[0-9]+ .autotmp_[0-9]+$"
428 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ .autotmp_[0-9]+$"
429 } // ERROR "live at call to deferreturn: .autotmp_[0-9]+ .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 newproc: &x$"
438 go call27(func() { x++ }) // ERROR "live at call to newobject: &x$"
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 "live at call to concatstrings: .autotmp_[0-9]+$" "live at call to printstring: .autotmp_[0-9]+$"
453 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: .autotmp_[0-9]+$" "live at call to printstring: .autotmp_[0-9]+$"
454 printstring(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10) // ERROR "live at call to concatstrings: .autotmp_[0-9]+$" "live at call to printstring: .autotmp_[0-9]+$"
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]+$"
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
478 // two live temps during print(p):
479 // the copy of ptrarr and the internal iterator pointer.
481 for _, p := range ptrarr {
482 printintpointer(p) // ERROR "live at call to printintpointer: .autotmp_[0-9]+ .autotmp_[0-9]+$"
485 for _, p := range ptrarr {
486 printintpointer(p) // ERROR "live at call to printintpointer: .autotmp_[0-9]+ .autotmp_[0-9]+$"
488 for _, p := range ptrarr {
489 printintpointer(p) // ERROR "live at call to printintpointer: .autotmp_[0-9]+ .autotmp_[0-9]+$"
493 // conversion to interface should not leave temporary behind
495 func f31(b1, b2, b3 bool) {
497 g31(str()) // ERROR "live at call to convT2E: .autotmp_[0-9]+$" "live at call to g31: .autotmp_[0-9]+$"
500 h31(str()) // ERROR "live at call to convT2E: .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to h31: .autotmp_[0-9]+$" "live at call to newobject: .autotmp_[0-9]+$"
503 panic(str()) // ERROR "live at call to convT2E: .autotmp_[0-9]+$" "live at call to gopanic: .autotmp_[0-9]+$"
508 func g31(interface{})
509 func h31(...interface{})
511 // non-escaping partial functions passed to function call should die on return
515 func (t *T32) Inc() { // ERROR "live at entry to \(\*T32\).Inc: t$"
523 call32(t32.Inc) // ERROR "live at call to call32: .autotmp_[0-9]+$"
525 call32(t32.Inc) // ERROR "live at call to call32: .autotmp_[0-9]+$"
526 call32(t32.Inc) // ERROR "live at call to call32: .autotmp_[0-9]+$"
532 // temporaries introduced during if conditions and && || expressions
533 // should die once the condition has been acted upon.
535 var m33 map[interface{}]int
538 if m33[byteptr()] == 0 { // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
548 if m33[byteptr()] == 0 { // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
556 if m33[byteptr()] == 0 && m33[byteptr()] == 0 { // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
564 if m33[byteptr()] == 0 || m33[byteptr()] == 0 { // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
572 if (m33[byteptr()] == 0 || m33[byteptr()] == 0) && m33[byteptr()] == 0 { // ERROR "live at call to mapaccess1: .autotmp_[0-9]+$"
579 // select temps should disappear in the case bodies
583 func fc38() chan string
584 func fi38(int) *string
588 // we don't care what temps are printed on the lines with output.
589 // we care that the println lines have no live variables
590 // and therefore no output.
592 select { // ERROR "live at call to newselect: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to selectgo: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$"
593 case <-fc38(): // ERROR "live at call to selectrecv: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$"
595 case fc38() <- *fi38(1): // ERROR "live at call to fc38: .autotmp_[0-9]+$" "live at call to fi38: .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to selectsend: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$"
597 case *fi38(2) = <-fc38(): // ERROR "live at call to fc38: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to fi38: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to selectrecv: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$"
599 case *fi38(3), *fb38() = <-fc38(): // ERROR "live at call to fb38: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to fc38: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to fi38: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$" "live at call to selectrecv2: .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+ .autotmp_[0-9]+$"
607 // issue 8097: mishandling of x = x during return.
609 func f39() (x []int) {
611 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
615 func f39a() (x []int) {
617 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+$"
621 func f39b() (x [10]*int) {
623 x[0] = new(int) // ERROR "live at call to newobject: x$"
624 printnl() // ERROR "live at call to printnl: x$"
628 func f39c() (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 // issue 8142: lost 'addrtaken' bit on inlined variables.
636 // no inlining in this test, so just checking that non-inlined works.
644 ret.m = make(map[int]int) // ERROR "live at call to makemap: &ret$"
656 ret.m = make(map[int]int) // ERROR "live at call to makemap: .autotmp_[0-9]+ ret$"
658 printnl() // ERROR "live at call to printnl: .autotmp_[0-9]+ ret$"
662 func ddd1(x, y *int) { // ERROR "live at entry to ddd1: x y$"
663 ddd2(x, y) // ERROR "live at call to ddd2: .autotmp_[0-9]+$"
665 // Note: no .?autotmp live at printnl. See issue 16996.
667 func ddd2(a ...*int) { // ERROR "live at entry to ddd2: a$"
671 // issue 16016: autogenerated wrapper should have arguments live
674 func (*T) Foo(ptr *int) {}
676 type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "live at entry to R\.Foo: \.this ptr"
678 // issue 18860: output arguments must be live all the time if there is a defer.
679 // In particular, at printint r must be live.
680 func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
682 defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
685 printint(0) // ERROR "live at call to printint: q r$"
687 return // ERROR "live at call to deferreturn: r$"