Source file test/fixedbugs/issue15747.go
1 // errorcheck -0 -live 2 3 //go:build !goexperiment.cgocheck2 4 5 // Copyright 2016 The Go Authors. All rights reserved. 6 // Use of this source code is governed by a BSD-style 7 // license that can be found in the LICENSE file. 8 9 // Issue 15747: liveness analysis was marking heap-escaped params live too much, 10 // and worse was using the wrong bitmap bits to do so. 11 12 package p 13 14 var global *[]byte 15 16 type Q struct{} 17 18 type T struct{ M string } 19 20 var b bool 21 22 func f1(q *Q, xx []byte) interface{} { // ERROR "live at call to newobject: xx$" "live at entry to f1: xx$" 23 // xx was copied from the stack to the heap on the previous line: 24 // xx was live for the first two prints but then it switched to &xx 25 // being live. We should not see plain xx again. 26 if b { 27 global = &xx 28 } 29 xx, _, err := f2(xx, 5) // ERROR "live at call to f2: &xx$" 30 if err != nil { 31 return err 32 } 33 return nil 34 } 35 36 //go:noinline 37 func f2(d []byte, n int) (odata, res []byte, e interface{}) { // ERROR "live at entry to f2: d$" 38 if n > len(d) { 39 return d, nil, &T{M: "hello"} // ERROR "live at call to newobject: d" 40 } 41 res = d[:n] 42 odata = d[n:] 43 return 44 } 45