Patchwork [gccgo] Use stub methods in type descriptors

login
register
mail settings
Submitter Ian Taylor
Date Nov. 11, 2010, 12:45 a.m.
Message ID <mcrzktgu1qk.fsf@google.com>
Download mbox | patch
Permalink /patch/70739/
State New
Headers show

Comments

Ian Taylor - Nov. 11, 2010, 12:45 a.m.
For embedded methods the Go frontend often needs to generate a stub
method, a small method which is similar to a C++ multiple inheritance
thunk.  The compiler was incorrectly failing to put these stub methods
in the type descriptor.  This patch fixes that.  Committed to gccgo
branch.

Ian

Patch

diff -r 2809673826c1 go/types.cc
--- a/go/types.cc	Wed Nov 10 15:36:06 2010 -0800
+++ b/go/types.cc	Wed Nov 10 16:42:42 2010 -0800
@@ -1369,7 +1369,15 @@ 
       vals->push_back(Expression::make_unary(OPERATOR_AND, s, bloc));
     }
 
-  Function_type* mtype = m->type();
+  Named_object* no = (m->needs_stub_method()
+		      ? m->stub_object()
+		      : m->named_object());
+
+  Function_type* mtype;
+  if (no->is_function())
+    mtype = no->func_value()->type();
+  else
+    mtype = no->func_declaration_value()->type();
   gcc_assert(mtype->is_method());
   Type* nonmethod_type = mtype->copy_without_receiver();
 
@@ -1383,8 +1391,7 @@ 
 
   ++p;
   gcc_assert(p->field_name() == "tfn");
-  vals->push_back(Expression::make_func_reference(m->named_object(), NULL,
-						  bloc));
+  vals->push_back(Expression::make_func_reference(no, NULL, bloc));
 
   ++p;
   gcc_assert(p == fields->end());
diff -r 2809673826c1 go/types.h
--- a/go/types.h	Wed Nov 10 15:36:06 2010 -0800
+++ b/go/types.h	Wed Nov 10 16:42:42 2010 -0800
@@ -161,6 +161,14 @@ 
   Named_object*
   named_object() const;
 
+  // Get the stub object.
+  Named_object*
+  stub_object() const
+  {
+    gcc_assert(this->stub_ != NULL);
+    return this->stub_;
+  }
+
   // Set the stub object.
   void
   set_stub_object(Named_object* no)