This Go frontend patch by Cherry Zhang fixes the loopdepth tracking in
array slicing expressions in escape analysis.  In the gc compiler, for
slicing an array, its AST has an implicit address operation node.
There isn't such a node in the gofrontend AST.  During escape
analysis, we create a fake node to mimic the gc compiler's behavior.
For the fake node, the loopdepth was not tracked correctly, causing
miscompilation.  Since this is an address operation, do the same thing
as we do for the address operator.  This fixes
https://golang.org/issue/36404.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to trunk and GCC 9 branch.

Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 279979)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-6fa9657df508ff4d7760cf1abfad3611ba808561
+e0790a756e9ba77e2d3d6ef5d0abbb11dd71211b
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/escape.cc
===================================================================
--- gcc/go/gofrontend/escape.cc (revision 279815)
+++ gcc/go/gofrontend/escape.cc (working copy)
@@ -1906,7 +1906,8 @@ Escape_analysis_assign::expression(Expre
             this->context_->track(addr_node);
 
             Node::Escape_state* addr_state = addr_node->state(this->context_, 
NULL);
-            addr_state->loop_depth = array_state->loop_depth;
+            if (array_state->loop_depth != 0)
+              addr_state->loop_depth = array_state->loop_depth;
           }
       }
       break;

Reply via email to