diff mbox

Go patch committed: avoid infinite loop when reporting initialization loop

Message ID CAOyqgcVTcdK=YvT50=_bjD3LkVxZgkV0f7BechqJY_7O6UZ-+g@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 22, 2015, 5:11 p.m. UTC
This patch by Chris Manghane fixes the Go frontend to avoid an
infinite loop when reporting an initialization loop.  This is Go issue
7558.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r 4a641c29091f go/gogo.cc
--- a/go/gogo.cc	Wed Jan 21 20:07:40 2015 -0800
+++ b/go/gogo.cc	Thu Jan 22 08:43:48 2015 -0800
@@ -1089,6 +1089,7 @@ 
   // variable initializations that depend on it.
   typedef std::map<Var_init, std::set<Var_init*> > Init_deps;
   Init_deps init_deps;
+  bool init_loop = false;
   for (Var_inits::iterator p1 = var_inits->begin();
        p1 != var_inits->end();
        ++p1)
@@ -1137,14 +1138,15 @@ 
 			   p2var->message_name().c_str());
 		  inform(p2->var()->location(), "%qs defined here",
 			 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 (!init_deps.empty())
+  if (!init_deps.empty() && !init_loop)
     {
       // Otherwise, sort variable initializations by emitting all variables with
       // no dependencies in declaration order. VAR_INITS is already in