misc/cgo/test/testdata/issue41761.go | 20 ++++++++++++++++++++ misc/cgo/test/testdata/issue41761a/a.go | 14 ++++++++++++++ src/cmd/compile/internal/gc/iexport.go | 6 ++++++ src/cmd/compile/internal/gc/iimport.go | 5 +++++ diff --git a/misc/cgo/test/testdata/issue41761.go b/misc/cgo/test/testdata/issue41761.go new file mode 100644 index 0000000000000000000000000000000000000000..919c7492510096d6b245002a86618a055a56e422 --- /dev/null +++ b/misc/cgo/test/testdata/issue41761.go @@ -0,0 +1,20 @@ +// Copyright 2020 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. + +package cgotest + +/* + typedef struct S S; +*/ +import "C" + +import ( + "cgotest/issue41761a" + "testing" +) + +func test41761(t *testing.T) { + var x issue41761a.T + _ = (*C.struct_S)(x.X) +} diff --git a/misc/cgo/test/testdata/issue41761a/a.go b/misc/cgo/test/testdata/issue41761a/a.go new file mode 100644 index 0000000000000000000000000000000000000000..ca5c18191eb31de331d99da51e51fe692ec4f209 --- /dev/null +++ b/misc/cgo/test/testdata/issue41761a/a.go @@ -0,0 +1,14 @@ +// Copyright 2020 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. + +package issue41761a + +/* + typedef struct S S; +*/ +import "C" + +type T struct { + X *C.S +} diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go index 35b8d985cb3ef39448dc8589b144eb8805dc165f..81eb975b08ba00d64a72c2bf9bd9791623b891fd 100644 --- a/src/cmd/compile/internal/gc/iexport.go +++ b/src/cmd/compile/internal/gc/iexport.go @@ -492,6 +492,7 @@ w.param(m.Type.Recv()) w.signature(m.Type) } + w.typeExt(t) for _, m := range ms.Slice() { w.methExt(m) } @@ -1010,6 +1011,11 @@ // For re-exporting an imported symbol, pass its index through. w.int64(int64(lsym.SymIdx)) } } +} + +func (w *exportWriter) typeExt(t *types.Type) { + // Export whether this type is marked notinheap. + w.bool(t.NotInHeap()) } // Inline bodies. diff --git a/src/cmd/compile/internal/gc/iimport.go b/src/cmd/compile/internal/gc/iimport.go index 104b5fb79af64c3c905e6a2054bd5ad8b1c9ccbf..d9148eae2264e9cf4753865319f80b2f45f18b8a 100644 --- a/src/cmd/compile/internal/gc/iimport.go +++ b/src/cmd/compile/internal/gc/iimport.go @@ -346,6 +346,7 @@ mtyp.SetNname(asTypesNode(m)) } t.Methods().Set(ms) + r.typeExt(t) for _, m := range ms { r.methExt(m) } @@ -708,6 +709,10 @@ lsym.SymIdx = idx lsym.Set(obj.AttrIndexed, true) } } +} + +func (r *importReader) typeExt(t *types.Type) { + t.SetNotInHeap(r.bool()) } func (r *importReader) doInline(n *Node) {