Source file test/fixedbugs/issue19168.go

     1  // errorcheck -0 -l -d=wb
     2  
     3  // Copyright 2017 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  package p
     8  
     9  import (
    10  	"reflect"
    11  	"unsafe"
    12  
    13  	reflect2 "reflect"
    14  )
    15  
    16  func sink(e interface{})
    17  
    18  func a(hdr *reflect.SliceHeader, p *byte) {
    19  	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    20  }
    21  
    22  func b(hdr *reflect.StringHeader, p *byte) {
    23  	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    24  }
    25  
    26  func c(hdrs *[1]reflect.SliceHeader, p *byte) {
    27  	hdrs[0].Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    28  }
    29  
    30  func d(hdr *struct{ s reflect.StringHeader }, p *byte) {
    31  	hdr.s.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    32  }
    33  
    34  func e(p *byte) (resHeap, resStack string) {
    35  	sink(&resHeap)
    36  
    37  	hdr := (*reflect.StringHeader)(unsafe.Pointer(&resHeap))
    38  	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    39  
    40  	// No write barrier for non-escaping stack vars.
    41  	hdr = (*reflect.StringHeader)(unsafe.Pointer(&resStack))
    42  	hdr.Data = uintptr(unsafe.Pointer(p))
    43  
    44  	return
    45  }
    46  
    47  func f(hdr *reflect2.SliceHeader, p *byte) {
    48  	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
    49  }
    50  
    51  type SliceHeader struct {
    52  	Data uintptr
    53  }
    54  
    55  func g(hdr *SliceHeader, p *byte) {
    56  	// No write barrier for lookalike SliceHeader.
    57  	hdr.Data = uintptr(unsafe.Pointer(p))
    58  }
    59  

View as plain text