From 06428f3d1137b4570371fb011f014732fddd8d84 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 29 Jul 2023 12:23:31 -0700 Subject: [PATCH 1/2] Make sure `const var` variables are constant Commit 3daa2982acb2 ("Add support for `const` variables") added support for constant variables, but had a small mistake and did propagate the constant flag from the parser if the variable is declared with the `var` keyword. Still allowing to modify those variables. Fix this. Signed-off-by: Lars-Peter Clausen --- parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse.y b/parse.y index 92e8c73ef..24c3a27a0 100644 --- a/parse.y +++ b/parse.y @@ -2738,7 +2738,7 @@ block_item_decl data_type = new vector_type_t(IVL_VT_LOGIC, false, 0); FILE_NAME(data_type, @2); } - pform_make_var(@2, $5, data_type, attributes_in_context); + pform_make_var(@2, $5, data_type, attributes_in_context, $1); var_lifetime = LexicalScope::INHERITED; } From bdfd873dc41603866c6b5b052c946531fccf5f13 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 29 Jul 2023 12:20:48 -0700 Subject: [PATCH 2/2] Add regression test for `const var` Check that variables declared with `const var` can not be modified. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_const_fail9.v | 13 +++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/sv_const_fail9.json | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 ivtest/ivltests/sv_const_fail9.v create mode 100644 ivtest/vvp_tests/sv_const_fail9.json diff --git a/ivtest/ivltests/sv_const_fail9.v b/ivtest/ivltests/sv_const_fail9.v new file mode 100644 index 000000000..41a69c7fc --- /dev/null +++ b/ivtest/ivltests/sv_const_fail9.v @@ -0,0 +1,13 @@ +// Check that blocking assignment to a const variable fails, when the variable is +// declared with the `var` keyword. + +module test; + + const var integer x = 10; + + initial begin + x = 20; // Error: Assignment to const variable + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 11f9dc682..aea653cb9 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -73,6 +73,7 @@ sv_const_fail5 vvp_tests/sv_const_fail5.json sv_const_fail6 vvp_tests/sv_const_fail6.json sv_const_fail7 vvp_tests/sv_const_fail7.json sv_const_fail8 vvp_tests/sv_const_fail8.json +sv_const_fail9 vvp_tests/sv_const_fail9.json sv_foreach9 vvp_tests/sv_foreach9.json sv_foreach10 vvp_tests/sv_foreach10.json sv_module_port1 vvp_tests/sv_module_port1.json diff --git a/ivtest/vvp_tests/sv_const_fail9.json b/ivtest/vvp_tests/sv_const_fail9.json new file mode 100644 index 000000000..f0b235dc1 --- /dev/null +++ b/ivtest/vvp_tests/sv_const_fail9.json @@ -0,0 +1,5 @@ +{ + "type" : "CE", + "source" : "sv_const_fail9.v", + "iverilog-args" : [ "-g2005-sv" ] +}