Commit b3484a49 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Catch redefinition of non-method sub's early.

parent 1a5b7fd0
varnishtest "Test sub redefinition"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend { } -start
varnish v1 -badvcl {
backend foo { .host = "127.0.0.1"; }
sub c1 { }
sub c1 { }
sub vcl_recv { call c1; }
}
......@@ -310,7 +310,7 @@ void vcc_VarVal(struct vcc *tl, const struct var *vp,
void vcc_ParseImport(struct vcc *tl);
/* vcc_xref.c */
void vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
int vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
void vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind type);
int vcc_CheckReferences(struct vcc *tl);
......
......@@ -194,7 +194,7 @@ vcc_Compound(struct vcc *tl)
static void
vcc_Function(struct vcc *tl)
{
int m;
int m, i;
vcc_NextToken(tl);
ExpectErr(tl, ID);
......@@ -214,7 +214,13 @@ vcc_Function(struct vcc *tl)
Fb(tl, 0, " */\n");
} else {
tl->fb = tl->fc;
vcc_AddDef(tl, tl->t, SYM_SUB);
i = vcc_AddDef(tl, tl->t, SYM_SUB);
if (i > 1) {
vsb_printf(tl->sb,
"Function %.*s redefined\n", PF(tl->t));
vcc_ErrWhere(tl, tl->t);
return;
}
tl->curproc = vcc_AddProc(tl, tl->t);
Fh(tl, 0, "static int VGC_function_%.*s (struct sess *sp);\n",
PF(tl->t));
......
......@@ -87,7 +87,7 @@ vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind kind)
sym->nref++;
}
void
int
vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind)
{
struct symbol *sym;
......@@ -95,6 +95,7 @@ vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind)
sym = VCC_GetSymbolTok(tl, t, kind);
AN(sym);
sym->ndef++;
return (sym->ndef);
}
/*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment