This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Fix handling of hidden methods for unnamed types


This patch to the Go frontend fixes the handling of hidden methods for
unnamed types.  If an interface has hidden methods, we must make the
interface table comdat if it is for an unnamed type.  When we create a
stub method for an unnamed type, we don't make it publically visible.
Bootstrapped and ran Go testsuite for x86_64-unknown-linux-gnu.
Committed to mainline.  Will commit to 4.8 branch when the branch
reopens.

Ian

diff -r 92e9a04996ea go/gogo-tree.cc
--- a/go/gogo-tree.cc	Fri Oct 11 15:14:51 2013 -0700
+++ b/go/gogo-tree.cc	Fri Oct 11 15:50:19 2013 -0700
@@ -2154,10 +2154,11 @@
   TREE_CONSTANT(decl) = 1;
   DECL_INITIAL(decl) = constructor;
 
-  // If the interface type has hidden methods, then this is the only
-  // definition of the table.  Otherwise it is a comdat table which
-  // may be defined in multiple packages.
-  if (has_hidden_methods)
+  // If the interface type has hidden methods, and the table is for a
+  // named type, then this is the only definition of the table.
+  // Otherwise it is a comdat table which may be defined in multiple
+  // packages.
+  if (has_hidden_methods && type->named_type() != NULL)
     TREE_PUBLIC(decl) = 1;
   else
     {
diff -r 92e9a04996ea go/gogo.cc
--- a/go/gogo.cc	Fri Oct 11 15:14:51 2013 -0700
+++ b/go/gogo.cc	Fri Oct 11 15:50:19 2013 -0700
@@ -3320,7 +3320,8 @@
     closure_var_(NULL), block_(block), location_(location), labels_(),
     local_type_count_(0), descriptor_(NULL), fndecl_(NULL), defer_stack_(NULL),
     is_sink_(false), results_are_named_(false), nointerface_(false),
-    calls_recover_(false), is_recover_thunk_(false), has_recover_thunk_(false),
+    is_unnamed_type_stub_method_(false), calls_recover_(false),
+    is_recover_thunk_(false), has_recover_thunk_(false),
     in_unique_section_(false)
 {
 }
@@ -3844,7 +3845,8 @@
       else if (!Gogo::is_hidden_name(no->name())
                || this->type_->is_method())
         {
-          is_visible = true;
+	  if (!this->is_unnamed_type_stub_method_)
+	    is_visible = true;
           std::string pkgpath = gogo->pkgpath_symbol();
           if (this->type_->is_method()
               && Gogo::is_hidden_name(no->name())
diff -r 92e9a04996ea go/gogo.h
--- a/go/gogo.h	Fri Oct 11 15:14:51 2013 -0700
+++ b/go/gogo.h	Fri Oct 11 15:50:19 2013 -0700
@@ -953,6 +953,15 @@
     this->nointerface_ = true;
   }
 
+  // Record that this function is a stub method created for an unnamed
+  // type.
+  void
+  set_is_unnamed_type_stub_method()
+  {
+    go_assert(this->is_method());
+    this->is_unnamed_type_stub_method_ = true;
+  }
+
   // Add a new field to the closure variable.
   void
   add_closure_field(Named_object* var, Location loc)
@@ -1178,6 +1187,9 @@
   bool results_are_named_ : 1;
   // True if this method should not be included in the type descriptor.
   bool nointerface_ : 1;
+  // True if this function is a stub method created for an unnamed
+  // type.
+  bool is_unnamed_type_stub_method_ : 1;
   // True if this function calls the predeclared recover function.
   bool calls_recover_ : 1;
   // True if this a thunk built for a function which calls recover.
diff -r 92e9a04996ea go/types.cc
--- a/go/types.cc	Fri Oct 11 15:14:51 2013 -0700
+++ b/go/types.cc	Fri Oct 11 15:50:19 2013 -0700
@@ -9031,6 +9031,8 @@
 				      fntype->is_varargs(), location);
 	  gogo->finish_function(fntype->location());
 
+	  if (type->named_type() == NULL && stub->is_function())
+	    stub->func_value()->set_is_unnamed_type_stub_method();
 	  if (m->nointerface() && stub->is_function())
 	    stub->func_value()->set_nointerface();
 	}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]