Commit eb592d82 authored by Russ Cox's avatar Russ Cox

cmd/gc: do not follow uintptr passed as function argument

The escape analysis works by tracing assignment paths from
variables that start with pointer type, or addresses of variables
(addresses are always pointers).  It does allow non-pointers
in the path, so that in this code it sees x's value escape into y:

        var x *[10]int
        y := (*int)(unsafe.Pointer(uintptr(unsafe.Pointer(x))+32))

It must allow uintptr in order to see through this kind of
"pointer arithmetic".

It also traces such values if they end up as uintptrs passed to
functions. This used to be important because packages like
encoding/gob passed around uintptrs holding real pointers.

The introduction of precise collection of stacks has forced
code to be more honest about which declared stack variables
hold pointers and which do not. In particular, the garbage
collector no longer sees pointers stored in uintptr variables.
Because of this, packages like encoding/gob have been fixed.

There is not much point in the escape analysis accepting
uintptrs as holding pointers at call boundaries if the garbage
collector does not.

Excluding uintptr-valued arguments brings the escape
analysis in line with the garbage collector and has the
useful side effect of making arguments to syscall.Syscall
not appear to escape.

That is, this CL should yield the same benefits as
CL 45930043 (rolled back in CL 53870043), but it does
so by making uintptrs less special, not more.

R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/53940043
parent 8027660a
......@@ -916,8 +916,12 @@ esccall(EscState *e, Node *n)
// print("esc analyzed fn: %#N (%+T) returning (%+H)\n", fn, fntype, n->escretval);
// Receiver.
if(n->op != OCALLFUNC)
escassignfromtag(e, getthisx(fntype)->type->note, n->escretval, n->left->left);
if(n->op != OCALLFUNC) {
t = getthisx(fntype)->type;
src = n->left->left;
if(haspointers(t->type))
escassignfromtag(e, t->note, n->escretval, src);
}
for(t=getinargx(fntype)->type; ll; ll=ll->next) {
src = ll->n;
......@@ -930,6 +934,7 @@ esccall(EscState *e, Node *n)
e->noesc = list(e->noesc, src);
n->right = src;
}
if(haspointers(t->type))
escassignfromtag(e, t->note, n->escretval, src);
if(src != ll->n)
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment