Patchwork Go patch committed: Don't crash if tuple init redefines non-variable

login
register
mail settings
Submitter Ian Taylor
Date Jan. 4, 2011, 9:15 p.m.
Message ID <mcr39p8pdzj.fsf@google.com>
Download mbox | patch
Permalink /patch/77528/
State New
Headers show

Comments

Ian Taylor - Jan. 4, 2011, 9:15 p.m.
This patch to the Go frontend avoids a crash if a tuple initializer is
used to define a variable, but the definition is erroneous because the
name is already defined as something other than a variable.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 0087a6ca3b8b go/parse.cc
--- a/go/parse.cc	Tue Jan 04 12:17:58 2011 -0800
+++ b/go/parse.cc	Tue Jan 04 13:12:50 2011 -0800
@@ -1655,9 +1655,15 @@ 
   if (!this->gogo_->in_global_scope())
     this->gogo_->add_statement(s);
   else if (!val_no->is_sink())
-    val_no->var_value()->add_preinit_statement(s);
+    {
+      if (val_no->is_variable())
+	val_no->var_value()->add_preinit_statement(s);
+    }
   else if (!no->is_sink())
-    no->var_value()->add_preinit_statement(s);
+    {
+      if (no->is_variable())
+	no->var_value()->add_preinit_statement(s);
+    }
   else
     {
       // Execute the map index expression just so that we can fail if
@@ -1716,9 +1722,15 @@ 
   if (!this->gogo_->in_global_scope())
     this->gogo_->add_statement(s);
   else if (!val_no->is_sink())
-    val_no->var_value()->add_preinit_statement(s);
+    {
+      if (val_no->is_variable())
+	val_no->var_value()->add_preinit_statement(s);
+    }
   else if (!no->is_sink())
-    no->var_value()->add_preinit_statement(s);
+    {
+      if (no->is_variable())
+	no->var_value()->add_preinit_statement(s);
+    }
   else
     {
       Named_object* dummy = this->create_dummy_global(Type::lookup_bool_type(),
@@ -1776,9 +1788,15 @@ 
   if (!this->gogo_->in_global_scope())
     this->gogo_->add_statement(s);
   else if (!val_no->is_sink())
-    val_no->var_value()->add_preinit_statement(s);
+    {
+      if (val_no->is_variable())
+	val_no->var_value()->add_preinit_statement(s);
+    }
   else if (!no->is_sink())
-    no->var_value()->add_preinit_statement(s);
+    {
+      if (no->is_variable())
+	no->var_value()->add_preinit_statement(s);
+    }
   else
     {
       Named_object* dummy = this->create_dummy_global(type, NULL, location);