Source file test/escape_struct_return.go

     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 escape analysis for function parameters.
     8  
     9  package foo
    10  
    11  var Ssink *string
    12  
    13  type U struct {
    14  	_sp  *string
    15  	_spp **string
    16  }
    17  
    18  func A(sp *string, spp **string) U { // ERROR "leaking param: sp to result ~r0 level=0$" "leaking param: spp to result ~r0 level=0$"
    19  	return U{sp, spp}
    20  }
    21  
    22  func B(spp **string) U { // ERROR "leaking param: spp to result ~r0 level=0$"
    23  	return U{*spp, spp}
    24  }
    25  
    26  func tA1() {
    27  	s := "cat"
    28  	sp := &s
    29  	spp := &sp
    30  	u := A(sp, spp)
    31  	_ = u
    32  	println(s)
    33  }
    34  
    35  func tA2() {
    36  	s := "cat"
    37  	sp := &s
    38  	spp := &sp
    39  	u := A(sp, spp)
    40  	println(*u._sp)
    41  }
    42  
    43  func tA3() {
    44  	s := "cat"
    45  	sp := &s
    46  	spp := &sp
    47  	u := A(sp, spp)
    48  	println(**u._spp)
    49  }
    50  
    51  func tB1() {
    52  	s := "cat"
    53  	sp := &s
    54  	spp := &sp
    55  	u := B(spp)
    56  	_ = u
    57  	println(s)
    58  }
    59  
    60  func tB2() {
    61  	s := "cat"
    62  	sp := &s
    63  	spp := &sp
    64  	u := B(spp)
    65  	println(*u._sp)
    66  }
    67  
    68  func tB3() {
    69  	s := "cat"
    70  	sp := &s
    71  	spp := &sp
    72  	u := B(spp)
    73  	println(**u._spp)
    74  }
    75  

View as plain text