summaryrefslogtreecommitdiffstats
path: root/test/fixedbugs/issue19168.go
blob: b94b1d0a993d849f20fbfd6770291b8cd57457dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// errorcheck -0 -l -d=wb

// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package p

import (
	"reflect"
	"unsafe"

	reflect2 "reflect"
)

func sink(e interface{})

func a(hdr *reflect.SliceHeader, p *byte) {
	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
}

func b(hdr *reflect.StringHeader, p *byte) {
	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
}

func c(hdrs *[1]reflect.SliceHeader, p *byte) {
	hdrs[0].Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
}

func d(hdr *struct{ s reflect.StringHeader }, p *byte) {
	hdr.s.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
}

func e(p *byte) (resHeap, resStack string) {
	sink(&resHeap)

	hdr := (*reflect.StringHeader)(unsafe.Pointer(&resHeap))
	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"

	// No write barrier for non-escaping stack vars.
	hdr = (*reflect.StringHeader)(unsafe.Pointer(&resStack))
	hdr.Data = uintptr(unsafe.Pointer(p))

	return
}

func f(hdr *reflect2.SliceHeader, p *byte) {
	hdr.Data = uintptr(unsafe.Pointer(p)) // ERROR "write barrier"
}

type SliceHeader struct {
	Data uintptr
}

func g(hdr *SliceHeader, p *byte) {
	// No write barrier for lookalike SliceHeader.
	hdr.Data = uintptr(unsafe.Pointer(p))
}