From 4854de06cad3c9a921b5e75577eb421064d5cf1b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 5 Jan 2025 09:17:53 -0800 Subject: [PATCH 1/2] vvp: Fix logic class property initialization Logic type class properties use the wrong constructor resulting in a default value of a vector with 0 width. Switch to the right constructor to fix this. Signed-off-by: Lars-Peter Clausen --- vvp/class_type.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vvp/class_type.cc b/vvp/class_type.cc index be7a55b5a..716cfb944 100644 --- a/vvp/class_type.cc +++ b/vvp/class_type.cc @@ -175,7 +175,7 @@ class property_logic : public class_property_t { public: void construct(char*buf) const - { new (buf+offset_) vvp_vector4_t (0, wid_); } + { new (buf+offset_) vvp_vector4_t (wid_); } void destruct(char*buf) const { vvp_vector4_t*tmp = reinterpret_cast(buf+offset_); From c22b375c86b484eedb0b4a839794b6f529f6888f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 5 Jan 2025 09:43:13 -0800 Subject: [PATCH 2/2] Add regression test for logic class property default value Check that class logic class properties get initialized to 'x. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_class_prop_logic.v | 28 +++++++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/sv_class_prop_logic.json | 5 ++++ 3 files changed, 34 insertions(+) create mode 100644 ivtest/ivltests/sv_class_prop_logic.v create mode 100644 ivtest/vvp_tests/sv_class_prop_logic.json diff --git a/ivtest/ivltests/sv_class_prop_logic.v b/ivtest/ivltests/sv_class_prop_logic.v new file mode 100644 index 000000000..d96e39636 --- /dev/null +++ b/ivtest/ivltests/sv_class_prop_logic.v @@ -0,0 +1,28 @@ +// Check that logic class properties are initialized to 'x. + +module test; + + bit failed = 1'b0; + + `define check(val, exp) do \ + if (val != exp) begin \ + $display("FAILED(%0d). '%s' expected %d, got %d", `__LINE__, `"val`", exp, val); \ + failed = 1'b1; \ + end \ + while(0) + + class C; + logic [31:0] x; + endclass + + C c; + + initial begin + c = new; + `check(c.x, 32'hxx); + + if (!failed) begin + $display("PASSED"); + end + end +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 3dc8167b9..6c05287de 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -222,6 +222,7 @@ sv_chained_constructor2 vvp_tests/sv_chained_constructor2.json sv_chained_constructor3 vvp_tests/sv_chained_constructor3.json sv_chained_constructor4 vvp_tests/sv_chained_constructor4.json sv_chained_constructor5 vvp_tests/sv_chained_constructor5.json +sv_class_prop_logic vvp_tests/sv_class_prop_logic.json sv_const1 vvp_tests/sv_const1.json sv_const2 vvp_tests/sv_const2.json sv_const3 vvp_tests/sv_const3.json diff --git a/ivtest/vvp_tests/sv_class_prop_logic.json b/ivtest/vvp_tests/sv_class_prop_logic.json new file mode 100644 index 000000000..f0df90efe --- /dev/null +++ b/ivtest/vvp_tests/sv_class_prop_logic.json @@ -0,0 +1,5 @@ +{ + "type" : "normal", + "source" : "sv_class_prop_logic.v", + "iverilog-args" : [ "-g2005-sv" ] +}