summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-04-12 14:28:27 -0700
committerRuss Cox <rsc@golang.org>2010-04-12 14:28:27 -0700
commit22ccd9d4a41e63b10160cb21c39d38b63e333533 (patch)
tree8495023152320a66e2cf2ad27f4d33473009c7d6 /src
parent561ba3b677f43ed2ff93e2a6100f902534ead562 (diff)
downloadgolang-22ccd9d4a41e63b10160cb21c39d38b63e333533.tar.gz
gc: zero unnamed return values on entry if func has defer
R=ken2 CC=golang-dev http://codereview.appspot.com/891050
Diffstat (limited to 'src')
-rw-r--r--src/cmd/gc/walk.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c
index 34ac32436..5768285b8 100644
--- a/src/cmd/gc/walk.c
+++ b/src/cmd/gc/walk.c
@@ -2312,7 +2312,7 @@ reorder4(NodeList *ll)
* copies of escaped parameters to the heap.
*/
NodeList*
-paramstoheap(Type **argin)
+paramstoheap(Type **argin, int out)
{
Type *t;
Iter savet;
@@ -2322,6 +2322,12 @@ paramstoheap(Type **argin)
nn = nil;
for(t = structfirst(&savet, argin); t != T; t = structnext(&savet)) {
v = t->nname;
+ if(v == N && out && hasdefer) {
+ // Defer might stop a panic and show the
+ // return values as they exist at the time of panic.
+ // Make sure to zero them on entry to the function.
+ nn = list(nn, nod(OAS, nodarg(t, 1), N));
+ }
if(v == N || !(v->class & PHEAP))
continue;
@@ -2366,9 +2372,9 @@ heapmoves(void)
{
NodeList *nn;
- nn = paramstoheap(getthis(curfn->type));
- nn = concat(nn, paramstoheap(getinarg(curfn->type)));
- nn = concat(nn, paramstoheap(getoutarg(curfn->type)));
+ nn = paramstoheap(getthis(curfn->type), 0);
+ nn = concat(nn, paramstoheap(getinarg(curfn->type), 0));
+ nn = concat(nn, paramstoheap(getoutarg(curfn->type), 1));
curfn->enter = concat(curfn->enter, nn);
curfn->exit = returnsfromheap(getoutarg(curfn->type));
}