Fix duplicate static names in blocks in functions (#4144) (#4160)

Static variables of functions are created in the function. When blocks
in a function use identical names for static variables, we need to name
those variables properly.
This commit is contained in:
Stefan Wallentowitz 2023-05-03 02:24:44 +02:00 committed by GitHub
parent 707f230353
commit 7708c88e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 1 deletions

View File

@ -111,6 +111,7 @@ private:
string dot(const string& a, const string& b) {
if (a == "") return b;
if (b == "") return a;
return a + "__DOT__" + b;
}
@ -260,7 +261,8 @@ private:
void visit(AstVar* nodep) override {
// If static variable, move it outside a function.
if (nodep->lifetime().isStatic() && m_ftaskp) {
const std::string newName = m_ftaskp->name() + "__Vstatic__" + nodep->name();
const std::string newName
= m_ftaskp->name() + "__Vstatic__" + dot(m_unnamedScope, nodep->name());
nodep->name(newName);
nodep->unlinkFrBack();
m_ftaskp->addHereThisAsNext(nodep);

View File

@ -0,0 +1,23 @@
#!/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(simulator => 1);
$Self->{verilated_randReset} = 1;
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,34 @@
// DESCRIPTION: Verilator: Verilog Test module
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t;
function do_stuff();
static int some_int;
begin: block0
static int some_int;
end
begin: block1
static int some_int;
end
begin
static int some_int;
end
begin: block2
begin: block3
static int some_int;
end
begin
static int some_int;
end
end
endfunction
initial begin
$write("*-* All Finished *-*\n");
$finish();
end
endmodule