]> Cypherpunks repositories - gostls13.git/commit
go/internal/gccgoimporter: fix updating of "forward declared" types
authorRobert Griesemer <gri@golang.org>
Tue, 25 Sep 2018 22:31:23 +0000 (15:31 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 27 Sep 2018 02:52:03 +0000 (02:52 +0000)
commit9c81402f58ae83987f32153c1587c9f03b4a5769
treeff0411e9eceea3a5a5ceb4c1c448332faeef9c9f
parentae9c822f78d5048aa4290b06a5a38f67aaf23dbe
go/internal/gccgoimporter: fix updating of "forward declared" types

The existing code uses a type map which associates a type number
with a type; references to existing types are expressed via the
type number in the export data.

Before this CL, type map entries were set when a type was read
in completely, which meant that recursive references to types
(i.e., type map entries) that were in the middle of construction
(i.e., where the type map was not yet updated) would lead to nil
types. Such cycles are usually created via defined types which
introduce a types.Named entry into the type map before the underlying
type is parsed; in this case the code worked. In case of type aliases,
no such "forwarder" exists and type cycles lead to nil types.

This CL fixes the problem by a) updating the type map as soon as
a type becomes available but before the type's components are parsed;
b) keeping track of a list of type map entries that may need to be
updated together (because of aliases that may all refer to the same
type); and c) adding (redundant) markers to the type map to detect
algorithmic errors.

Also:
- distinguish between parseInt and parseInt64
- added more test cases

Fixes #27856.

Change-Id: Iba701439ea3231aa435b7b80ea2d419db2af3be1
Reviewed-on: https://go-review.googlesource.com/137857
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/go/internal/gccgoimporter/importer_test.go
src/go/internal/gccgoimporter/parser.go
src/go/internal/gccgoimporter/testdata/aliases.go [new file with mode: 0644]
src/go/internal/gccgoimporter/testdata/aliases.gox [new file with mode: 0644]
src/go/internal/gccgoimporter/testdata/issue27856.go [new file with mode: 0644]
src/go/internal/gccgoimporter/testdata/issue27856.gox [new file with mode: 0644]