cmd/compile: make go:notinheap error message friendlier for cgo

Update #40954

Change-Id: Ifaab7349631ccb12fc892882bbdf7f0ebf3d845f
Reviewed-on: https://go-review.googlesource.com/c/go/+/251158
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Keith Randall <khr@golang.org>
This commit is contained in:
Keith Randall 2020-08-27 14:05:52 -07:00
parent 42b023d7b9
commit 37f261010f
6 changed files with 24 additions and 24 deletions

View file

@ -20,7 +20,7 @@ var x nih
// Stack variables are not okay.
func f() {
var y nih // ERROR "nih is go:notinheap; stack allocation disallowed"
var y nih // ERROR "nih is incomplete \(or unallocatable\); stack allocation disallowed"
x = y
}
@ -34,13 +34,13 @@ var w []nih
var n int
func g() {
y = new(nih) // ERROR "heap allocation disallowed"
y2 = new(struct{ x nih }) // ERROR "heap allocation disallowed"
y3 = new([1]nih) // ERROR "heap allocation disallowed"
z = make([]nih, 1) // ERROR "heap allocation disallowed"
z = append(z, x) // ERROR "heap allocation disallowed"
y = new(nih) // ERROR "can't be allocated in Go"
y2 = new(struct{ x nih }) // ERROR "can't be allocated in Go"
y3 = new([1]nih) // ERROR "can't be allocated in Go"
z = make([]nih, 1) // ERROR "can't be allocated in Go"
z = append(z, x) // ERROR "can't be allocated in Go"
// Test for special case of OMAKESLICECOPY
x := make([]nih, n) // ERROR "heap allocation disallowed"
x := make([]nih, n) // ERROR "can't be allocated in Go"
copy(x, z)
z = x
}