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: Don't crash on self-referential initializer


This patch to the Go frontend avoids a crash when a variable initializer
erroneously refers to the variable itself.  We already avoided many such
crashes, but not in cases where lowering the initializer changes the
initializer itself.  This patch fixes cases like that.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r e33f8e5aa641 go/gogo.cc
--- a/go/gogo.cc	Tue Feb 15 11:05:24 2011 -0800
+++ b/go/gogo.cc	Tue Feb 15 11:30:28 2011 -0800
@@ -1139,7 +1139,8 @@
 {
  public:
   Lower_parse_tree(Gogo* gogo, Named_object* function)
-    : Traverse(traverse_constants
+    : Traverse(traverse_variables
+	       | traverse_constants
 	       | traverse_functions
 	       | traverse_statements
 	       | traverse_expressions),
@@ -1147,6 +1148,9 @@
   { }
 
   int
+  variable(Named_object*);
+
+  int
   constant(Named_object*, bool);
 
   int
@@ -1167,6 +1171,18 @@
   int iota_value_;
 };
 
+// Lower variables.  We handle variables specially to break loops in
+// which a variable initialization expression refers to itself.  The
+// loop breaking is in lower_init_expression.
+
+int
+Lower_parse_tree::variable(Named_object* no)
+{
+  if (no->is_variable())
+    no->var_value()->lower_init_expression(this->gogo_, this->function_);
+  return TRAVERSE_CONTINUE;
+}
+
 // Lower constants.  We handle constants specially so that we can set
 // the right value for the predeclared constant iota.  This works in
 // conjunction with the way we lower Const_expression objects.

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