Fix WIDTH warnings on comparisons with nullptr (#2602).

This commit is contained in:
Wilson Snyder 2020-10-22 17:27:23 -04:00
parent 25593c0ee2
commit 4cec3ff2a0
5 changed files with 17 additions and 1 deletions

View File

@ -6,6 +6,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
**** Support queue slicing (#2326).
**** Fix WIDTH warnings on comparisons with nullptr (#2602). [Rupert Swarbrick]
* Verilator 4.102 2020-10-15

View File

@ -4781,6 +4781,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_CAST(underp->dtypep(), BasicDType)->keyword()
== AstBasicDTypeKwd::CHANDLE)) {
// Allow warning-free "if (handle)"
VL_DO_DANGLING(fixWidthReduce(underp), underp); // Changed
} else if (!underp->dtypep()->basicp()) {
nodep->v3error("Logical operator " << nodep->prettyTypeName()
<< " expects a non-complex data type on the "

View File

@ -4228,7 +4228,7 @@ expr<nodep>: // IEEE: part of expression/constant_expression/primary
// // Indistinguishable from function_subroutine_call:method_call
//
| '$' { $$ = new AstUnbounded($<fl>1); }
| yNULL { $$ = new AstConst($1, AstConst::LogicFalse()); }
| yNULL { $$ = new AstConst($1, AstConst::StringToParse(), "'0"); }
// // IEEE: yTHIS
// // See exprScope
//

View File

@ -15,8 +15,11 @@ module t (/*AUTOARG*/);
initial begin
Cls c;
if (c != null) $stop;
if (c) $stop;
$display("Display: null = \"%p\"", c); // null
c = new;
if (c == null) $stop;
if (!c) $stop;
$display("Display: newed = \"%p\"", c); // '{imembera:0, imemberb:0}
c.imembera = 10;
c.imemberb = 20;

View File

@ -216,6 +216,11 @@ module t (/*AUTOARG*/);
d_time = $time;
if ($time !== d_time) $stop;
// Null checks
d_chandle = null;
if (d_chandle != null) $stop;
if (d_chandle) $stop;
$write("*-* All Finished *-*\n");
$finish;
end