Fix typedef'ed class conversion to boolean (#3616).

This commit is contained in:
Wilson Snyder 2022-09-12 18:03:47 -04:00
parent 08b6bdddf9
commit 81fe35ee2e
3 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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 << ".");

View File

@ -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;