From ec2ea40b315e8b1a3d1dc8f7987584c4e2a00ef4 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 8 Aug 2022 01:10:18 +0700 Subject: 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 Reviewed-by: Joedian Reid Reviewed-by: David Chase TryBot-Result: Gopher Robot Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/noder.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index 15b1bf7b9f..b68d7b7702 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -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}) } -- cgit v1.3