This patch from Rémy Oudompheng avoids an infinite recursion in the Go
frontend when evaluating a string constant. It avoids a compiler crash
on invalid code like
const f, g = g, f
func S() []byte { return []byte(f) }
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.7 branch.
Ian
diff -r 3271745b0eb0 go/expressions.cc
--- a/go/expressions.cc Wed Apr 04 11:49:50 2012 -0700
+++ b/go/expressions.cc Mon Apr 16 15:57:40 2012 -0700
@@ -2403,8 +2403,7 @@
do_numeric_constant_value(Numeric_constant* nc) const;
bool
- do_string_constant_value(std::string* val) const
- { return this->constant_->const_value()->expr()->string_constant_value(val); }
+ do_string_constant_value(std::string* val) const;
Type*
do_type();
@@ -2514,6 +2513,21 @@
return r;
}
+bool
+Const_expression::do_string_constant_value(std::string* val) const
+{
+ if (this->seen_)
+ return false;
+
+ Expression* e = this->constant_->const_value()->expr();
+
+ this->seen_ = true;
+ bool ok = e->string_constant_value(val);
+ this->seen_ = false;
+
+ return ok;
+}
+
// Return the type of the const reference.
Type*