Commit 6f14cada authored by Russ Cox's avatar Russ Cox

gc: walk pointer in range on slice/array

R=ken2
https://golang.org/cl/166071
parent 7c4aeec8
...@@ -90,6 +90,7 @@ walkrange(Node *n) ...@@ -90,6 +90,7 @@ walkrange(Node *n)
{ {
Node *ohv1, *hv1, *hv2; // hidden (old) val 1, 2 Node *ohv1, *hv1, *hv2; // hidden (old) val 1, 2
Node *ha, *hit; // hidden aggregate, iterator Node *ha, *hit; // hidden aggregate, iterator
Node *hn, *hp; // hidden len, pointer
Node *a, *v1, *v2; // not hidden aggregate, val 1, 2 Node *a, *v1, *v2; // not hidden aggregate, val 1, 2
Node *fn, *tmp; Node *fn, *tmp;
NodeList *body, *init; NodeList *body, *init;
...@@ -122,16 +123,32 @@ walkrange(Node *n) ...@@ -122,16 +123,32 @@ walkrange(Node *n)
case TARRAY: case TARRAY:
hv1 = nod(OXXX, N, n); hv1 = nod(OXXX, N, n);
tempname(hv1, types[TINT]); tempname(hv1, types[TINT]);
hn = nod(OXXX, N, N);
tempname(hn, types[TINT]);
hp = nil;
init = list(init, nod(OAS, hv1, N)); init = list(init, nod(OAS, hv1, N));
n->ntest = nod(OLT, hv1, nod(OLEN, ha, N)); init = list(init, nod(OAS, hn, nod(OLEN, ha, N)));
if(v2) {
hp = nod(OXXX, N, N);
tempname(hp, ptrto(a->type->type));
tmp = nod(OINDEX, ha, nodintconst(0));
tmp->etype = 1; // no bounds check
init = list(init, nod(OAS, hp, nod(OADDR, tmp, N)));
}
n->ntest = nod(OLT, hv1, hn);
n->nincr = nod(OASOP, hv1, nodintconst(1)); n->nincr = nod(OASOP, hv1, nodintconst(1));
n->nincr->etype = OADD; n->nincr->etype = OADD;
body = list1(nod(OAS, v1, hv1)); body = list1(nod(OAS, v1, hv1));
if(v2) { if(v2) {
tmp = nod(OINDEX, ha, hv1); body = list(body, nod(OAS, v2, nod(OIND, hp, N)));
tmp->etype = 1; // no bounds check tmp = nod(OADD, hp, nodintconst(t->type->width));
body = list(body, nod(OAS, v2, tmp)); tmp->type = hp->type;
tmp->typecheck = 1;
tmp->right->type = types[tptr];
tmp->right->typecheck = 1;
body = list(body, nod(OAS, hp, tmp));
} }
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment