Go patch committed: Fix global var init to call with calls as args

Message ID mcr1uusny98.fsf@coign.corp.google.com
State New
Headers show

Commit Message

Ian Taylor Oct. 4, 2011, 11:16 p.m.
The Go frontend had a bug when initializing a global variable to a
function call when some of the arguments to the call were themselves
function calls.  The code which enforces function call ordering was
accidentally causing the outermost function to be called twice.  This
patch fixes the bug.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 50541425d168 go/gogo.cc
--- a/go/gogo.cc	Wed Sep 28 06:13:03 2011 -0700
+++ b/go/gogo.cc	Tue Oct 04 16:13:56 2011 -0700
@@ -2063,6 +2063,8 @@ 
       return TRAVERSE_SKIP_COMPONENTS;
     }
 
+  Expression* orig_init = init;
+
   for (Find_eval_ordering::const_iterator p = find_eval_ordering.begin();
        p != find_eval_ordering.end();
        ++p)
@@ -2087,6 +2089,9 @@ 
       var->add_preinit_statement(this->gogo_, s);
     }
 
+  if (init != orig_init)
+    var->set_init(init);
+
   return TRAVERSE_SKIP_COMPONENTS;
 }