From 4cec3ff2a05ea407b56644d092ad57d56ca81096 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 22 Oct 2020 17:27:23 -0400 Subject: [PATCH] Fix WIDTH warnings on comparisons with nullptr (#2602). --- Changes | 2 ++ src/V3Width.cpp | 6 ++++++ src/verilog.y | 2 +- test_regress/t/t_class1.v | 3 +++ test_regress/t/t_var_types.v | 5 +++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index ffa68c30d..c2fff4499 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index e0b17d71b..7e91a0362 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -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 " diff --git a/src/verilog.y b/src/verilog.y index eee186507..dfbe30a97 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -4228,7 +4228,7 @@ expr: // IEEE: part of expression/constant_expression/primary // // Indistinguishable from function_subroutine_call:method_call // | '$' { $$ = new AstUnbounded($1); } - | yNULL { $$ = new AstConst($1, AstConst::LogicFalse()); } + | yNULL { $$ = new AstConst($1, AstConst::StringToParse(), "'0"); } // // IEEE: yTHIS // // See exprScope // diff --git a/test_regress/t/t_class1.v b/test_regress/t/t_class1.v index 6d9a663f1..b584c5be6 100644 --- a/test_regress/t/t_class1.v +++ b/test_regress/t/t_class1.v @@ -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; diff --git a/test_regress/t/t_var_types.v b/test_regress/t/t_var_types.v index 75a06d55e..273ad4691 100644 --- a/test_regress/t/t_var_types.v +++ b/test_regress/t/t_var_types.v @@ -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