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 if constant refers to itself


This patch fixes another case in the Go frontend where a constant refers
to itself.  If we need the type of a constant while it is being lowered,
then we have an invalid recursive reference.  This patch detects that
case rather than crashing by trying to get the type of the initializer
which has not yet been lowered.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r f22ca4fe9909 go/expressions.cc
--- a/go/expressions.cc	Tue Dec 21 22:17:16 2010 -0800
+++ b/go/expressions.cc	Tue Dec 21 22:24:46 2010 -0800
@@ -2528,7 +2528,9 @@
   if (this->type_ != NULL)
     return this->type_;
 
-  if (this->seen_)
+  Named_constant* nc = this->constant_->const_value();
+
+  if (this->seen_ || nc->lowering())
     {
       this->report_error(_("constant refers to itself"));
       this->type_ = Type::make_error_type();
@@ -2537,7 +2539,6 @@
 
   this->seen_ = true;
 
-  Named_constant* nc = this->constant_->const_value();
   Type* ret = nc->type();
 
   if (ret != NULL)
diff -r f22ca4fe9909 go/gogo.cc
--- a/go/gogo.cc	Tue Dec 21 22:17:16 2010 -0800
+++ b/go/gogo.cc	Tue Dec 21 22:24:46 2010 -0800
@@ -1163,8 +1163,8 @@
 {
   Named_constant* nc = no->const_value();
 
-  // We can recursively a constant if the initializer expression
-  // manages to refer to itself.
+  // Don't get into trouble if the constant's initializer expression
+  // refers to the constant itself.
   if (nc->lowering())
     return TRAVERSE_CONTINUE;
   nc->set_lowering();

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