diff --git a/Changes b/Changes index ecb9d6d99..d816b7ae3 100644 --- a/Changes +++ b/Changes @@ -145,6 +145,7 @@ Verilator 5.047 devel * Fix CMake compiler coroutine flags (#7404). [Shogo Yamazaki] * Fix delete inside foreach skipping elements (#7407) (#7410) * Fix std::randomize in parameterized-derived class (#7409) (#7416). [Yilou Wang] +* Fix virtual interface implied comparison with null (#7421). [Alex Solomatnikov] Verilator 5.046 2026-02-28 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 6a6213471..51ce3e53b 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -8352,7 +8352,8 @@ class WidthVisitor final : public VNVisitor { VNRelinker linker; nodep->unlinkFrBack(&linker); AstNodeExpr* newp; - if (VN_IS(nodep->dtypep()->skipRefp(), ClassRefDType)) { + AstNodeDType* const dtypeSkipp = nodep->dtypep()->skipRefp(); + if (VN_IS(dtypeSkipp, ClassRefDType) || VN_IS(dtypeSkipp, IfaceRefDType)) { // Cannot use AstRedOr, as we may be redurcing a class handle newp = new AstNeq{nodep->fileline(), new AstConst{nodep->fileline(), AstConst::Null{}}, diff --git a/test_regress/t/t_interface_virtual.v b/test_regress/t/t_interface_virtual.v index 0bd84dc24..fca1da253 100644 --- a/test_regress/t/t_interface_virtual.v +++ b/test_regress/t/t_interface_virtual.v @@ -36,15 +36,19 @@ module t; initial begin if (va != null) $stop; if (null != va) $stop; + if (va) $stop; va = null; if (va != null) $stop; if (null != va) $stop; + if (va) $stop; va = ia; if (va == null) $stop; if (null == va) $stop; + if (!va) $stop; va = null; if (va != null) $stop; if (null != va) $stop; + if (va) $stop; va = ia; if (va != ia) $stop; diff --git a/test_regress/t/t_interface_virtual_cond.v b/test_regress/t/t_interface_virtual_cond.v index 5d9af886c..711b994cf 100644 --- a/test_regress/t/t_interface_virtual_cond.v +++ b/test_regress/t/t_interface_virtual_cond.v @@ -11,6 +11,7 @@ endinterface module t; Bus intf (); virtual Bus vif; + virtual Bus vif_arr[5]; function logic get_vif(inout virtual Bus vif); vif = intf; @@ -20,8 +21,17 @@ module t; initial begin if (get_vif(vif)); while (get_vif(vif)); - do ; while (get_vif(vif)); + do; while (get_vif(vif)); for (int i = 0; get_vif(vif); i++); + + foreach (vif_arr[i]) begin + if (vif_arr[i]) begin + $display("vif_arr[%0d]=%p", i, vif_arr[i]); + end + else begin + vif_arr[i] = intf; + end + end end endmodule