OSDN Git Service

compiler: Check for initialization loop in constant initializer.
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Feb 2012 19:27:27 +0000 (19:27 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 17 Feb 2012 19:27:27 +0000 (19:27 +0000)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184347 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/go/gofrontend/gogo-tree.cc

index 352179d..603b97e 100644 (file)
@@ -834,8 +834,15 @@ Gogo::write_globals()
              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