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

login
register
mail settings
Submitter Ian Taylor
Date Oct. 4, 2011, 11:16 p.m.
Message ID <mcr1uusny98.fsf@coign.corp.google.com>
Download mbox | patch
Permalink /patch/117712/
State New
Headers show

Comments

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;
 }