int iscomposite(Type*);
Node* callnew(Type*);
Node* saferef(Node*, NodeList**);
+Node* safeval(Node*, NodeList**);
int is64(Type*);
int noconv(Type*, Type*);
NodeList* list1(Node*);
}
/*
- * 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)
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)
{
mapop(Node *n, NodeList **init)
{
Node *r, *a;
- Type *t;
r = n;
switch(n->op) {
case OASOP:
// rewrite map[index] op= right
// into tmpi := index; map[tmpi] = map[tmpi] op right
- // TODO(rsc): does this double-evaluate map?
- t = n->left->left->type;
- a = nod(OXXX, N, N);
- tempname(a, t->down); // tmpi
- r = nod(OAS, a, n->left->right); // tmpi := index
- n->left->right = a; // m[tmpi]
- typecheck(&r, Etop);
- walkexpr(&r, init);
- *init = list(*init, r);
+ // make it ok to double-evaluate map[tmpi]
+ n->left->left = safeval(n->left->left, init);
+ n->left->right = safeval(n->left->right, init);
a = nod(OXXX, N, N);
*a = *n->left; // copy of map[tmpi]
=========== bugs/bug193.go
BUG: errchk: bugs/bug193.go:14: missing expected error: 'shift'
-
-=========== bugs/bug196.go
-too many calls: 5
-panic PC=xxx
-BUG: bug196