diff --git a/src/V3EmitCFunc.cpp b/src/V3EmitCFunc.cpp index 18bb14c68..8eb82b31f 100644 --- a/src/V3EmitCFunc.cpp +++ b/src/V3EmitCFunc.cpp @@ -463,9 +463,7 @@ void EmitCFunc::emitVarReset(const string& prefix, AstVar* varp, bool constructi // 'constructing' indicates that the object was just constructed, so if it is a string or // something that starts off clear already, no need to clear it again AstNodeDType* const dtypep = varp->dtypep()->skipRefp(); - const string vlSelf = m_cfuncp && m_cfuncp->isStatic() - ? "vlSymsp->TOP__" + m_modp->name() + "." - : VSelfPointerText::replaceThis(m_useSelfForThis, "this->"); + const string vlSelf = VSelfPointerText::replaceThis(m_useSelfForThis, "this->"); const string varNameProtected = ((VN_IS(m_modp, Class) || varp->isFuncLocal()) || !prefix.empty()) ? varp->nameProtect() diff --git a/src/V3EmitCFunc.h b/src/V3EmitCFunc.h index c05c46afe..6eedcbc69 100644 --- a/src/V3EmitCFunc.h +++ b/src/V3EmitCFunc.h @@ -573,8 +573,14 @@ public: + "\", " + std::to_string(nodep->fileline()->lineno()) + ")->"), memberVarp, resetp->constructing()); } else { - AstVar* const varp = VN_AS(fromp, NodeVarRef)->varp(); - emitVarReset("", varp, resetp->constructing()); + AstNodeVarRef* const fromVarRefp = VN_AS(fromp, NodeVarRef); + AstVar* const varp = fromVarRefp->varp(); + const string prefix + = fromVarRefp->selfPointer().isEmpty() + ? "" + : dereferenceString( + VN_AS(fromp, NodeVarRef)->selfPointerProtect(m_useSelfForThis)); + emitVarReset(prefix, varp, resetp->constructing()); } return; }