Patchwork Go patch committed: Don't crash declaring function named "_"

login
register
mail settings
Submitter Ian Taylor
Date March 3, 2011, 1:48 a.m.
Message ID <mcraahd3rf3.fsf@google.com>
Download mbox | patch
Permalink /patch/85210/
State New
Headers show

Comments

Ian Taylor - March 3, 2011, 1:48 a.m.
In Go the name "_" is special: it means that the object has no name at
all.  This patch to the Go frontend fixes the case of declaring a
function with the name "_".  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 581b2502f121 go/parse.cc
--- a/go/parse.cc	Wed Mar 02 17:38:24 2011 -0800
+++ b/go/parse.cc	Wed Mar 02 17:43:26 2011 -0800
@@ -2063,9 +2063,12 @@ 
 	  return;
 	}
       this->advance_token();
-      named_object = this->gogo_->declare_function(name, fntype, location);
-      if (named_object->is_function_declaration())
-	named_object->func_declaration_value()->set_asm_name(asm_name);
+      if (!Gogo::is_sink_name(name))
+	{
+	  named_object = this->gogo_->declare_function(name, fntype, location);
+	  if (named_object->is_function_declaration())
+	    named_object->func_declaration_value()->set_asm_name(asm_name);
+	}
     }
 
   // Check for the easy error of a newline before the opening brace.
@@ -2082,8 +2085,8 @@ 
 
   if (!this->peek_token()->is_op(OPERATOR_LCURLY))
     {
-      if (named_object == NULL)
-	named_object = this->gogo_->declare_function(name, fntype, location);
+      if (named_object == NULL && !Gogo::is_sink_name(name))
+	this->gogo_->declare_function(name, fntype, location);
     }
   else
     {