Skip to content

cmd/compile: no write barrier for stores to reflect.{Slice,String}Header #19168

Closed
@mdempsky

Description

@mdempsky

Package unsafe's godocs explicitly state this is safe:

hdr.Data = uintptr(unsafe.Pointer(p))              // case 6 (this case)

But compiling this code does not produce any write barriers:

package p

import (
	"reflect"
	"unsafe"
)

func F(hdr *reflect.SliceHeader, p *byte) {
	hdr.Data = uintptr(unsafe.Pointer(p))
}

func G(hdr *reflect.StringHeader, p *byte) {
	hdr.Data = uintptr(unsafe.Pointer(p))
}

We should probably change needwritebarrier(l) to return true when l is an ODOTPTR for accessing reflect.{Slice,String}Header.Data.

This should probably be backported to 1.8 too?

/cc @aclements @rsc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions