From 2dfc736cc774d78991712e80940446fc448d03ac Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 16 Apr 2012 23:05:40 +0000 Subject: [PATCH] compiler: fix infinite recursion in string constant evaluation. Fixes compilation of incorrect code: const f, g = g, f func S() []byte { return []byte(f) } The problem was already handled for numerical constants. Part of issue 3186 (go). From-SVN: r186511 --- gcc/go/gofrontend/expressions.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index baff0c9a5d9..6ff071860aa 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -2403,8 +2403,7 @@ class Const_expression : public Expression 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 @@ Const_expression::do_numeric_constant_value(Numeric_constant* nc) const 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*