Fix virtual interface implied comparison with null (#7421).

Fixes #7421.
This commit is contained in:
Wilson Snyder 2026-04-14 07:25:02 -04:00
parent 9eb2ba4c54
commit 7e3400b37d
4 changed files with 18 additions and 2 deletions

View File

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

View File

@ -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{}},

View File

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

View File

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