]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.15] cmd/compile: make go:notinheap error message friendlier for cgo
authorKeith Randall <khr@golang.org>
Thu, 27 Aug 2020 21:05:52 +0000 (14:05 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 9 Oct 2020 17:25:25 +0000 (17:25 +0000)
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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/255338
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go
test/notinheap.go
test/notinheap2.go

index d5cca4a38bdcb770dab5af7f010772bc5ae50309..08000dd374ef3731e30fd84476a2b2f58e2e539b 100644 (file)
@@ -1030,7 +1030,7 @@ func (e *Escape) newLoc(n *Node, transient bool) *EscLocation {
                Fatalf("e.curfn isn't set")
        }
        if n != nil && n.Type != nil && n.Type.NotInHeap() {
-               yyerrorl(n.Pos, "%v is go:notinheap; stack allocation disallowed", n.Type)
+               yyerrorl(n.Pos, "%v is incomplete (or unallocatable); stack allocation disallowed", n.Type)
        }
 
        n = canonicalNode(n)
index 9362c7428865a6f7d10b1e75fb8071d799c462d7..c82eefb63d2fb2653e94d172cdfee6275dd52152 100644 (file)
@@ -696,14 +696,14 @@ func convertop(srcConstant bool, src, dst *types.Type, why *string) Op {
        // (a) Disallow (*T) to (*U) where T is go:notinheap but U isn't.
        if src.IsPtr() && dst.IsPtr() && dst.Elem().NotInHeap() && !src.Elem().NotInHeap() {
                if why != nil {
-                       *why = fmt.Sprintf(":\n\t%v is go:notinheap, but %v is not", dst.Elem(), src.Elem())
+                       *why = fmt.Sprintf(":\n\t%v is incomplete (or unallocatable), but %v is not", dst.Elem(), src.Elem())
                }
                return OXXX
        }
        // (b) Disallow string to []T where T is go:notinheap.
        if src.IsString() && dst.IsSlice() && dst.Elem().NotInHeap() && (dst.Elem().Etype == types.Bytetype.Etype || dst.Elem().Etype == types.Runetype.Etype) {
                if why != nil {
-                       *why = fmt.Sprintf(":\n\t%v is go:notinheap", dst.Elem())
+                       *why = fmt.Sprintf(":\n\t%v is incomplete (or unallocatable)", dst.Elem())
                }
                return OXXX
        }
index b29f5ef5ec7eb86ab9a329e0f2c838b73a0354e5..56a03f19318cbef6a50af25b551eab4225e3a831 100644 (file)
@@ -471,10 +471,10 @@ func typecheck1(n *Node, top int) (res *Node) {
                        return n
                }
                if l.Type.NotInHeap() {
-                       yyerror("go:notinheap map key not allowed")
+                       yyerror("incomplete (or unallocatable) map key not allowed")
                }
                if r.Type.NotInHeap() {
-                       yyerror("go:notinheap map value not allowed")
+                       yyerror("incomplete (or unallocatable) map value not allowed")
                }
 
                setTypeNode(n, types.NewMap(l.Type, r.Type))
@@ -491,7 +491,7 @@ func typecheck1(n *Node, top int) (res *Node) {
                        return n
                }
                if l.Type.NotInHeap() {
-                       yyerror("chan of go:notinheap type not allowed")
+                       yyerror("chan of incomplete (or unallocatable) type not allowed")
                }
 
                setTypeNode(n, types.NewChan(l.Type, n.TChanDir()))
index 8dd12777050ef5399e577ac18fb8a04458781a5d..af6602f70cdf806e7e9182617591e9cb9ae09db6 100644 (file)
@@ -640,7 +640,7 @@ opswitch:
                        // x = append(...)
                        r := n.Right
                        if r.Type.Elem().NotInHeap() {
-                               yyerror("%v is go:notinheap; heap allocation disallowed", r.Type.Elem())
+                               yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", r.Type.Elem())
                        }
                        switch {
                        case isAppendOfMake(r):
@@ -1152,7 +1152,7 @@ opswitch:
 
        case ONEW:
                if n.Type.Elem().NotInHeap() {
-                       yyerror("%v is go:notinheap; heap allocation disallowed", n.Type.Elem())
+                       yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", n.Type.Elem())
                }
                if n.Esc == EscNone {
                        if n.Type.Elem().Width >= maxImplicitStackVarSize {
@@ -1323,7 +1323,7 @@ opswitch:
                }
                t := n.Type
                if t.Elem().NotInHeap() {
-                       yyerror("%v is go:notinheap; heap allocation disallowed", t.Elem())
+                       yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", t.Elem())
                }
                if n.Esc == EscNone {
                        if !isSmallMakeSlice(n) {
@@ -1400,7 +1400,7 @@ opswitch:
 
                t := n.Type
                if t.Elem().NotInHeap() {
-                       yyerror("%v is go:notinheap; heap allocation disallowed", t.Elem())
+                       yyerror("%v can't be allocated in Go; it is incomplete (or unallocatable)", t.Elem())
                }
 
                length := conv(n.Left, types.Types[TINT])
index a2284a50689c21b647e95392ecf1b6df2f6a504b..5dd4997a6572daf7449a2f37f3a4d24dee099ef1 100644 (file)
@@ -23,11 +23,11 @@ type embed3 struct { // ERROR "must be go:notinheap"
        x [1]nih
 }
 
-type embed4 map[nih]int // ERROR "go:notinheap map key not allowed"
+type embed4 map[nih]int // ERROR "incomplete \(or unallocatable\) map key not allowed"
 
-type embed5 map[int]nih // ERROR "go:notinheap map value not allowed"
+type embed5 map[int]nih // ERROR "incomplete \(or unallocatable\) map value not allowed"
 
-type emebd6 chan nih // ERROR "chan of go:notinheap type not allowed"
+type emebd6 chan nih // ERROR "chan of incomplete \(or unallocatable\) type not allowed"
 
 type okay1 *nih
 
@@ -64,8 +64,8 @@ var sink interface{}
 
 func i() {
        sink = new(t1)                     // no error
-       sink = (*t2)(new(t1))              // ERROR "cannot convert(.|\n)*t2 is go:notinheap"
-       sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is go:notinheap"
-       sink = []t3("foo")                 // ERROR "cannot convert(.|\n)*t3 is go:notinheap"
-       sink = []t4("bar")                 // ERROR "cannot convert(.|\n)*t4 is go:notinheap"
+       sink = (*t2)(new(t1))              // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)"
+       sink = (*t2)(new(struct{ x int })) // ERROR "cannot convert(.|\n)*t2 is incomplete \(or unallocatable\)"
+       sink = []t3("foo")                 // ERROR "cannot convert(.|\n)*t3 is incomplete \(or unallocatable\)"
+       sink = []t4("bar")                 // ERROR "cannot convert(.|\n)*t4 is incomplete \(or unallocatable\)"
 }
index 09d0fc0b7b665d80abb8fa238316110e2fff0670..23d4b0ae77469a0c6fda6886adc40f76daac8d7e 100644 (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
 }