summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-07-06 23:42:57 -0700
committerRuss Cox <rsc@golang.org>2009-07-06 23:42:57 -0700
commit84fcade90acd893ef30b1353d73d84584fcd5bb8 (patch)
tree291df7b3c11db466dd45cb82f1f45b905700f555
parent50501ef24e74e190e9c48646050205d02e2903dd (diff)
downloadgolang-84fcade90acd893ef30b1353d73d84584fcd5bb8.tar.gz
insert ODCL in type switch case.
needed for heap allocation if variable escapes. package main func main(){ var i interface{} = 42; switch v := i.(type) { case int: println(&v, v); } } R=ken OCL=31245 CL=31245
-rw-r--r--src/cmd/gc/swt.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cmd/gc/swt.c b/src/cmd/gc/swt.c
index 6ea8c9628..4347eeac9 100644
--- a/src/cmd/gc/swt.c
+++ b/src/cmd/gc/swt.c
@@ -680,9 +680,11 @@ static Node* boolname;
Node*
typeone(Node *t)
{
- Node *a, *b;
+ Node *a, *b, *dcl;
a = t->left->left; // var
+ dcl = nod(ODCL, a, N);
+
a = nod(OLIST, a, boolname); // var,bool
b = nod(ODOTTYPE, facename, N);
@@ -693,7 +695,7 @@ typeone(Node *t)
b = nod(OIF, N, N);
b->ntest = boolname;
b->nbody = t->right; // if bool { goto l }
- return list(a, b);
+ return list(list(dcl, a), b);
}
Node*