[master] f53ae41f2 vcc: Run compile time recursion check also on dynamic-only SUBs

Nils Goroll nils.goroll at uplex.de
Mon Feb 8 17:52:04 UTC 2021


commit f53ae41f2bf21293521c1b474f0c9f38d3317879
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sat Jan 30 20:24:27 2021 +0100

    vcc: Run compile time recursion check also on dynamic-only SUBs
    
    We previously missed to run the static recursion check on SUBs which
    are only referenced symbolically (and thus might be called
    dynamically).
    
    This changes the error reporting tested in v00021.vtc because the
    recursion is detected on the recursing subs alone before the call tree
    from vcl_recv {} is walked.

diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index 720ff8ca5..74bb36509 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -49,11 +49,6 @@ Subroutine recurses on
         sub foo { call foo; }
 -----------------------###---
 
-
-...called from "vcl_recv"
-('<vcl.inline>' Line 6 Pos 29)
-        sub vcl_recv { call foo; }
-----------------------------###---
 } {
 	backend b { .host = "${localhost}"; }
 
@@ -62,16 +57,9 @@ Subroutine recurses on
 }
 
 varnish v1 -errvcl {
-Subroutine recurses on
-('<vcl.inline>' Line 6 Pos 13)
-        sub foo { call bar; }
-------------###--------------
-
-
-...called from "bar"
-('<vcl.inline>' Line 5 Pos 24)
+('<vcl.inline>' Line 5 Pos 13)
         sub bar { call foo; }
------------------------###---
+------------###--------------
 
 
 ...called from "foo"
@@ -80,10 +68,11 @@ Subroutine recurses on
 -----------------------###---
 
 
-...called from "vcl_recv"
-('<vcl.inline>' Line 7 Pos 29)
-        sub vcl_recv { call foo; }
-----------------------------###---
+...called from "bar"
+('<vcl.inline>' Line 5 Pos 24)
+        sub bar { call foo; }
+-----------------------###---
+
 } {
 	backend b { .host = "${localhost}"; }
 
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 286e81ee0..83dec7461 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -227,25 +227,33 @@ static void
 vcc_checkaction(struct vcc *tl, const struct symbol *sym)
 {
 	struct proc *p;
+	unsigned bitmap;
 
 	p = sym->proc;
 	AN(p);
 	AN(p->name);
+
 	if (p->method == NULL)
+		bitmap = ~0U;
+	else
+		bitmap = p->method->ret_bitmap;
+
+	if (! vcc_CheckActionRecurse(tl, p, bitmap))
 		return;
-	if (vcc_CheckActionRecurse(tl, p, p->method->ret_bitmap)) {
-		VSB_printf(tl->sb,
-		    "\n...which is the \"%s\" subroutine\n", p->method->name);
-		VSB_cat(tl->sb, "Legal returns are:");
+
+	tl->err = 1;
+	if (p->method == NULL)
+		return;
+
+	VSB_printf(tl->sb,
+		   "\n...which is the \"%s\" subroutine\n", p->method->name);
+	VSB_cat(tl->sb, "Legal returns are:");
 #define VCL_RET_MAC(l, U, B)						\
-		if (p->method->ret_bitmap & ((1 << VCL_RET_##U)))	\
-			VSB_printf(tl->sb, " \"%s\"", #l);
+	if (p->method->ret_bitmap & ((1 << VCL_RET_##U)))		\
+		VSB_printf(tl->sb, " \"%s\"", #l);
 
 #include "tbl/vcl_returns.h"
-		VSB_cat(tl->sb, "\n");
-		tl->err = 1;
-	}
-
+	VSB_cat(tl->sb, "\n");
 }
 
 int


More information about the varnish-commit mailing list