diff options
author | Ori Bernstein <ori@markovcorp.com> | 2017-07-31 10:35:24 -0700 |
---|---|---|
committer | Ori Bernstein <ori@markovcorp.com> | 2017-07-31 10:35:24 -0700 |
commit | 3ec895664e76bd357845402831cf41506a0b280d (patch) | |
tree | 94f50fc533aec928535958414570618b028f5dfa | |
parent | 118c93adea60980900d8976944f2eb05496783d2 (diff) | |
download | mc-3ec895664e76bd357845402831cf41506a0b280d.tar.gz |
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.
-rw-r--r-- | parse/infer.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/parse/infer.c b/parse/infer.c index 67db28f..6c7a1a2 100644 --- a/parse/infer.c +++ b/parse/infer.c @@ -2031,9 +2031,6 @@ tyfix(Node *ctx, Type *orig, int noerr) 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 @@ applytraits(Node *f) void verify(Node *f) { + Type *t; Node *n; size_t i; @@ -2607,6 +2605,14 @@ verify(Node *f) 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)); + } } void |