From 4e71f359bf6c19e603541c0107ffff0d90a85a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Chmiel?= Date: Mon, 4 Nov 2024 15:06:15 +0100 Subject: [PATCH] Fix duplicate scope identifiers decoding (#5584) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bartłomiej Chmiel Co-authored-by: Ryszard Rozak --- src/V3EmitCSyms.cpp | 13 +------------ test_regress/t/t_vpi_escape.cpp | 10 ++++++++++ test_regress/t/t_vpi_escape.v | 4 ++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 14323fed6..4198eecc5 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -156,7 +156,6 @@ class EmitCSyms final : EmitCBaseVisitorConst { } static string scopeDecodeIdentifier(const string& scpname) { - string out = scpname; string::size_type pos = string::npos; // Remove hierarchy @@ -172,17 +171,7 @@ class EmitCSyms final : EmitCBaseVisitorConst { } } - if (pos != std::string::npos) out.erase(0, pos + 1); - - // Decode all escaped characters - while ((pos = out.find("__0")) != string::npos) { - unsigned int x; - std::stringstream ss; - ss << std::hex << out.substr(pos + 3, 2); - ss >> x; - out.replace(pos, 5, 1, (char)x); - } - return out; + return pos != string::npos ? scpname.substr(pos + 1) : scpname; } /// (scp, m_vpiScopeCandidates, m_scopeNames) -> m_scopeNames diff --git a/test_regress/t/t_vpi_escape.cpp b/test_regress/t/t_vpi_escape.cpp index 043a62a5d..7fed0d2e6 100644 --- a/test_regress/t/t_vpi_escape.cpp +++ b/test_regress/t/t_vpi_escape.cpp @@ -135,6 +135,16 @@ int _mon_check_iter() { TEST_CHECK_CSTR(p, ""); // Unsupported } + TestVpiHandle vh_null_name = MY_VPI_HANDLE("___0_"); + TEST_CHECK_NZ(vh_null_name); + p = vpi_get_str(vpiName, vh_null_name); + TEST_CHECK_CSTR(p, "___0_"); + + TestVpiHandle vh_hex_name = MY_VPI_HANDLE("___0F_"); + TEST_CHECK_NZ(vh_hex_name); + p = vpi_get_str(vpiName, vh_hex_name); + TEST_CHECK_CSTR(p, "___0F_"); + TestVpiHandle vh10 = vpi_iterate(vpiReg, vh2); TEST_CHECK_NZ(vh10); TEST_CHECK_EQ(vpi_get(vpiType, vh10), vpiIterator); diff --git a/test_regress/t/t_vpi_escape.v b/test_regress/t/t_vpi_escape.v index b575dc199..a912c1096 100644 --- a/test_regress/t/t_vpi_escape.v +++ b/test_regress/t/t_vpi_escape.v @@ -63,6 +63,10 @@ extern "C" int mon_check(); sub \mod.with_dot (.cyc(cyc)); + // Check if scope names are not decoded twice + sub ___0F_ (.cyc(cyc)); + sub ___0_ (.cyc(cyc)); + initial begin `ifdef VERILATOR