...
Run Format

Source file test/escape_level.go

Documentation: test

     1  // errorcheck -0 -m -l
     2  
     3  // Copyright 2015 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 indirection level computation in escape analysis.
     8  
     9  package escape
    10  
    11  var sink interface{}
    12  
    13  func level0() {
    14  	i := 0     // ERROR "moved to heap: i"
    15  	p0 := &i   // ERROR "moved to heap: p0" "&i escapes to heap"
    16  	p1 := &p0  // ERROR "moved to heap: p1" "&p0 escapes to heap"
    17  	p2 := &p1  // ERROR "moved to heap: p2" "&p1 escapes to heap"
    18  	sink = &p2 // ERROR "&p2 escapes to heap"
    19  }
    20  
    21  func level1() {
    22  	i := 0    // ERROR "moved to heap: i"
    23  	p0 := &i  // ERROR "moved to heap: p0" "&i escapes to heap"
    24  	p1 := &p0 // ERROR "moved to heap: p1" "&p0 escapes to heap"
    25  	p2 := &p1 // ERROR "&p1 escapes to heap"
    26  	sink = p2 // ERROR "p2 escapes to heap"
    27  }
    28  
    29  func level2() {
    30  	i := 0     // ERROR "moved to heap: i"
    31  	p0 := &i   // ERROR "moved to heap: p0" "&i escapes to heap"
    32  	p1 := &p0  // ERROR "&p0 escapes to heap"
    33  	p2 := &p1  // ERROR "&p1 does not escape"
    34  	sink = *p2 // ERROR "\*p2 escapes to heap"
    35  }
    36  
    37  func level3() {
    38  	i := 0      // ERROR "moved to heap: i"
    39  	p0 := &i    // ERROR "&i escapes to heap"
    40  	p1 := &p0   // ERROR "&p0 does not escape"
    41  	p2 := &p1   // ERROR "&p1 does not escape"
    42  	sink = **p2 // ERROR "\* \(\*p2\) escapes to heap"
    43  }
    44  
    45  func level4() {
    46  	i := 0     // ERROR "moved to heap: i"
    47  	p0 := &i   // ERROR "moved to heap: p0" "&i escapes to heap"
    48  	p1 := &p0  // ERROR "&p0 escapes to heap"
    49  	p2 := p1   // ERROR "moved to heap: p2"
    50  	sink = &p2 // ERROR "&p2 escapes to heap"
    51  }
    52  
    53  func level5() {
    54  	i := 0    // ERROR "moved to heap: i"
    55  	p0 := &i  // ERROR "moved to heap: p0" "&i escapes to heap"
    56  	p1 := &p0 // ERROR "&p0 escapes to heap"
    57  	p2 := p1
    58  	sink = p2 // ERROR "p2 escapes to heap"
    59  }
    60  
    61  func level6() {
    62  	i := 0    // ERROR "moved to heap: i"
    63  	p0 := &i  // ERROR "&i escapes to heap"
    64  	p1 := &p0 // ERROR "&p0 does not escape"
    65  	p2 := p1
    66  	sink = *p2 // ERROR "\*p2 escapes to heap"
    67  }
    68  
    69  func level7() {
    70  	i := 0    // ERROR "moved to heap: i"
    71  	p0 := &i  // ERROR "&i escapes to heap"
    72  	p1 := &p0 // ERROR "&p0 does not escape"
    73  	// note *p1 == &i
    74  	p2 := *p1  // ERROR "moved to heap: p2"
    75  	sink = &p2 // ERROR "&p2 escapes to heap"
    76  }
    77  
    78  func level8() {
    79  	i := 0    // ERROR "moved to heap: i"
    80  	p0 := &i  // ERROR "&i escapes to heap"
    81  	p1 := &p0 // ERROR "&p0 does not escape"
    82  	p2 := *p1
    83  	sink = p2 // ERROR "p2 escapes to heap"
    84  }
    85  
    86  func level9() {
    87  	i := 0
    88  	p0 := &i  // ERROR "&i does not escape"
    89  	p1 := &p0 // ERROR "&p0 does not escape"
    90  	p2 := *p1
    91  	sink = *p2 // ERROR "\*p2 escapes to heap"
    92  }
    93  
    94  func level10() {
    95  	i := 0
    96  	p0 := &i // ERROR "&i does not escape"
    97  	p1 := *p0
    98  	p2 := &p1  // ERROR "&p1 does not escape"
    99  	sink = *p2 // ERROR "\*p2 escapes to heap"
   100  }
   101  
   102  func level11() {
   103  	i := 0
   104  	p0 := &i   // ERROR "&i does not escape"
   105  	p1 := &p0  // ERROR "&p0 does not escape"
   106  	p2 := **p1 // ERROR "moved to heap: p2"
   107  	sink = &p2 // ERROR "&p2 escapes to heap"
   108  }
   109  

View as plain text