compiler: fix bug in handling of unordered set during exporting

In CL 183850 a change was made to combine tracking/discovery of
exported types and imported packages during export data generation. As
a result of this refactoring a bug was introduced: the new code can
potentially insert items into the exports set (an unordered_set) while
iterating through the same set, which is illegal according to the spec
for std::unordered_set.

This patch fixes the problem by changing the type discovery phase to
iterate through a separate list of sorted exports, as opposed to
iterating through the main unordered set.  Also included is a change
to fix the code that looks for variables that are referenced from
inlined routine bodies (this code wasn't scanning all of the function
that it needed to scan).

New test case for this problem in CL 186697.

Updates golang/go#33020.

Change-Id: Id9ae5af462bc0819e8c9a8dd038ce9746297ad5d
Reviewed-by: Ian Lance Taylor <>
3 files changed