Debian Codegraph @

test/fixedbugs/issue27278.go

raw
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
10 package main
11
12 type T struct {
13 _ [3]string
14 T2
15 }
16
17 func (t *T) M() []string {
18 return t.T2.M()
19 }
20
21 type T2 struct {
22 T3
23 }
24
25 func (t *T2) M() []string {
26 return t.T3.M()
27 }
28
29 type T3 struct {
30 a string
31 }
32
33 func (t *T3) M() []string {
34 return []string{}
35 }
36
37 func main() {
38 poison()
39 f()
40 }
41
42 //go:noinline
43 func f() {
44 (&T{}).M()
45 grow(10000)
46 }
47
48 // grow stack, triggers stack copy
49 func 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
58 func poison() {
59 x := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
60 g = x
61 }
62
63 var g [10]int