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-02 20:24:44 -04:00
committed by GitHub
parent 707f230353
commit 7708c88e32
3 changed files with 60 additions and 1 deletions
+3 -1
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);