test: use cgo.Incomplete instead of go:notinheap for "run" tests

Same as CL 421880, but for test directory.

Updates #46731

Change-Id: If8d18df013a6833adcbd40acc1a721bbc23ca6b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/421881
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cuong Manh Le 2022-08-08 00:14:43 +07:00
parent ca634fa2c5
commit 64b260dbde
6 changed files with 39 additions and 15 deletions

View file

@ -4,14 +4,18 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build cgo
package main package main
import "runtime/cgo"
type iface interface { type iface interface {
Get() int Get() int
} }
//go:notinheap
type notInHeap struct { type notInHeap struct {
_ cgo.Incomplete
i int i int
} }
@ -29,7 +33,7 @@ type embed struct {
var val = 1234 var val = 1234
var valNotInHeap = notInHeap{val} var valNotInHeap = notInHeap{i: val}
func main() { func main() {
i := val i := val

View file

@ -4,24 +4,29 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build cgo
package main package main
import ( import (
"runtime/cgo"
"unsafe" "unsafe"
) )
//go:notinheap type S struct {
type S struct{ x int } _ cgo.Incomplete
x int
}
func main() { func main() {
var i int var i int
p := (*S)(unsafe.Pointer(uintptr(unsafe.Pointer(&i)))) p := (*S)(unsafe.Pointer(uintptr(unsafe.Pointer(&i))))
v := uintptr(unsafe.Pointer(p)) v := uintptr(unsafe.Pointer(p))
// p is a pointer to a go:notinheap type. Like some C libraries, // p is a pointer to a not-in-heap type. Like some C libraries,
// we stored an integer in that pointer. That integer just happens // we stored an integer in that pointer. That integer just happens
// to be the address of i. // to be the address of i.
// v is also the address of i. // v is also the address of i.
// p has a base type which is marked go:notinheap, so it // p has a base type which is marked not-in-heap, so it
// should not be adjusted when the stack is copied. // should not be adjusted when the stack is copied.
recurse(100, p, v) recurse(100, p, v)
} }

View file

@ -4,10 +4,14 @@
// source code is governed by a BSD-style license that can be found in // source code is governed by a BSD-style license that can be found in
// the LICENSE file. // the LICENSE file.
//go:build cgo
package main package main
//go:notinheap import "runtime/cgo"
type NIH struct { type NIH struct {
_ cgo.Incomplete
} }
type T struct { type T struct {

View file

@ -4,12 +4,17 @@
// source code is governed by a BSD-style license that can be found in // source code is governed by a BSD-style license that can be found in
// the LICENSE file. // the LICENSE file.
//go:build cgo
package main package main
import "reflect" import (
"reflect"
"runtime/cgo"
)
//go:notinheap
type NIH struct { type NIH struct {
_ cgo.Incomplete
} }
var x, y NIH var x, y NIH

View file

@ -1,6 +1,6 @@
// run // run
//go:build goexperiment.unified //go:build goexperiment.unified && cgo
// +build goexperiment.unified // +build goexperiment.unified,cgo
// TODO(mdempsky): Enable test unconditionally. This test should pass // TODO(mdempsky): Enable test unconditionally. This test should pass
// for non-unified mode too. // for non-unified mode too.
@ -11,8 +11,12 @@
package main package main
//go:notinheap import "runtime/cgo"
type A struct{ B }
type A struct {
B
_ cgo.Incomplete
}
type B struct{ x byte } type B struct{ x byte }
type I interface{ M() *B } type I interface{ M() *B }

View file

@ -4,15 +4,17 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build cgo
package main package main
import ( import (
"log" "log"
"runtime/cgo"
"unsafe" "unsafe"
) )
//go:notinheap type S struct{ _ cgo.Incomplete }
type S struct{}
func main() { func main() {
p := (*S)(unsafe.Pointer(uintptr(0x8000))) p := (*S)(unsafe.Pointer(uintptr(0x8000)))