Fix dynamic casts of null values (#4631)

This commit is contained in:
Ryszard Rozak 2023-10-27 15:58:40 +02:00 committed by GitHub
parent 739521333c
commit e6135981a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -1685,6 +1685,10 @@ public:
template <typename T, typename U>
static inline bool VL_CAST_DYNAMIC(VlClassRef<T> in, VlClassRef<U>& outr) {
if (!in) {
outr = VlNull{};
return true;
}
VlClassRef<U> casted = in.template dynamicCast<U>();
if (VL_LIKELY(casted)) {
outr = casted;
@ -1694,6 +1698,12 @@ static inline bool VL_CAST_DYNAMIC(VlClassRef<T> in, VlClassRef<U>& outr) {
}
}
template <typename T>
static inline bool VL_CAST_DYNAMIC(VlNull in, VlClassRef<T>& outr) {
outr = VlNull{};
return true;
}
//=============================================================================
// VlSampleQueue stores samples for input clockvars in clocking blocks. At a clocking event,
// samples from this queue should be written to the correct input clockvar.

View File

@ -9,6 +9,10 @@ endclass
class BasedA extends Base;
endclass
class BasedB extends Base;
static function BasedB getBasedB(bit getNull);
BasedB b = new;
return getNull ? null : b;
endfunction
endclass
module t (/*AUTOARG*/);
@ -55,6 +59,18 @@ module t (/*AUTOARG*/);
if (i != 1) $stop;
if (b != bb) $stop;
bb = null;
b = bb;
i = $cast(bbo, b);
if (i != 1) $stop;
if (b != bb) $stop;
bb = BasedB::getBasedB(1);
b = bb;
i = $cast(bbo, b);
if (i != 1) $stop;
if (b != bb) $stop;
bb = new;
b = bb;
bao = ba;