Source file test/live2.go

     1  // errorcheck -0 -live -wb=0
     2  
     3  // Copyright 2014 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  // liveness tests with inlining ENABLED
     8  // see also live.go.
     9  
    10  package main
    11  
    12  // issue 8142: lost 'addrtaken' bit on inlined variables.
    13  
    14  func printnl()
    15  
    16  //go:noescape
    17  func useT40(*T40)
    18  
    19  type T40 struct {
    20  	m map[int]int
    21  }
    22  
    23  func newT40() *T40 {
    24  	ret := T40{}
    25  	ret.m = make(map[int]int, 42) // ERROR "live at call to makemap: &ret$"
    26  	return &ret
    27  }
    28  
    29  func bad40() {
    30  	t := newT40() // ERROR "stack object ret T40$" "stack object .autotmp_[0-9]+ runtime.hmap$"
    31  	printnl()     // ERROR "live at call to printnl: ret$"
    32  	useT40(t)
    33  }
    34  
    35  func good40() {
    36  	ret := T40{}                  // ERROR "stack object ret T40$"
    37  	ret.m = make(map[int]int, 42) // ERROR "stack object .autotmp_[0-9]+ runtime.hmap$"
    38  	t := &ret
    39  	printnl() // ERROR "live at call to printnl: ret$"
    40  	useT40(t)
    41  }
    42  

View as plain text