Commit 6e436286 by Ian Lance Taylor

compiler: Avoid infinite recursion when describing initialization loops.

Fixes infinite recursion from golang/go#7558.

From-SVN: r220009
parent f77107e8
...@@ -1089,6 +1089,7 @@ sort_var_inits(Gogo* gogo, Var_inits* var_inits) ...@@ -1089,6 +1089,7 @@ sort_var_inits(Gogo* gogo, Var_inits* var_inits)
// variable initializations that depend on it. // variable initializations that depend on it.
typedef std::map<Var_init, std::set<Var_init*> > Init_deps; typedef std::map<Var_init, std::set<Var_init*> > Init_deps;
Init_deps init_deps; Init_deps init_deps;
bool init_loop = false;
for (Var_inits::iterator p1 = var_inits->begin(); for (Var_inits::iterator p1 = var_inits->begin();
p1 != var_inits->end(); p1 != var_inits->end();
++p1) ++p1)
...@@ -1137,14 +1138,15 @@ sort_var_inits(Gogo* gogo, Var_inits* var_inits) ...@@ -1137,14 +1138,15 @@ sort_var_inits(Gogo* gogo, Var_inits* var_inits)
p2var->message_name().c_str()); p2var->message_name().c_str());
inform(p2->var()->location(), "%qs defined here", inform(p2->var()->location(), "%qs defined here",
p2var->message_name().c_str()); p2var->message_name().c_str());
p2 = var_inits->end(); init_loop = true;
break;
} }
} }
} }
} }
// If there are no dependencies then the declaration order is sorted. // If there are no dependencies then the declaration order is sorted.
if (!init_deps.empty()) if (!init_deps.empty() && !init_loop)
{ {
// Otherwise, sort variable initializations by emitting all variables with // Otherwise, sort variable initializations by emitting all variables with
// no dependencies in declaration order. VAR_INITS is already in // no dependencies in declaration order. VAR_INITS is already in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment