]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix escape analysis ordering
authorRuss Cox <rsc@golang.org>
Tue, 25 Jun 2013 21:28:49 +0000 (17:28 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 25 Jun 2013 21:28:49 +0000 (17:28 -0400)
Functions without bodies were excluded from the ordering logic,
because when I wrote the ordering logic there was no reason to
analyze them.

But then we added //go:noescape tags that need analysis, and we
didn't update the ordering logic.

So in the absence of good ordering, //go:noescape only worked
if it appeared before the use in the source code.

Fixes #5773.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/10570043

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

index df273e39271609d737d5bfffe140eab0cbe65876..497645ab598c4d978d99cd66d2758b8d64f8f613 100644 (file)
@@ -144,7 +144,7 @@ visitcode(Node *n, uint32 min)
                fn = n->left;
                if(n->op == OCALLMETH)
                        fn = n->left->right->sym->def;
-               if(fn && fn->op == ONAME && fn->class == PFUNC && fn->defn && fn->defn->nbody)
+               if(fn && fn->op == ONAME && fn->class == PFUNC && fn->defn)
                        if((m = visit(fn->defn)) < min)
                                min = m;
        }
index ba88f4b3bfdae36650c4566b9c5543466c3b7d61..5122356bf9f6bfa6ff21c8b25ec3ce305410ab27 100644 (file)
@@ -1337,3 +1337,22 @@ func foo143() {
                }()
        }
 }
+
+// issue 5773
+// Check that annotations take effect regardless of whether they
+// are before or after the use in the source code.
+
+//go:noescape
+
+func foo144a(*int)
+
+func foo144() {
+       var x int
+       foo144a(&x) // ERROR "&x does not escape"
+       var y int
+       foo144b(&y) // ERROR "&y does not escape"
+}
+
+//go:noescape
+
+func foo144b(*int)