Go patch committed: Follow-on fix for finalizing imported methods

Message ID CAOyqgcXSGfnCXcyhqMFxrnhgPezZoJ-7Tu0RaG3XwojAEmUdwA@mail.gmail.com
State New
Headers show
Series
  • Go patch committed: Follow-on fix for finalizing imported methods
Related show

Commit Message

Ian Lance Taylor July 23, 2019, 12:34 a.m.
This Go frontend patch by Than McIntosh is a revision to
https://golang.org/cl/185518
(https://gcc.gnu.org/ml/gcc-patches/2019-07/msg00821.html), which
added code to perform finalization of methods on types created by the
importer and not directly reachable until inlining is done.

The original fix invoked the finalization code at the end of
Import::read_types(), but it turns out this doesn't handle the case
where a type with methods is read in due to a reference from something
later in the export data (a function or variable).  The fix is to move
the import finalization call to the end of Import::import().

A testcase for this bug is in https://golang.org/cl/187057.

This fixes https://golang.org/issue/33219.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 273611)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-e242929304e7a524ced56dc94605bbf6d83e6489
+b7bce0dbccb978d33eb8ce0bffc02fae2c2857c1
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/import.cc
===================================================================
--- gcc/go/gofrontend/import.cc	(revision 273577)
+++ gcc/go/gofrontend/import.cc	(working copy)
@@ -450,6 +450,14 @@  Import::import(Gogo* gogo, const std::st
       this->require_c_string("\n");
     }
 
+  // Finalize methods for any imported types. This call is made late in the
+  // import process so as to A) avoid finalization of a type whose methods
+  // refer to types that are only partially read in, and B) capture both the
+  // types imported by read_types() directly, and those imported indirectly
+  // because they are referenced by an imported function or variable.
+  // See issues #33013 and #33219 for more on why this is needed.
+  this->finalize_methods();
+
   return this->package_;
 }
 
@@ -678,12 +686,6 @@  Import::read_types()
 	this->gogo_->add_named_type(nt);
     }
 
-  // Finalize methods for any imported types. This is done after most of
-  // read_types() is complete so as to avoid method finalization of a type
-  // whose methods refer to types that are only partially read in.
-  // See issue #33013 for more on why this is needed.
-  this->finalize_methods();
-
   return true;
 }