ref: 3ec895664e76bd357845402831cf41506a0b280d
parent: 118c93adea60980900d8976944f2eb05496783d2
author: Ori Bernstein <ori@markovcorp.com>
date: Mon Jul 31 06:35:24 EDT 2017
Move array size checking to verification. We don't necessarily know the type of the array index until after substituting, so things like sizeof() or constant folding may not work.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2031,9 +2031,6 @@
t->fixed = 1;
if (t->type == Tyarray) {
typesub(t->asize, noerr);
- t->asize = fold(t->asize, 1);
- if (t->asize && exprop(t->asize) != Olit)
- fatal(t->asize, "nonconstant array size near %s\n", ctxstr(t->asize));
} else if (t->type == Tystruct) {
inaggr++;
for (i = 0; i < t->nmemb; i++)
@@ -2593,6 +2590,7 @@
void
verify(Node *f)
{
+ Type *t;
Node *n;
size_t i;
@@ -2606,6 +2604,14 @@
fatal(n, "missing implementation for prototype '%s %s'",
namestr(n->impl.traitname), tystr(n->impl.type));
}
+ }
+ for (i = 0; i < ntypes; i++) {
+ t = types[i];
+ if (t->type != Tyarray)
+ continue;
+ t->asize = fold(t->asize, 1);
+ if (t->asize && exprop(t->asize) != Olit)
+ fatal(t->asize, "nonconstant array size near %s\n", ctxstr(t->asize));
}
}