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.
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