1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:27:59 -07:00

cmd/gc: fix ... escape analysis bug

If the ... element type contained no pointers,
then the escape analysis did not track the ... itself.
This manifested in an escaping ...byte being treated
as non-escaping.

Fixes #7934.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/100310043
This commit is contained in:
Russ Cox 2014-05-09 15:40:45 -04:00
parent 1848d71445
commit c99dce2b05
3 changed files with 23 additions and 9 deletions

View File

@ -903,6 +903,7 @@ esccall(EscState *e, Node *n, Node *up)
src->type = typ(TARRAY);
src->type->type = lr->n->type->type;
src->type->bound = count(ll);
src->type = ptrto(src->type); // make pointer so it will be tracked
src->escloopdepth = e->loopdepth;
src->lineno = n->lineno;
src->esc = EscNone; // until we find otherwise
@ -960,6 +961,7 @@ esccall(EscState *e, Node *n, Node *up)
src->type = typ(TARRAY);
src->type->type = t->type->type;
src->type->bound = count(ll);
src->type = ptrto(src->type); // make pointer so it will be tracked
src->esc = EscNone; // until we find otherwise
e->noesc = list(e->noesc, src);
n->right = src;

View File

@ -1012,7 +1012,7 @@ orderexpr(Node **np, Order *order)
// Allocate a temporary that will be cleaned up when this statement
// completes. We could be more aggressive and try to arrange for it
// to be cleaned up when the call completes.
n->alloc = ordertemp(n->type, order, 0);
n->alloc = ordertemp(n->type->type, order, 0);
}
break;

View File

@ -1399,3 +1399,15 @@ func foo149(l List) { // ERROR " l does not escape"
}
}
}
// issue 7934: missed ... if element type had no pointers
var save150 []byte
func foo150(x ...byte) { // ERROR "leaking param: x"
save150 = x
}
func bar150() {
foo150(1, 2, 3) // ERROR "[.][.][.] argument escapes to heap"
}