Skip to content

Commit 37f2610

Browse files
committed
cmd/compile: make go:notinheap error message friendlier for cgo
Update golang#40954 Change-Id: Ifaab7349631ccb12fc892882bbdf7f0ebf3d845f Reviewed-on: https://go-review.googlesource.com/c/go/+/251158 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Trust: Keith Randall <[email protected]>
1 parent 42b023d commit 37f2610

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

src/cmd/compile/internal/gc/escape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ func (e *Escape) newLoc(n *Node, transient bool) *EscLocation {
10301030
Fatalf("e.curfn isn't set")
10311031
}
10321032
if n != nil && n.Type != nil && n.Type.NotInHeap() {
1033-
yyerrorl(n.Pos, "%v is go:notinheap; stack allocation disallowed", n.Type)
1033+
yyerrorl(n.Pos, "%v is incomplete (or unallocatable); stack allocation disallowed", n.Type)
10341034
}
10351035

10361036
n = canonicalNode(n)

src/cmd/compile/internal/gc/subr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,14 +689,14 @@ func convertop(srcConstant bool, src, dst *types.Type, why *string) Op {
689689
// (a) Disallow (*T) to (*U) where T is go:notinheap but U isn't.
690690
if src.IsPtr() && dst.IsPtr() && dst.Elem().NotInHeap() && !src.Elem().NotInHeap() {
691691
if why != nil {
692-
*why = fmt.Sprintf(":\n\t%v is go:notinheap, but %v is not", dst.Elem(), src.Elem())
692+
*why = fmt.Sprintf(":\n\t%v is incomplete (or unallocatable), but %v is not", dst.Elem(), src.Elem())
693693
}
694694
return OXXX
695695
}
696696
// (b) Disallow string to []T where T is go:notinheap.
697697
if src.IsString() && dst.IsSlice() && dst.Elem().NotInHeap() && (dst.Elem().Etype == types.Bytetype.Etype || dst.Elem().Etype == types.Runetype.Etype) {
698698
if why != nil {
699-
*why = fmt.Sprintf(":\n\t%v is go:notinheap", dst.Elem())
699+
*why = fmt.Sprintf(":\n\t%v is incomplete (or unallocatable)", dst.Elem())
700700
}
701701
return OXXX
702702
}

src/cmd/compile/internal/gc/typecheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,10 @@ func typecheck1(n *Node, top int) (res *Node) {
471471
return n
472472
}
473473
if l.Type.NotInHeap() {
474-
yyerror("go:notinheap map key not allowed")
474+
yyerror("incomplete (or unallocatable) map key not allowed")
475475
}
476476
if r.Type.NotInHeap() {
477-
yyerror("go:notinheap map value not allowed")
477+
yyerror("incomplete (or unallocatable) map value not allowed")
478478
}
479479

480480
setTypeNode(n, types.NewMap(l.Type, r.Type))
@@ -491,7 +491,7 @@ func typecheck1(n *Node, top int) (res *Node) {
491491
return n
492492
}
493493
if l.Type.NotInHeap() {
494-
yyerror("chan of go:notinheap type not allowed")
494+
yyerror("chan of incomplete (or unallocatable) type not allowed")
495495
}
496496

497497
setTypeNode(n, types.NewChan(l.Type, n.TChanDir()))

src/cmd/compile/internal/gc/walk.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ opswitch:
648648
// x = append(...)
649649
r := n.Right
650650
if r.Type.Elem().NotInHeap() {
651-
yyerror("%v is go:notinheap; heap allocation disallowed", r.Type.Elem())
651+
yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", r.Type.Elem())
652652
}
653653
switch {
654654
case isAppendOfMake(r):
@@ -1164,7 +1164,7 @@ opswitch:
11641164

11651165
case ONEW:
11661166
if n.Type.Elem().NotInHeap() {
1167-
yyerror("%v is go:notinheap; heap allocation disallowed", n.Type.Elem())
1167+
yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", n.Type.Elem())
11681168
}
11691169
if n.Esc == EscNone {
11701170
if n.Type.Elem().Width >= maxImplicitStackVarSize {
@@ -1335,7 +1335,7 @@ opswitch:
13351335
}
13361336
t := n.Type
13371337
if t.Elem().NotInHeap() {
1338-
yyerror("%v is go:notinheap; heap allocation disallowed", t.Elem())
1338+
yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", t.Elem())
13391339
}
13401340
if n.Esc == EscNone {
13411341
if !isSmallMakeSlice(n) {
@@ -1412,7 +1412,7 @@ opswitch:
14121412

14131413
t := n.Type
14141414
if t.Elem().NotInHeap() {
1415-
yyerror("%v is go:notinheap; heap allocation disallowed", t.Elem())
1415+
yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", t.Elem())
14161416
}
14171417

14181418
length := conv(n.Left, types.Types[TINT])

test/notinheap.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ type embed3 struct { // ERROR "must be go:notinheap"
2323
x [1]nih
2424
}
2525

26-
type embed4 map[nih]int // ERROR "go:notinheap map key not allowed"
26+
type embed4 map[nih]int // ERROR "incomplete \(or unallocatable\) map key not allowed"
2727

28-
type embed5 map[int]nih // ERROR "go:notinheap map value not allowed"
28+
type embed5 map[int]nih // ERROR "incomplete \(or unallocatable\) map value not allowed"
2929

30-
type emebd6 chan nih // ERROR "chan of go:notinheap type not allowed"
30+
type emebd6 chan nih // ERROR "chan of incomplete \(or unallocatable\) type not allowed"
3131

3232
type okay1 *nih
3333

@@ -64,8 +64,8 @@ var sink interface{}
6464

6565
func i() {
6666
sink = new(t1) // no error
67-
sink = (*t2)(new(t1)) // ERROR "cannot convert(.|\n)*t2 is go:notinheap"
68-
sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is go:notinheap"
69-
sink = []t3("foo") // ERROR "cannot convert(.|\n)*t3 is go:notinheap"
70-
sink = []t4("bar") // ERROR "cannot convert(.|\n)*t4 is go:notinheap"
67+
sink = (*t2)(new(t1)) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)"
68+
sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)"
69+
sink = []t3("foo") // ERROR "cannot convert(.|\n)*t3 is incomplete \(or unallocatable\)"
70+
sink = []t4("bar") // ERROR "cannot convert(.|\n)*t4 is incomplete \(or unallocatable\)"
7171
}

test/notinheap2.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var x nih
2020
// Stack variables are not okay.
2121

2222
func f() {
23-
var y nih // ERROR "nih is go:notinheap; stack allocation disallowed"
23+
var y nih // ERROR "nih is incomplete \(or unallocatable\); stack allocation disallowed"
2424
x = y
2525
}
2626

@@ -34,13 +34,13 @@ var w []nih
3434
var n int
3535

3636
func g() {
37-
y = new(nih) // ERROR "heap allocation disallowed"
38-
y2 = new(struct{ x nih }) // ERROR "heap allocation disallowed"
39-
y3 = new([1]nih) // ERROR "heap allocation disallowed"
40-
z = make([]nih, 1) // ERROR "heap allocation disallowed"
41-
z = append(z, x) // ERROR "heap allocation disallowed"
37+
y = new(nih) // ERROR "can't be allocated in Go"
38+
y2 = new(struct{ x nih }) // ERROR "can't be allocated in Go"
39+
y3 = new([1]nih) // ERROR "can't be allocated in Go"
40+
z = make([]nih, 1) // ERROR "can't be allocated in Go"
41+
z = append(z, x) // ERROR "can't be allocated in Go"
4242
// Test for special case of OMAKESLICECOPY
43-
x := make([]nih, n) // ERROR "heap allocation disallowed"
43+
x := make([]nih, n) // ERROR "can't be allocated in Go"
4444
copy(x, z)
4545
z = x
4646
}

0 commit comments

Comments
 (0)