Commit c458c983 authored by Ken Thompson's avatar Ken Thompson

[...] bug

R=r
OCL=22218
CL=22218
parent 855495ea
...@@ -836,3 +836,4 @@ void argspace(int32); ...@@ -836,3 +836,4 @@ void argspace(int32);
Node* nodarg(Type*, int); Node* nodarg(Type*, int);
void nodconst(Node*, Type*, vlong); void nodconst(Node*, Type*, vlong);
Type* deep(Type*); Type* deep(Type*);
Type* shallow(Type*);
...@@ -3556,38 +3556,44 @@ arraylit(Node *n) ...@@ -3556,38 +3556,44 @@ arraylit(Node *n)
Iter saver; Iter saver;
Type *t; Type *t;
Node *var, *r, *a, *nnew; Node *var, *r, *a, *nnew;
int idx, b; int idx, ninit, b;
t = n->type; t = n->type;
if(t->etype != TARRAY) if(t->etype != TARRAY)
fatal("arraylit: not array"); fatal("arraylit: not array");
// count initializers
ninit = 0;
r = listfirst(&saver, &n->left);
if(r != N && r->op == OEMPTY)
r = N;
while(r != N) {
ninit++;
r = listnext(&saver);
}
b = t->bound;
if(b == -100) {
// flag for [...]
b = ninit;
t = shallow(t);
t->bound = b;
}
var = nod(OXXX, N, N); var = nod(OXXX, N, N);
tempname(var, t); tempname(var, t);
b = t->bound; if(b < 0) {
if(b < 0 && b != -100) {
// slice // slice
nnew = nod(OMAKE, N, N); nnew = nod(OMAKE, N, N);
nnew->type = t; nnew->type = t;
a = nod(OAS, var, nnew); a = nod(OAS, var, nnew);
addtop = list(addtop, a); addtop = list(addtop, a);
} } else {
if(b >= 0) {
idx = 0;
r = listfirst(&saver, &n->left);
if(r != N && r->op == OEMPTY)
r = N;
while(r != N) {
// count initializers
idx++;
r = listnext(&saver);
}
// if entire array isnt initialized, // if entire array isnt initialized,
// then clear the array // then clear the array
if(idx < b) { if(ninit < b) {
a = nod(OAS, var, N); a = nod(OAS, var, N);
addtop = list(addtop, a); addtop = list(addtop, a);
} }
...@@ -3606,11 +3612,6 @@ arraylit(Node *n) ...@@ -3606,11 +3612,6 @@ arraylit(Node *n)
idx++; idx++;
r = listnext(&saver); r = listnext(&saver);
} }
if(b == -100) {
// compiler counted closed array
b = idx;
t->bound = b;
}
if(b < 0) if(b < 0)
nnew->left = nodintconst(idx); nnew->left = nodintconst(idx);
return var; return var;
......
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