This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Check for initialization loop in constant init


In Go it is possible to have an initialization loop in a constant
initializer, if the initializer is a function pointer.  This patch adds
that check to the gccgo frontend.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r e19e56d17d8c go/gogo-tree.cc
--- a/go/gogo-tree.cc	Fri Feb 17 07:42:24 2012 -0800
+++ b/go/gogo-tree.cc	Fri Feb 17 11:02:24 2012 -0800
@@ -834,8 +834,15 @@
 	      else if (init == NULL_TREE)
 		;
 	      else if (TREE_CONSTANT(init))
-		this->backend()->global_variable_set_init(var,
-							  tree_to_expr(init));
+		{
+		  if (expression_requires(no->var_value()->init(), NULL, no))
+		    error_at(no->location(),
+			     "initialization expression for %qs depends "
+			     "upon itself",
+			     no->message_name().c_str());
+		  this->backend()->global_variable_set_init(var,
+							    tree_to_expr(init));
+		}
 	      else if (is_sink)
 		var_init_tree = init;
 	      else

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]