Fix null assignment to virtual interfaces (#5974) (#5990). [Maxim Fonarev]

Fixes #5974.

Co-authored-by: Maksim Fonarev <fonarickm@yandex.ru>
This commit is contained in:
Wilson Snyder 2026-03-19 20:29:02 -04:00
parent 49716995fa
commit 94f8181cff
5 changed files with 22 additions and 4 deletions

View File

@ -46,6 +46,7 @@ Verilator 5.047 devel
* Fix recursive default assignment for sub-arrays (#4589) (#7202). [Julian Carrier]
* Fix shift width mismatch in constraint solver SMT emission (#5420) (#7265). [Yilou Wang]
* Fix randomize size+element queue constraints (#5582) (#7225). [Rahul Behl, Testorrent USA, Inc.]
* Fix null assignment to virtual interfaces (#5974) (#5990). [Maxim Fonarev]
* Fix lambda coroutines (#6106) (#7135). [Nick Brereton]
* Fix super constructor calls with local variables (#6214) (#6933). [Igor Zaworski, Antmicro Ltd.]
* Fix false recursive definition error (#6769) (#7118). [Alex Zhou]

View File

@ -176,6 +176,7 @@ Mateusz Gancarz
Matt Stroud
Matthew Ballance
Max Wipfli
Maxim Fonarev
Michael Bedford Taylor
Michael Bikovitsky
Michael Killough

View File

@ -1931,7 +1931,10 @@ public:
struct VlNull final {
operator bool() const { return false; }
bool operator==(const void* ptr) const { return !ptr; }
template <class T>
operator T*() const {
return nullptr;
}
};
inline bool operator==(const void* ptr, VlNull) { return !ptr; }

View File

@ -8676,7 +8676,9 @@ class WidthVisitor final : public VNVisitor {
= VN_CAST(expDTypep->skipRefp(), IfaceRefDType)) {
const AstIfaceRefDType* underIfaceRefp
= VN_CAST(underp->dtypep()->skipRefp(), IfaceRefDType);
if (!underIfaceRefp) {
if (VN_IS(underp, Const) && VN_AS(underp, Const)->num().isNull()) {
// '= null' is ok
} else if (!underIfaceRefp) {
underp->v3error(ucfirst(parentp->prettyOperatorName())
<< " expected " << expIfaceRefp->ifaceViaCellp()->prettyNameQ()
<< " interface on " << side << " but " << underp->prettyNameQ()

View File

@ -34,10 +34,21 @@ module t;
Clsgen #(virtual PBus) gen;
initial begin
if (va != null) $stop;
if (null != va) $stop;
va = null;
if (va != null) $stop;
if (null != va) $stop;
va = ia;
vb = ia;
if (va == null) $stop;
if (null == va) $stop;
va = null;
if (va != null) $stop;
if (null != va) $stop;
va = ia;
if (va != ia) $stop;
vb = ia;
$display("va==vb? %b", va == vb);
$display("va!=vb? %b", va != vb);