1// run 2 3// Copyright 2018 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7// Issue 27278: dead auto elim deletes an auto and its 8// initialization, but it is live because of a nil check. 9 10package main 11 12type T struct { 13 _ [3]string 14 T2 15} 16 17func (t *T) M() []string { 18 return t.T2.M() 19} 20 21type T2 struct { 22 T3 23} 24 25func (t *T2) M() []string { 26 return t.T3.M() 27} 28 29type T3 struct { 30 a string 31} 32 33func (t *T3) M() []string { 34 return []string{} 35} 36 37func main() { 38 poison() 39 f() 40} 41 42//go:noinline 43func f() { 44 (&T{}).M() 45 grow(10000) 46} 47 48// grow stack, triggers stack copy 49func grow(n int) { 50 if n == 0 { 51 return 52 } 53 grow(n-1) 54} 55 56// put some junk on stack, which cannot be valid address 57//go:noinline 58func poison() { 59 x := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 60 g = x 61} 62 63var g [10]int 64