]> Cypherpunks repositories - gostls13.git/commitdiff
go/internal/gccgoimporter: parse optional escape info in export data
authorRobert Griesemer <gri@golang.org>
Tue, 9 Jan 2018 18:28:29 +0000 (10:28 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 10 Jan 2018 19:41:25 +0000 (19:41 +0000)
Fixes #23324.

Change-Id: Ie2383bad35f0bcc1344a8a1683be08d5fd0eea96
Reviewed-on: https://go-review.googlesource.com/86977
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/go/internal/gccgoimporter/importer_test.go
src/go/internal/gccgoimporter/parser.go
src/go/internal/gccgoimporter/testdata/escapeinfo.go [new file with mode: 0644]
src/go/internal/gccgoimporter/testdata/escapeinfo.gox [new file with mode: 0644]

index 26f5d9f5b7e8999a3bf08a1ab3d5a1f74b4fb043..01ab47a445129aae1983f9e8a41a2ef738ff1e7b 100644 (file)
@@ -102,6 +102,7 @@ var importerTests = [...]importerTest{
        {pkgpath: "unicode", name: "MaxRune", want: "const MaxRune untyped rune", wantval: "1114111"},
        {pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import", "math..import"}},
        {pkgpath: "alias", name: "IntAlias2", want: "type IntAlias2 = Int"},
+       {pkgpath: "escapeinfo", name: "NewT", want: "func NewT(data []byte) *T"},
 }
 
 func TestGoxImporter(t *testing.T) {
index 8a1ad5ff07fc14d6d0ef00f07e67a40d28992a14..4b3d899efd1bf8d7acc77a6f7fe006944eb32f3e 100644 (file)
@@ -226,6 +226,14 @@ func (p *parser) parseField(pkg *types.Package) (field *types.Var, tag string) {
 // Param = Name ["..."] Type .
 func (p *parser) parseParam(pkg *types.Package) (param *types.Var, isVariadic bool) {
        name := p.parseName()
+       if p.tok == '<' && p.scanner.Peek() == 'e' {
+               // EscInfo = "<esc:" int ">" . (optional and ignored)
+               p.next()
+               p.expectKeyword("esc")
+               p.expect(':')
+               p.expect(scanner.Int)
+               p.expect('>')
+       }
        if p.tok == '.' {
                p.next()
                p.expect('.')
diff --git a/src/go/internal/gccgoimporter/testdata/escapeinfo.go b/src/go/internal/gccgoimporter/testdata/escapeinfo.go
new file mode 100644 (file)
index 0000000..103ad95
--- /dev/null
@@ -0,0 +1,13 @@
+// Test case for escape info in export data. To compile and extract .gox file:
+// gccgo -fgo-optimize-allocs -c escapeinfo.go
+// objcopy -j .go_export escapeinfo.o escapeinfo.gox
+
+package escapeinfo
+
+type T struct{ data []byte }
+
+func NewT(data []byte) *T {
+       return &T{data}
+}
+
+func (*T) Read(p []byte) {}
diff --git a/src/go/internal/gccgoimporter/testdata/escapeinfo.gox b/src/go/internal/gccgoimporter/testdata/escapeinfo.gox
new file mode 100644 (file)
index 0000000..1db8156
Binary files /dev/null and b/src/go/internal/gccgoimporter/testdata/escapeinfo.gox differ