Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

assertion failure for duplicated label definitions

6 views
Skip to first unread message

Jun Woong

unread,
May 19, 2011, 2:53:46 AM5/19/11
to
Because lcc allowing a label installed twice, one of its assertions
may fail while marking a label as equivalent to another. Consider the
following code:

int main(void)
{
L1:
goto L2;
L1: /* invalid */
goto L3;
{
L2:
func();
L3:
func();
}
}

lcc says:
> 5: redefinition of label `L1' previously defined at 3
> rcc: src/stmt.c:610: equatelab: Assertion `old->u.l.equatedto == ((void *)0)' failed.
> Aborted

Meeting the definition of L1 twice, lcc barks at the second one but
still installs it. equatedto() that builds up a list of equivalent
labels asserts that a label definition appear only once, and that
assertion does not hold when trying to mark L1 again on "goto L3."

This problem can be fixed by
- modifying definelab() so that it avoid planting a label twice; or
- simply dropping the assert() in question from equatedto().


Thanks.

jacob navia

unread,
May 20, 2011, 1:42:34 PM5/20/11
to
Le 19/05/11 08:53, Jun Woong a écrit :

I changed stmtlabel in lcc-win to
static void stmtlabel(void)
{
Symbol p = lookup(token, stmtlabs);

if (p == NULL) {
p = install(token, &stmtlabs, 0, FUNC);
p->scope = LABELS;
p->u.l.label = genlabel(1);
p->src = src;
}
if (p->defined)
RedefinitionDiagnostic(p, REDEFINITION_LABEL|REDEFINITION_ERROR );
else {
p->defined = 1;
definelab(p->u.l.label);
}
t = gettok();
expect(':');
}

Now your program provokes the following diagnostics:
Error tlab.c: 5 redefinition of label 'L1'
Error tlab.c: 3 Previous definition of 'L1' here
Warning tlab.c: 9 missing prototype for func
Warning tlab.c: 9 Missing prototype for 'func'
Warning tlab.c: 11 Missing prototype for 'func'
2 errors, 3 warnings

I have rewritten anyway the error reporting to make clearer to the
user what is going on.

Thanks for your message

jacob

0 new messages