Fix `new this` (#5909).

This commit is contained in:
Wilson Snyder 2025-04-01 08:12:34 -04:00
parent 538f39edf9
commit 168f0ed9e5
4 changed files with 26 additions and 10 deletions

View File

@ -62,6 +62,7 @@ Verilator 5.035 devel
* Fix process comparisons (#5896).
* Fix ccache with clang (#5899). [Geza Lore]
* Fix delayed assignment malformed LHS assertion (#5904).
* Fix `new this` (#5909).
Verilator 5.034 2025-02-24

View File

@ -120,15 +120,7 @@ public:
// Iff has second dtype, set as generic node function
virtual void virtRefDType2p(AstNodeDType* nodep) {}
// Assignable equivalence. Calls skipRefToNonRefp() during comparisons.
bool similarDType(const AstNodeDType* samep) const {
const AstNodeDType* nodep = this;
nodep = nodep->skipRefToNonRefp();
samep = samep->skipRefToNonRefp();
if (nodep == samep) return true;
if (nodep->type() != samep->type()) return false;
return nodep->similarDTypeNode(samep);
}
bool similarDType(const AstNodeDType* samep) const;
// Iff has a non-null subDTypep(), as generic node function
virtual AstNodeDType* subDTypep() const VL_MT_STABLE { return nullptr; }
virtual bool isFourstate() const;
@ -581,7 +573,11 @@ public:
const AstClassRefDType* const asamep = VN_DBG_AS(samep, ClassRefDType);
return (m_classp == asamep->m_classp && m_classOrPackagep == asamep->m_classOrPackagep);
}
bool similarDTypeNode(const AstNodeDType* samep) const override { return sameNode(samep); }
bool similarDTypeNode(const AstNodeDType* samep) const override {
// Doesn't need to compare m_classOrPackagep
const AstClassRefDType* const asamep = VN_DBG_AS(samep, ClassRefDType);
return m_classp == asamep->m_classp;
}
void dump(std::ostream& str = std::cout) const override;
void dumpJson(std::ostream& str = std::cout) const override;
void dumpSmall(std::ostream& str) const override;

View File

@ -848,6 +848,15 @@ const AstNodeDType* AstNodeDType::skipRefIterp(bool skipConst, bool skipEnum,
}
}
bool AstNodeDType::similarDType(const AstNodeDType* samep) const {
const AstNodeDType* nodep = this;
nodep = nodep->skipRefToNonRefp();
samep = samep->skipRefToNonRefp();
if (nodep == samep) return true;
if (nodep->type() != samep->type()) return false;
return nodep->similarDTypeNode(samep);
}
bool AstNodeDType::isFourstate() const { return basicp() && basicp()->isFourstate(); }
class AstNodeDType::CTypeRecursed final {

View File

@ -21,16 +21,26 @@ class Testcase implements ICls;
virtual function string get();
return "In ICls";
endfunction
function Testcase clone();
Testcase a = new this;
return a;
endfunction
endclass
module t(/*AUTOARG*/);
initial begin
Testcase test;
Testcase cloned;
test = new;
if (test.cls.name != "test_class") $stop;
if (test.cls.icls.get() != "In ICls") $stop;
cloned = test.clone();
if (cloned.cls.name != "test_class") $stop;
test.cls.icls = null; // Prevent leak
$write("*-* All Finished *-*\n");
$finish;
end