Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // run |
Russ Cox | c45c0c0 | 2011-09-02 15:11:28 -0400 | [diff] [blame] | 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2011 The Go Authors. All rights reserved. |
Russ Cox | c45c0c0 | 2011-09-02 15:11:28 -0400 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
Rob Pike | 83976e3 | 2012-02-19 14:28:53 +1100 | [diff] [blame] | 7 | // Test the run-time behavior of escape analysis-related optimizations. |
Russ Cox | c45c0c0 | 2011-09-02 15:11:28 -0400 | [diff] [blame] | 8 | |
| 9 | package main |
| 10 | |
| 11 | func main() { |
| 12 | test1() |
| 13 | } |
| 14 | |
| 15 | func test1() { |
| 16 | check1(0) |
| 17 | check1(1) |
| 18 | check1(2) |
| 19 | } |
| 20 | |
| 21 | type T1 struct { |
| 22 | X, Y, Z int |
| 23 | } |
| 24 | |
| 25 | func f() int { |
| 26 | return 1 |
| 27 | } |
| 28 | |
| 29 | func check1(pass int) T1 { |
| 30 | v := []T1{{X: f(), Z: f()}} |
| 31 | if v[0].Y != 0 { |
| 32 | panic("nonzero init") |
| 33 | } |
| 34 | v[0].Y = pass |
| 35 | return v[0] |
| 36 | } |