github.com/4ad/go@v0.0.0-20161219182952-69a12818b605/test/fixedbugs/issue15747.go (about)

     1  // errorcheck -0 -live
     2  
     3  // Copyright 2016 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  // Issue 15747: liveness analysis was marking heap-escaped params live too much,
     8  // and worse was using the wrong bitmap bits to do so.
     9  
    10  package p
    11  
    12  var global *[]byte
    13  
    14  type Q struct{}
    15  
    16  type T struct{ M string }
    17  
    18  var b bool
    19  
    20  func f1(q *Q, xx []byte) interface{} { // ERROR "live at entry to f1: q xx" "live at call to newobject: q xx" "live at call to writebarrierptr: q &xx"
    21  	// xx was copied from the stack to the heap on the previous line:
    22  	// xx was live for the first two prints but then it switched to &xx
    23  	// being live. We should not see plain xx again.
    24  	if b {
    25  		global = &xx // ERROR "live at call to writebarrierptr: q &xx$"
    26  	}
    27  	xx, _, err := f2(xx, 5) // ERROR "live at call to newobject: q( d)? &xx( odata.ptr)?" "live at call to writebarrierptr: q (e|err.data err.type)$"
    28  	if err != nil {
    29  		return err
    30  	}
    31  	return nil
    32  }
    33  
    34  func f2(d []byte, n int) (odata, res []byte, e interface{}) { // ERROR "live at entry to f2: d"
    35  	if n > len(d) {
    36  		return d, nil, &T{M: "hello"} // ERROR "live at call to newobject: d"
    37  	}
    38  	res = d[:n]
    39  	odata = d[n:]
    40  	return
    41  }