summaryrefslogtreecommitdiff
path: root/mi
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-11 22:20:11 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-11 22:20:11 -0800
commite9a476ebae14c3d6a806bddc1b7514b60a846fc4 (patch)
tree3ef4b7eb6e6b609d04e872b9e81887bc669512a5 /mi
parentd21cc40703f9e3fb86e590fce62ee0847fc6cfd8 (diff)
downloadmc-e9a476ebae14c3d6a806bddc1b7514b60a846fc4.tar.gz
Fix code to disallow use before definition.
At least in some cases.
Diffstat (limited to 'mi')
-rw-r--r--mi/dfcheck.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/mi/dfcheck.c b/mi/dfcheck.c
index a83f1db..392c8dd 100644
--- a/mi/dfcheck.c
+++ b/mi/dfcheck.c
@@ -23,6 +23,8 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
return;
if (exprop(n) == Ovar) {
did = n->expr.did;
+ if (decls[did]->decl.isconst)
+ return;
for (j = 0; j < r->ndefs[did]; j++) {
t = tybase(exprtype(n));
if (t->type == Tystruct || t->type == Tyunion || t->type == Tyarray || t->type == Tytuple)
@@ -33,7 +35,7 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
continue;
def = nodes[r->defs[did][j]];
if (exprop(def) == Oundef)
- fatal(n, "%s used before definition", namestr(n->expr.args[0]));
+ fatal(n, "%s used before definition [%d]", namestr(n->expr.args[0]), (int)did);
}
} else {
switch (exprop(n)) {
@@ -44,7 +46,7 @@ static void checkundef(Node *n, Reaching *r, Bitset *reach, Bitset *kill)
break;
case Oaddr:
case Oslice:
- /* these don't actually look at the of args[0], so they're ok. */
+ /* these don't actually look at the value of args[0], so they're ok. */
for (i = 1; i < n->expr.nargs; i++)
checkundef(n->expr.args[i], r, reach, kill);
break;
@@ -127,5 +129,5 @@ static void checkret(Cfg *cfg)
void check(Cfg *cfg)
{
checkret(cfg);
- if(0) checkreach(cfg);
+ checkreach(cfg);
}