...
Run Format

Source file test/escape3.go

Documentation: test

     1  // run
     2  
     3  // Copyright 2011 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  // Test the run-time behavior of escape analysis-related optimizations.
     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  }
    37  

View as plain text