summaryrefslogtreecommitdiff
path: root/src/cmd/gc/subr.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-19 21:10:29 -0700
committerRuss Cox <rsc@golang.org>2009-10-19 21:10:29 -0700
commit44cf55ce6fcd270c44987b45a6ae0bd829cffa35 (patch)
tree558a24096bb6e0aeceb8e9f756bd41a01a0a7e7b /src/cmd/gc/subr.c
parentf8efa6a67cab7b25f64421c27a2f2d822361a20e (diff)
downloadgolang-44cf55ce6fcd270c44987b45a6ae0bd829cffa35.tar.gz
bug196
R=ken OCL=35905 CL=35905
Diffstat (limited to 'src/cmd/gc/subr.c')
-rw-r--r--src/cmd/gc/subr.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c
index 819ebd51c..e65ce5551 100644
--- a/src/cmd/gc/subr.c
+++ b/src/cmd/gc/subr.c
@@ -2346,7 +2346,7 @@ staticname(Type *t)
}
/*
- * return side effect-free n, appending side effects to init.
+ * return side effect-free, assignable n, appending side effects to init.
*/
Node*
saferef(Node *n, NodeList **init)
@@ -2387,6 +2387,33 @@ saferef(Node *n, NodeList **init)
return N;
}
+/*
+ * return side effect-free n, appending side effects to init.
+ */
+Node*
+safeval(Node *n, NodeList **init)
+{
+ Node *l;
+ Node *r;
+ Node *a;
+
+ // is this a local variable or a dot of a local variable?
+ for(l=n; l->op == ODOT; l=l->left)
+ if(l->left->type != T && isptr[l->left->type->etype])
+ goto copy;
+ if(l->op == ONAME && (l->class == PAUTO || l->class == PPARAM))
+ return n;
+
+copy:
+ l = nod(OXXX, N, N);
+ tempname(l, n->type);
+ a = nod(OAS, l, n);
+ typecheck(&a, Etop);
+ walkexpr(&a, init);
+ *init = list(*init, a);
+ return l;
+}
+
void
setmaxarg(Type *t)
{