diff --git a/Changes b/Changes index d38e10ec4..af031e8e1 100644 --- a/Changes +++ b/Changes @@ -27,6 +27,7 @@ Verilator 5.023 devel * Fix try-lock spuriously fails (#4931) (#4938). [Kamil Rakoczy] * Fix V3Unknown unpacked struct x-assign (#4934). [Yan Xu] * Fix DFG removing forceable signals (#4942). [Geza Lore] +* Fix null characters in shortened identifiers (#4946). [Abdul Hameed] Verilator 5.022 2024-02-24 diff --git a/src/V3String.cpp b/src/V3String.cpp index 45e7da277..6df59770c 100644 --- a/src/V3String.cpp +++ b/src/V3String.cpp @@ -563,8 +563,13 @@ string VName::hashedName() { VHashSha256 hash{m_name}; const string suffix = "__Vhsh" + hash.digestSymbol(); if (s_minLength < s_maxLength) { - s_dehashMap[suffix] = m_name.substr(s_minLength); - m_hashed = m_name.substr(0, s_minLength) + suffix; + // Keep a prefix from the original name + // Backup over digits so adding __Vhash doesn't look like a encoded hex digit + // ("__0__Vhsh") + size_t prefLength = s_minLength; + while (prefLength >= 1 && m_name[prefLength - 1] != '_') --prefLength; + s_dehashMap[suffix] = m_name.substr(prefLength); + m_hashed = m_name.substr(0, prefLength) + suffix; } else { s_dehashMap[suffix] = m_name; m_hashed = suffix; diff --git a/test_regress/t/t_inst_long_bad.out b/test_regress/t/t_inst_long_bad.out index 12d38a513..3020fe05a 100644 --- a/test_regress/t/t_inst_long_bad.out +++ b/test_regress/t/t_inst_long_bad.out @@ -1,4 +1,4 @@ -%Error: obj_vlt/t_inst_long_bad/t_inst_long.v:4:3: Cannot find file containing module: 'long_long_long_long_long_long_lo__Vhsh1JZCXQVBM1QiASYlLmgTuAXYyUr7VAbJYwVHfiAD' +%Error: obj_vlt/t_inst_long_bad/t_inst_long.v:4:3: Cannot find file containing module: 'long_long_long_long_long_long___Vhsh1JZCXQVBM1QiASYlLmgTuAXYyUr7VAbJYwVHfiAD' 4 | long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_long_ inst (); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... Unsupported: Name is longer than 127 characters; automatic file lookup not supported. diff --git a/test_regress/t/t_inst_name_long.pl b/test_regress/t/t_inst_name_long.pl new file mode 100755 index 000000000..b65c35c81 --- /dev/null +++ b/test_regress/t/t_inst_name_long.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); + +compile(); + +ok(1); +1; diff --git a/test_regress/t/t_inst_name_long.v b/test_regress/t/t_inst_name_long.v new file mode 100644 index 000000000..964ca30dd --- /dev/null +++ b/test_regress/t/t_inst_name_long.v @@ -0,0 +1,46 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2024 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +// verilator lint_off PINMISSING +// verilator lint_off WIDTHEXPAND + +module t; + // Original issue + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + // Change sizes + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/Xxxxxxxxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxxxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + sub #(.PARAM("FALSE")) + \$mul$/nxx_xxxxxxx/xxxxxxx/XxxxxxxxxxxXxxxxxxxxx/xxx/.././xxx/xxx_xxxxxxxxxx_xxxxx_xxxx_xxx_xxx.v:30$7 ( + ); + +endmodule + +module sub #(parameter PARAM = "TRUE") + (input [5:0] ACC_FIR); + always @(ACC_FIR) $display("WARNING: instance %m input is %d", PARAM); +endmodule