modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue15747.go (about)

     1  // errorcheck -0 -live -d=eagerwb
     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  // TODO(austin): This expects function calls to the write barrier, so
    11  // we enable the legacy eager write barrier. Fix this once the
    12  // buffered write barrier works on all arches.
    13  
    14  package p
    15  
    16  var global *[]byte
    17  
    18  type Q struct{}
    19  
    20  type T struct{ M string }
    21  
    22  var b bool
    23  
    24  func f1(q *Q, xx []byte) interface{} { // ERROR "live at call to newobject: xx$" "live at call to writebarrierptr: &xx$" "live at entry to f1: xx$"
    25  	// xx was copied from the stack to the heap on the previous line:
    26  	// xx was live for the first two prints but then it switched to &xx
    27  	// being live. We should not see plain xx again.
    28  	if b {
    29  		global = &xx // ERROR "live at call to writebarrierptr: &xx$"
    30  	}
    31  	xx, _, err := f2(xx, 5) // ERROR "live at call to f2: &xx$" "live at call to writebarrierptr: err.data err.type$"
    32  	if err != nil {
    33  		return err
    34  	}
    35  	return nil
    36  }
    37  
    38  //go:noinline
    39  func f2(d []byte, n int) (odata, res []byte, e interface{}) { // ERROR "live at entry to f2: d$"
    40  	if n > len(d) {
    41  		return d, nil, &T{M: "hello"} // ERROR "live at call to newobject: d" "live at call to writebarrierptr: d"
    42  	}
    43  	res = d[:n]
    44  	odata = d[n:]
    45  	return
    46  }