diff --git a/Changes b/Changes index 5cae1fc1c..202e279c2 100644 --- a/Changes +++ b/Changes @@ -13,7 +13,8 @@ Verilator 4.227 devel **Minor:** -Fix crash in gate optimization of circular logic (#3543). [Bill Flynn] +* Fix crash in gate optimization of circular logic (#3543). [Bill Flynn] +* Fix typedef'ed class conversion to boolean (#3616). [Aleksander Kiryk] Verilator 4.226 2022-08-31 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 7fdbf20f0..081fc526e 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5808,7 +5808,8 @@ private: "Node has no type"); // Perhaps forgot to do a prelim visit on it? // // For DOUBLE under a logical op, add implied test against zero, never a warning - if (underp && underp->isDouble()) { + AstNodeDType* const underVDTypep = underp ? underp->dtypep()->skipRefp() : nullptr; + if (underp && underVDTypep->isDouble()) { UINFO(6, " spliceCvtCmpD0: " << underp << endl); VNRelinker linker; underp->unlinkFrBack(&linker); @@ -5816,13 +5817,12 @@ private: = new AstNeqD(nodep->fileline(), underp, new AstConst(nodep->fileline(), AstConst::RealDouble(), 0.0)); linker.relink(newp); - } else if (VN_IS(underp->dtypep(), ClassRefDType) - || (VN_IS(underp->dtypep(), BasicDType) - && VN_AS(underp->dtypep(), BasicDType)->keyword() - == VBasicDTypeKwd::CHANDLE)) { + } else if (VN_IS(underVDTypep, ClassRefDType) + || (VN_IS(underVDTypep, BasicDType) + && VN_AS(underVDTypep, BasicDType)->keyword() == VBasicDTypeKwd::CHANDLE)) { // Allow warning-free "if (handle)" VL_DO_DANGLING(fixWidthReduce(underp), underp); // Changed - } else if (!underp->dtypep()->basicp()) { + } else if (!underVDTypep->basicp()) { nodep->v3error("Logical operator " << nodep->prettyTypeName() << " expects a non-complex data type on the " << side << "."); diff --git a/test_regress/t/t_class1.v b/test_regress/t/t_class1.v index b584c5be6..c10125c51 100644 --- a/test_regress/t/t_class1.v +++ b/test_regress/t/t_class1.v @@ -12,14 +12,20 @@ class Cls; endclass : Cls module t (/*AUTOARG*/); + typedef Cls Cls2; + initial begin Cls c; + Cls2 c2; if (c != null) $stop; if (c) $stop; + if (c2) $stop; $display("Display: null = \"%p\"", c); // null c = new; + c2 = new; if (c == null) $stop; if (!c) $stop; + if (!c2) $stop; $display("Display: newed = \"%p\"", c); // '{imembera:0, imemberb:0} c.imembera = 10; c.imemberb = 20;