Don't crash lowering self-referential variable initializer.

From-SVN: r170194
This commit is contained in:
Ian Lance Taylor 2011-02-15 19:34:33 +00:00
parent 1c4a5fc8ca
commit 72f812a2b5
1 changed files with 17 additions and 1 deletions

View File

@ -1139,13 +1139,17 @@ class Lower_parse_tree : public Traverse
{
public:
Lower_parse_tree(Gogo* gogo, Named_object* function)
: Traverse(traverse_constants
: Traverse(traverse_variables
| traverse_constants
| traverse_functions
| traverse_statements
| traverse_expressions),
gogo_(gogo), function_(function), iota_value_(-1)
{ }
int
variable(Named_object*);
int
constant(Named_object*, bool);
@ -1167,6 +1171,18 @@ class Lower_parse_tree : public Traverse
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.