diff options
| author | Russ Cox <rsc@golang.org> | 2009-10-19 21:10:29 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-10-19 21:10:29 -0700 |
| commit | 44cf55ce6fcd270c44987b45a6ae0bd829cffa35 (patch) | |
| tree | 558a24096bb6e0aeceb8e9f756bd41a01a0a7e7b /src/cmd/gc/subr.c | |
| parent | f8efa6a67cab7b25f64421c27a2f2d822361a20e (diff) | |
| download | golang-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.c | 29 |
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) { |
