mirror of
https://github.com/golang/go
synced 2024-11-22 08:54:39 -07:00
cmd/compile: restrict //go:notinheap to runtime/internal/sys
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>
This commit is contained in:
parent
134cd34c07
commit
ec2ea40b31
@ -344,6 +344,9 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P
|
||||
if flag == 0 && !allowedStdPragmas[verb] && base.Flag.Std {
|
||||
p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s is not allowed in the standard library", verb)})
|
||||
}
|
||||
if flag == ir.NotInHeap && *base.Flag.LowerP != "runtime/internal/sys" {
|
||||
p.error(syntax.Error{Pos: pos, Msg: "//go:notinheap only allowed in runtime/internal/sys"})
|
||||
}
|
||||
pragma.Flag |= flag
|
||||
pragma.Pos = append(pragma.Pos, pragmaPos{flag, pos})
|
||||
}
|
||||
|
@ -29,17 +29,9 @@ const c = 1
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
type T int
|
||||
|
||||
// ok
|
||||
//go:notinheap
|
||||
type T1 int
|
||||
|
||||
type (
|
||||
//go:notinheap
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
T2 int
|
||||
T2b int
|
||||
//go:notinheap
|
||||
T2c int
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
T3 int
|
||||
)
|
||||
@ -61,11 +53,5 @@ func f() {
|
||||
_ = func() {}
|
||||
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
// ok:
|
||||
//go:notinheap
|
||||
type T int
|
||||
}
|
||||
|
||||
// someday there might be a directive that can apply to type aliases, but go:notinheap doesn't.
|
||||
//go:notinheap // ERROR "misplaced compiler directive"
|
||||
type T6 = int
|
||||
|
@ -13,21 +13,20 @@ package main
|
||||
|
||||
//go:build bad // ERROR "misplaced compiler directive"
|
||||
|
||||
//go:notinheap // ERROR "misplaced compiler directive"
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
type (
|
||||
T2 int //go:notinheap // ERROR "misplaced compiler directive"
|
||||
T2 int //go:noinline // ERROR "misplaced compiler directive"
|
||||
T2b int
|
||||
T2c int
|
||||
T3 int
|
||||
)
|
||||
|
||||
//go:notinheap // ERROR "misplaced compiler directive"
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
type (
|
||||
//go:notinheap
|
||||
T4 int
|
||||
)
|
||||
|
||||
//go:notinheap // ERROR "misplaced compiler directive"
|
||||
//go:noinline // ERROR "misplaced compiler directive"
|
||||
type ()
|
||||
|
||||
type T5 int
|
||||
@ -53,10 +52,6 @@ func f() {
|
||||
const c = 1
|
||||
|
||||
_ = func() {}
|
||||
|
||||
// ok:
|
||||
//go:notinheap
|
||||
type T int
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
@ -6,6 +6,8 @@
|
||||
|
||||
// Caused a gofrontend crash.
|
||||
|
||||
//go:build gccgo
|
||||
|
||||
package p
|
||||
|
||||
//go:notinheap
|
||||
|
@ -4,12 +4,16 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Test walk errors for go:notinheap.
|
||||
// Test walk errors for not-in-heap.
|
||||
|
||||
//go:build cgo
|
||||
|
||||
package p
|
||||
|
||||
//go:notinheap
|
||||
import "runtime/cgo"
|
||||
|
||||
type nih struct {
|
||||
_ cgo.Incomplete
|
||||
next *nih
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,12 @@
|
||||
|
||||
// Test write barrier elimination for notinheap.
|
||||
|
||||
//go:build cgo
|
||||
|
||||
package p
|
||||
|
||||
import "runtime/cgo"
|
||||
|
||||
type t1 struct {
|
||||
x *nih
|
||||
s []nih
|
||||
@ -20,8 +24,8 @@ type t2 struct {
|
||||
y [1024]byte
|
||||
}
|
||||
|
||||
//go:notinheap
|
||||
type nih struct {
|
||||
_ cgo.Incomplete
|
||||
x uintptr
|
||||
}
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
// errorcheck
|
||||
|
||||
// Copyright 2021 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.
|
||||
|
||||
// Reported by Cuong Manh Le.
|
||||
|
||||
package p
|
||||
|
||||
type a struct{}
|
||||
|
||||
//go:notinheap
|
||||
type b a
|
||||
|
||||
var _ = (*b)(new(a)) // ERROR "cannot convert"
|
Loading…
Reference in New Issue
Block a user