mirror of
https://github.com/golang/go.git
synced 2026-01-29 07:02:05 +03:00
So it won't be visible outside of runtime package. There are changes to
make tests happy:
- For test/directive*.go files, using "go:noinline" for testing misplaced
directives instead.
- Restrict test/fixedbugs/bug515.go for gccgo only.
- For test/notinheap{2,3}.go, using runtime/cgo.Incomplete for marking
the type as not-in-heap. Though it's somewhat clumsy, it's the easiest
way to keep the test errors for not-in-heap types until we can cleanup
further.
- test/typeparam/mdempsky/11.go is about defined type in user code marked
as go:notinheap, which can't happen after this CL, though.
Fixes #46731
Change-Id: I869f5b2230c8a2a363feeec042e7723bbc416e8e
Reviewed-on: https://go-review.googlesource.com/c/go/+/421882
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
81 lines
1.3 KiB
Go
81 lines
1.3 KiB
Go
// errorcheck -+ -0 -l -d=wb
|
|
|
|
// Copyright 2016 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.
|
|
|
|
// Test write barrier elimination for notinheap.
|
|
|
|
//go:build cgo
|
|
|
|
package p
|
|
|
|
import "runtime/cgo"
|
|
|
|
type t1 struct {
|
|
x *nih
|
|
s []nih
|
|
y [1024]byte // Prevent write decomposition
|
|
}
|
|
|
|
type t2 struct {
|
|
x *ih
|
|
s []ih
|
|
y [1024]byte
|
|
}
|
|
|
|
type nih struct {
|
|
_ cgo.Incomplete
|
|
x uintptr
|
|
}
|
|
|
|
type ih struct { // In-heap type
|
|
x uintptr
|
|
}
|
|
|
|
var (
|
|
v1 t1
|
|
v2 t2
|
|
|
|
v1s []t1
|
|
v2s []t2
|
|
)
|
|
|
|
func f() {
|
|
// Test direct writes
|
|
v1.x = nil // no barrier
|
|
v2.x = nil // ERROR "write barrier"
|
|
v1.s = []nih(nil) // no barrier
|
|
v2.s = []ih(nil) // ERROR "write barrier"
|
|
}
|
|
|
|
func g() {
|
|
// Test aggregate writes
|
|
v1 = t1{x: nil} // no barrier
|
|
v2 = t2{x: nil} // ERROR "write barrier"
|
|
}
|
|
|
|
func h() {
|
|
// Test copies and appends.
|
|
copy(v1s, v1s[1:]) // no barrier
|
|
copy(v2s, v2s[1:]) // ERROR "write barrier"
|
|
_ = append(v1s, v1s...) // no barrier
|
|
_ = append(v2s, v2s...) // ERROR "write barrier"
|
|
}
|
|
|
|
// Slice clearing
|
|
|
|
var (
|
|
sliceIH []*ih
|
|
sliceNIH []*nih
|
|
)
|
|
|
|
func sliceClear() {
|
|
for i := range sliceIH {
|
|
sliceIH[i] = nil // ERROR "write barrier"
|
|
}
|
|
for i := range sliceNIH {
|
|
sliceNIH[i] = nil // no barrier
|
|
}
|
|
}
|