]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gccgoimporter: support notinheap annotation
authorIan Lance Taylor <iant@golang.org>
Tue, 27 Oct 2020 19:59:54 +0000 (12:59 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Oct 2020 20:49:38 +0000 (20:49 +0000)
The gofrontend has started emitting a notinheap annotation for types
marked go:notinheap.

For #41761

Change-Id: Ic8f7ffc32dbfe98ec09b3d835957f1be8e6c1208
Reviewed-on: https://go-review.googlesource.com/c/go/+/265702
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/go/internal/gccgoimporter/importer_test.go
src/go/internal/gccgoimporter/parser.go
src/go/internal/gccgoimporter/testdata/notinheap.go [new file with mode: 0644]
src/go/internal/gccgoimporter/testdata/notinheap.gox [new file with mode: 0644]

index a74a45686801bab142d1bf163942a31ece1a7c77..e4236a586709638fd58c5c3eb3afa8b047ba489a 100644 (file)
@@ -97,6 +97,7 @@ var importerTests = [...]importerTest{
        {pkgpath: "issue30628", name: "Apple", want: "type Apple struct{hey sync.RWMutex; x int; RQ [517]struct{Count uintptr; NumBytes uintptr; Last uintptr}}"},
        {pkgpath: "issue31540", name: "S", gccgoVersion: 7, want: "type S struct{b int; map[Y]Z}"},
        {pkgpath: "issue34182", name: "T1", want: "type T1 struct{f *T2}"},
+       {pkgpath: "notinheap", name: "S", want: "type S struct{}"},
 }
 
 func TestGoxImporter(t *testing.T) {
index e2ef33f7ae6d3b182ee7384619c73e214d660348..1b1d07d3f6ed57da2ccbc9edd570064f5be7d101 100644 (file)
@@ -517,6 +517,13 @@ func (p *parser) parseNamedType(nlist []interface{}) types.Type {
                p.errorf("%v has nil type", obj)
        }
 
+       if p.tok == scanner.Ident && p.lit == "notinheap" {
+               p.next()
+               // The go/types package has no way of recording that
+               // this type is marked notinheap. Presumably no user
+               // of this package actually cares.
+       }
+
        // type alias
        if p.tok == '=' {
                p.next()
diff --git a/src/go/internal/gccgoimporter/testdata/notinheap.go b/src/go/internal/gccgoimporter/testdata/notinheap.go
new file mode 100644 (file)
index 0000000..b1ac967
--- /dev/null
@@ -0,0 +1,4 @@
+package notinheap
+
+//go:notinheap
+type S struct{}
diff --git a/src/go/internal/gccgoimporter/testdata/notinheap.gox b/src/go/internal/gccgoimporter/testdata/notinheap.gox
new file mode 100644 (file)
index 0000000..cc438e7
--- /dev/null
@@ -0,0 +1,7 @@
+v3;
+package notinheap
+pkgpath notinheap
+init notinheap ~notinheap
+types 3 2 30 18
+type 1 "S" notinheap <type 2>
+type 2 struct { }