summaryrefslogtreecommitdiff
path: root/parse/stab.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-21 00:31:56 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-21 00:31:56 -0800
commit3792aa38235a273f449d25c4fe813de01bce3093 (patch)
tree504ab56b2997110a9ff37a20f508f97ce94d30d6 /parse/stab.c
parent3435783cac36d00e147a7cc6f76cf2fa9d484cc4 (diff)
downloadmc-3792aa38235a273f449d25c4fe813de01bce3093.tar.gz
Add labels before linking them up.
Forward jumps were broken since we were looking up labels before adding them. Oops.
Diffstat (limited to 'parse/stab.c')
-rw-r--r--parse/stab.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/parse/stab.c b/parse/stab.c
index 9da49dc..2d55f99 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -114,6 +114,7 @@ Stab *mkstab(int isfunc)
st->lbl = mkht(strhash, streq);
}
st->impl = mkht(implhash, impleq);
+ st->isfunc = isfunc;
return st;
}
@@ -182,7 +183,7 @@ Node *getdcl(Stab *st, Node *n)
void putlbl(Stab *st, char *name, Node *lbl)
{
- while (!st->isfunc && st->super)
+ while (st && !st->isfunc)
st = st->super;
if (!st)
fatal(lbl, "label %s defined outside function\n", name);
@@ -193,10 +194,10 @@ void putlbl(Stab *st, char *name, Node *lbl)
Node *getlbl(Stab *st, Srcloc loc, char *name)
{
- while (!st->isfunc && st->super)
+ while (st && !st->isfunc)
st = st->super;
if (!st || !hthas(st->lbl, name))
- lfatal(loc, "unable to find label %s in function scope\n", name);
+ return NULL;
return htget(st->lbl, name);
}