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})
}
//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
+ T2 int
//go:noinline // ERROR "misplaced compiler directive"
T3 int
)
_ = 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
//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
const c = 1
_ = func() {}
-
- // ok:
- //go:notinheap
- type T int
}
// EOF
// Caused a gofrontend crash.
+//go:build gccgo
+
package p
//go:notinheap
type S1 struct{}
type S2 struct {
- r interface { Read([]byte) (int, error) }
+ r interface{ Read([]byte) (int, error) }
s1, s2 []byte
- p *S1
- n uintptr
+ p *S1
+ n uintptr
}
var V any = S2{}
// 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
}
// Test write barrier elimination for notinheap.
+//go:build cgo
+
package p
+import "runtime/cgo"
+
type t1 struct {
x *nih
s []nih
y [1024]byte
}
-//go:notinheap
type nih struct {
+ _ cgo.Incomplete
x uintptr
}
+++ /dev/null
-// 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"