From bb8b05bb5ddea26e1de3618d595e56ae33739708 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 20 Jun 2026 17:05:56 -0700 Subject: [PATCH] Add regression test for classes in generate blocks Check that a class declared in a conditional generate block can be used. Also check that classes declared in a generate loop get separate class scopes for each generated instance. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/br_gh1384.v | 50 +++++++++++++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/br_gh1384.json | 9 ++++++ 3 files changed, 60 insertions(+) create mode 100644 ivtest/ivltests/br_gh1384.v create mode 100644 ivtest/vvp_tests/br_gh1384.json diff --git a/ivtest/ivltests/br_gh1384.v b/ivtest/ivltests/br_gh1384.v new file mode 100644 index 000000000..f58f8a283 --- /dev/null +++ b/ivtest/ivltests/br_gh1384.v @@ -0,0 +1,50 @@ +// Check that classes declared inside generate blocks can be used. + +module test; + + reg failed; + + `define check(val, exp) \ + if (val !== exp) begin \ + $display("FAILED(%0d). '%s' expected %0d, got %0d", `__LINE__, \ + `"val`", exp, val); \ + failed = 1'b1; \ + end + + if (1) begin : g + class C; + int value; + + function new(int value); + this.value = value; + endfunction + endclass + + C c = new(42); + end + + for (genvar i = 0; i < 2; i = i + 1) begin : h + class C; + int value; + + function new(int value); + this.value = value + i; + endfunction + endclass + + C c = new(10); + end + + initial begin + failed = 1'b0; + + `check(g.c.value, 42); + `check(h[0].c.value, 10); + `check(h[1].c.value, 11); + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index d9a8f3e7b..b66ada6b5 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -82,6 +82,7 @@ br_gh1258a vvp_tests/br_gh1258a.json br_gh1258b vvp_tests/br_gh1258b.json br_gh1286 vvp_tests/br_gh1286.json br_gh1323 vvp_tests/br_gh1323.json +br_gh1384 vvp_tests/br_gh1384.json br_gh1385 vvp_tests/br_gh1385.json br_gh1385a vvp_tests/br_gh1385a.json br_gh1385b vvp_tests/br_gh1385b.json diff --git a/ivtest/vvp_tests/br_gh1384.json b/ivtest/vvp_tests/br_gh1384.json new file mode 100644 index 000000000..2f6ac5c8b --- /dev/null +++ b/ivtest/vvp_tests/br_gh1384.json @@ -0,0 +1,9 @@ +{ + "type" : "normal", + "source" : "br_gh1384.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Classes are not supported", + "type" : "CE" + } +}