vcc: do not overwrite SUB symbol properties when call'ing

vcc_act_call() implements use-before-define semantics. To do so, it
needs to instantiate SUB symbols if they do not exist.

However, it wrongly called VCC_GlobalSymbol() also for existing
symbols, overwriting symbol properties.

In the case of the built-in subs, the symbol's lname (historically)
still is the unescaped literal name, while user defined subs have
their name escaped via VCC_GlobalSymbol() -> VCC_PrintCName().

This made the wrong call to VCC_GlobalSymbol() apparent when a
built-in sub was called with an explicit "call" action.

Besides fixing the VCC_GlobalSymbol() call, we also need to set the
lname and rname attributes for built-in SUB symbols initialized in
VCC_New().

Alternatively, we could also have used VCC_GlobalSymbol() there, but
that would have affected other places where we (still) rely on the
known name scheme of built-in subs, e.h. EmitStruct(). While the name
unifaction was nice in general, I found the necessary changes (look up
SUB symbols) not worth the benefit.

Fixes #3719
parent 1996366d
......@@ -92,9 +92,12 @@ varnish v1 -vcl {
sub vcl_backend_fetch {
debug.call(priv_top);
}
sub vcl_backend_response {
set beresp.status = 200;
}
sub vcl_backend_error {
# falling through to None backend would be success
set beresp.status = 200;
call vcl_backend_response;
return (deliver);
}
} -start
......
......@@ -52,16 +52,16 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
t0 = tl->t;
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_PARTIAL_NOERR,
XREF_REF);
if (sym == NULL)
if (sym == NULL) {
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE,
XREF_REF);
if (sym == NULL)
return;
if (sym == NULL)
return;
VCC_GlobalSymbol(sym, SUB);
}
if (sym->kind == SYM_SUB) {
vcc_AddCall(tl, t0, sym);
VCC_GlobalSymbol(sym, SUB);
Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname);
SkipToken(tl, ';');
......
......@@ -820,6 +820,7 @@ VCC_New(void)
struct vcc *tl;
struct symbol *sym;
struct proc *p;
struct vsb *vsb;
int i;
ALLOC_OBJ(tl, VCC_MAGIC);
......@@ -849,7 +850,25 @@ VCC_New(void)
SYM_MAIN, SYM_SUB, VCL_LOW, VCL_HIGH);
p = vcc_NewProc(tl, sym);
p->method = &method_tab[i];
VSB_printf(p->cname, "VGC_function_%s", p->method->name);
// see also VCC_GlobalSymbol()
vsb = VSB_new_auto();
AN(vsb);
VSB_printf(vsb, "%s_%s", SUB->global_pfx, p->method->name);
AZ(VSB_finish(vsb));
AZ(VSB_bcat(p->cname, VSB_data(vsb), VSB_len(vsb)));
sym->lname = strdup(VSB_data(vsb));
AN(sym->lname);
VSB_clear(vsb);
VSB_printf(vsb, "sub_%s", sym->lname);
AZ(VSB_finish(vsb));
sym->rname = strdup(VSB_data(vsb));
AN(sym->rname);
VSB_destroy(&vsb);
}
tl->sb = VSB_new_auto();
AN(tl->sb);
......
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