From 74d5d008bb626b6a3c6c736206d85defdf70ed00 Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Thu, 19 Dec 2024 15:15:28 -0500 Subject: [PATCH] Fix VPI + SYMRSVDWORD intersection (#5686) --- src/V3Ast.cpp | 6 ++++-- test_regress/t/t_vpi_var.cpp | 10 ++++++++++ test_regress/t/t_vpi_var.py | 2 +- test_regress/t/t_vpi_var.v | 3 +++ test_regress/t/t_vpi_var2.py | 2 +- test_regress/t/t_vpi_var2.v | 1 + test_regress/t/t_vpi_var3.v | 1 + 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index d0f41968f..4369b1176 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -222,12 +222,14 @@ string AstNode::vpiName(const string& namein) { // This is slightly different from prettyName, in that when we encounter escaped characters, // we change that identifier to an escaped identifier, wrapping it with '\' and ' ' // as specified in LRM 23.6 + string name = namein; + if (0 == namein.substr(0, 7).compare("__SYM__")) { name = namein.substr(7); } string pretty; - pretty.reserve(namein.length()); + pretty.reserve(name.length()); bool inEscapedIdent = false; int lastIdent = 0; - for (const char* pos = namein.c_str(); *pos;) { + for (const char* pos = name.c_str(); *pos;) { char specialChar = 0; if (pos[0] == '-' && pos[1] == '>') { // -> specialChar = '.'; diff --git a/test_regress/t/t_vpi_var.cpp b/test_regress/t/t_vpi_var.cpp index 82c98783d..97c123985 100644 --- a/test_regress/t/t_vpi_var.cpp +++ b/test_regress/t/t_vpi_var.cpp @@ -405,6 +405,16 @@ int _mon_check_var() { CHECK_RESULT_CSTR(p, "vpiConstant"); } + // C++ keyword collision + { + TestVpiHandle vh10 = VPI_HANDLE("nullptr"); + CHECK_RESULT_NZ(vh10); + vpi_get_value(vh10, &tmpValue); + CHECK_RESULT(tmpValue.value.integer, 123); + p = vpi_get_str(vpiType, vh10); + CHECK_RESULT_CSTR(p, "vpiParameter"); + } + // non-integer variables tmpValue.format = vpiRealVal; { diff --git a/test_regress/t/t_vpi_var.py b/test_regress/t/t_vpi_var.py index 14985718b..610e7454d 100755 --- a/test_regress/t/t_vpi_var.py +++ b/test_regress/t/t_vpi_var.py @@ -17,7 +17,7 @@ test.compile(make_top_shell=False, sim_time=2100, iv_flags2=["-g2005-sv -D USE_VPI_NOT_DPI -DWAVES"], v_flags2=["+define+USE_VPI_NOT_DPI"], - verilator_flags2=["--exe --vpi --no-l2name", test.pli_filename]) + verilator_flags2=["-Wno-SYMRSVDWORD --exe --vpi --no-l2name", test.pli_filename]) test.execute(use_libvpi=True, all_run_flags=['+PLUS +INT=1234 +STRSTR']) diff --git a/test_regress/t/t_vpi_var.v b/test_regress/t/t_vpi_var.v index 52d92dfc4..d93196cc9 100644 --- a/test_regress/t/t_vpi_var.v +++ b/test_regress/t/t_vpi_var.v @@ -55,6 +55,9 @@ extern "C" int mon_check(); real real1 /*verilator public_flat_rw */; string str1 /*verilator public_flat_rw */; + // specifically public and not public_flat_rw here so as to induce the C++ + // keyword collision + localparam int nullptr /*verilator public */ = 123; sub sub(); diff --git a/test_regress/t/t_vpi_var2.py b/test_regress/t/t_vpi_var2.py index 478afcebb..62511e4cb 100755 --- a/test_regress/t/t_vpi_var2.py +++ b/test_regress/t/t_vpi_var2.py @@ -18,7 +18,7 @@ test.compile(make_top_shell=False, sim_time=2100, iv_flags2=["-g2005-sv -D USE_VPI_NOT_DPI -DWAVES -DT_VPI_VAR2"], v_flags2=["+define+USE_VPI_NOT_DPI"], - verilator_flags2=["--exe --vpi --no-l2name", test.pli_filename]) + verilator_flags2=["-Wno-SYMRSVDWORD --exe --vpi --no-l2name", test.pli_filename]) test.execute(use_libvpi=True, all_run_flags=['+PLUS +INT=1234 +STRSTR']) diff --git a/test_regress/t/t_vpi_var2.v b/test_regress/t/t_vpi_var2.v index 691502419..0c0019ddf 100644 --- a/test_regress/t/t_vpi_var2.v +++ b/test_regress/t/t_vpi_var2.v @@ -74,6 +74,7 @@ extern "C" int mon_check(); /*verilator public_flat_rw_on*/ real real1; string str1; + localparam int nullptr = 123; /*verilator public_off*/ sub sub(); diff --git a/test_regress/t/t_vpi_var3.v b/test_regress/t/t_vpi_var3.v index e81fb48db..a6422b8c2 100644 --- a/test_regress/t/t_vpi_var3.v +++ b/test_regress/t/t_vpi_var3.v @@ -55,6 +55,7 @@ extern "C" int mon_check(); real real1; string str1; + localparam int nullptr = 123; sub sub();