diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 78e29bdbe..c9d7abd9f 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -1555,8 +1555,7 @@ static VCastable computeCastableImp(const AstNodeDType* toDtp, const AstNodeDTyp return VCastable::ENUM_IMPLICIT; if (fromNumericable) return VCastable::ENUM_EXPLICIT; } else if (VN_IS(toDtp, ClassRefDType) && VN_IS(fromConstp, Const)) { - if (VN_IS(fromConstp, Const) && VN_AS(fromConstp, Const)->num().isNull()) - return VCastable::COMPATIBLE; + if (fromConstp->isNull()) return VCastable::COMPATIBLE; } else if (VN_IS(toDtp, ClassRefDType) && VN_IS(fromDtp, ClassRefDType)) { const auto toClassp = VN_AS(toDtp, ClassRefDType)->classp(); const auto fromClassp = VN_AS(fromDtp, ClassRefDType)->classp(); diff --git a/src/V3Ast.h b/src/V3Ast.h index 0126271dd..c36829cb2 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2082,6 +2082,7 @@ public: // ACCESSORS for specific types // Alas these can't be virtual or they break when passed a nullptr inline bool isClassHandleValue() const; + inline bool isNull() const; inline bool isZero() const; inline bool isOne() const; inline bool isNeqZero() const; diff --git a/src/V3AstInlines.h b/src/V3AstInlines.h index 8a1e1f96f..a20ee58d6 100644 --- a/src/V3AstInlines.h +++ b/src/V3AstInlines.h @@ -49,6 +49,7 @@ bool AstNode::isClassHandleValue() const { return (VN_IS(this, Const) && VN_AS(this, Const)->num().isNull()) || VN_IS(dtypep(), ClassRefDType); } +bool AstNode::isNull() const { return VN_IS(this, Const) && VN_AS(this, Const)->num().isNull(); } bool AstNode::isZero() const { return (VN_IS(this, Const) && VN_AS(this, Const)->num().isEqZero()); } diff --git a/src/V3Cast.cpp b/src/V3Cast.cpp index 8a6df2876..613be4798 100644 --- a/src/V3Cast.cpp +++ b/src/V3Cast.cpp @@ -82,8 +82,7 @@ class CastVisitor final : public VNVisitor { } void ensureCast(AstNodeExpr* nodep) { if (castSize(nodep->backp()) != castSize(nodep) || !nodep->user1()) { - const AstConst* const constp = VN_CAST(nodep, Const); - if (!(constp && constp->num().isNull())) insertCast(nodep, castSize(nodep->backp())); + if (!nodep->isNull()) insertCast(nodep, castSize(nodep->backp())); } } void ensureLower32Cast(AstCCast* nodep) { @@ -202,7 +201,7 @@ class CastVisitor final : public VNVisitor { // Constants are of unknown size if smaller than 33 bits, because // we're too lazy to wrap every constant in the universe in // ((IData)#). - nodep->user1(nodep->isQuad() || nodep->isWide() || nodep->num().isNull()); + nodep->user1(nodep->isQuad() || nodep->isWide() || nodep->isNull()); } // Null dereference protection diff --git a/src/V3Width.cpp b/src/V3Width.cpp index aee14cc61..b1dfcd85d 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -6560,8 +6560,8 @@ class WidthVisitor final : public VNVisitor { AstNodeDType* const rhsDtypep = rhsp->dtypep()->skipRefp(); if (AstClassRefDType* const rhsClassRefp = VN_CAST(rhsDtypep, ClassRefDType)) { if (isBaseClassRecurse(lhsClassRefp->classp(), rhsClassRefp->classp())) return; - } else if (auto* const constp = VN_CAST(rhsp, Const)) { - if (constp->num().isNull()) return; + } else if (rhsp->isNull()) { + return; } nodep->v3error(side << " expects a " << lhsClassRefp->prettyTypeName() << ", got " << rhsDtypep->prettyTypeName());