Home | History | Annotate | Download | only in fixedbugs
      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 call to newobject: xx$" "live at call to writebarrierptr: &xx$" "live at entry to f1: 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: &xx$"
     26 	}
     27 	xx, _, err := f2(xx, 5) // ERROR "live at call to f2: &xx$" "live at call to writebarrierptr: err.data err.type$"
     28 	if err != nil {
     29 		return err
     30 	}
     31 	return nil
     32 }
     33 
     34 //go:noinline
     35 func f2(d []byte, n int) (odata, res []byte, e interface{}) { // ERROR "live at entry to f2: d$"
     36 	if n > len(d) {
     37 		return d, nil, &T{M: "hello"} // ERROR "live at call to newobject: d" "live at call to writebarrierptr: d"
     38 	}
     39 	res = d[:n]
     40 	odata = d[n:]
     41 	return
     42 }
     43