diff mbox

Go patch committed: Don't crash on blank interface

Message ID mcrvbnj7r0m.fsf@iant-glaptop.roam.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 16, 2014, 7:28 p.m. UTC
This patch from Chris Manghane fixes a compiler crash when using a blank
interface type.  This is http://golang.org/issue/8079 .  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian
diff mbox

Patch

diff -r f0e1f402d71c go/parse.cc
--- a/go/parse.cc	Thu Oct 16 11:56:29 2014 -0700
+++ b/go/parse.cc	Thu Oct 16 12:08:52 2014 -0700
@@ -245,7 +245,7 @@ 
 	   || token->is_op(OPERATOR_CHANOP))
     return this->channel_type();
   else if (token->is_keyword(KEYWORD_INTERFACE))
-    return this->interface_type();
+    return this->interface_type(true);
   else if (token->is_keyword(KEYWORD_FUNC))
     {
       Location location = token->location();
@@ -1179,7 +1179,7 @@ 
 // MethodSpecList     = MethodSpec { ";" MethodSpec } [ ";" ] .
 
 Type*
-Parse::interface_type()
+Parse::interface_type(bool record)
 {
   go_assert(this->peek_token()->is_keyword(KEYWORD_INTERFACE));
   Location location = this->location();
@@ -1227,7 +1227,8 @@ 
     }
 
   Interface_type* ret = Type::make_interface_type(methods, location);
-  this->gogo_->record_interface_type(ret);
+  if (record)
+    this->gogo_->record_interface_type(ret);
   return ret;
 }
 
@@ -1526,7 +1527,13 @@ 
     }
 
   Type* type;
-  if (!this->peek_token()->is_op(OPERATOR_SEMICOLON))
+  if (name == "_" && this->peek_token()->is_keyword(KEYWORD_INTERFACE))
+    {
+      // We call Parse::interface_type explicity here because we do not want
+      // to record an interface with a blank type name.
+      type = this->interface_type(false);
+    }
+  else if (!this->peek_token()->is_op(OPERATOR_SEMICOLON))
     type = this->type();
   else
     {
diff -r f0e1f402d71c go/parse.h
--- a/go/parse.h	Thu Oct 16 11:56:29 2014 -0700
+++ b/go/parse.h	Thu Oct 16 12:08:52 2014 -0700
@@ -182,7 +182,7 @@ 
   void parameter_decl(bool, Typed_identifier_list*, bool*, bool*, bool*);
   bool result(Typed_identifier_list**);
   Location block();
-  Type* interface_type();
+  Type* interface_type(bool record);
   void method_spec(Typed_identifier_list*);
   void declaration();
   bool declaration_may_start_here();