]> Cypherpunks repositories - gostls13.git/commit
cmd/gc: fix &result escaping into result
authorRuss Cox <rsc@golang.org>
Wed, 11 Jun 2014 18:21:06 +0000 (14:21 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 11 Jun 2014 18:21:06 +0000 (14:21 -0400)
commitf20e4d5ecb87cae4846be07a68cb0e9132e6a8c6
tree1f523a0249a583c073852daac5bc718d27b4a0a5
parentbe91bc29a43ae582b6ca7f6adf561cfb25bd6911
cmd/gc: fix &result escaping into result

There is a hierarchy of location defined by loop depth:

        -1 = the heap
        0 = function results
        1 = local variables (and parameters)
        2 = local variable declared inside a loop
        3 = local variable declared inside a loop inside a loop
        etc

In general if an address from loopdepth n is assigned to
something in loop depth m < n, that indicates an extended
lifetime of some form that requires a heap allocation.

Function results can be local variables too, though, and so
they don't actually fit into the hierarchy very well.
Treat the address of a function result as level 1 so that
if it is written back into a result, the address is treated
as escaping.

Fixes #8185.

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/108870044
src/cmd/gc/esc.c
test/escape2.go