]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix arm build
authorRuss Cox <rsc@golang.org>
Mon, 29 Aug 2011 03:29:34 +0000 (23:29 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 29 Aug 2011 03:29:34 +0000 (23:29 -0400)
Escape analysis was incorrectly assuming that
functions without bodies don't leak their
parameters.  This meant that sync/atomic's
TestAddInt64 was allocating x on its stack,
and then x was not properly aligned for use
with the atomic 64-bit instructions.  Obviously
we should figure out the alignment story on 5g
too, but this fix is correct and should restore the
build to 'ok'.

TBR=lvd
CC=golang-dev
https://golang.org/cl/4964047

src/cmd/gc/esc.c
test/escape2.go

index 3a28a8ba73b2568ee7638caefd6676ee33a6a41d..8664dc606aec4134af2a0d1989f15440fff09fb2 100644 (file)
@@ -505,7 +505,7 @@ esccall(Node *n)
                }
        }
                        
-       if(fn && fn->op == ONAME && fn->class == PFUNC && fn->ntype) {
+       if(fn && fn->op == ONAME && fn->class == PFUNC && fn->defn && fn->defn->nbody && fn->ntype) {
                // Local function.  Incorporate into flow graph.
 
                // Receiver.
@@ -696,6 +696,10 @@ esctag(Node *func)
 {
        Node *savefn;
        NodeList *ll;
+       
+       // External functions must be assumed unsafe.
+       if(func->nbody == nil)
+               return;
 
        savefn = curfn;
        curfn = func;
index 24a88f751eae4ad6208876eda8b15c4c86ffc343..0b78624b6c8dd03c859b7c6ae4107b7f17d3525d 100644 (file)
@@ -774,3 +774,9 @@ func foo118(unknown func(*int)) {  // ERROR "unknown does not escape"
        x := 1 // ERROR "moved to heap: NAME-x"
        unknown(&x) // ERROR "&x escapes to heap"
 }
+
+func external(*int)
+
+func foo119(x *int) {  // ERROR "leaking param: NAME-x"
+       external(x)
+}