Add support for randomize..with on objects of aliased types (#6195)

This commit is contained in:
Ryszard Rozak 2025-07-18 13:04:47 +02:00 committed by GitHub
parent 28808f38bb
commit a21ecb2ab9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View File

@ -2198,14 +2198,14 @@ class RandomizeVisitor final : public VNVisitor {
AstClass* classp = nullptr;
if (AstMethodCall* const callp = VN_CAST(nodep, MethodCall)) {
UASSERT_OBJ(callp->fromp()->dtypep(), callp->fromp(), "Object dtype is not linked");
AstClassRefDType* const classrefdtypep
= VN_CAST(callp->fromp()->dtypep(), ClassRefDType);
if (!classrefdtypep) {
nodep->v3warn(E_UNSUPPORTED,
"Inline constraints are not supported for this node type");
return;
}
const AstNodeDType* const fromDTypep = callp->fromp()->dtypep();
UASSERT_OBJ(fromDTypep, callp->fromp(), "Object dtype is not linked");
const AstClassRefDType* const classrefdtypep
= VN_CAST(fromDTypep->skipRefp(), ClassRefDType);
UASSERT_OBJ(classrefdtypep, callp->fromp(),
"Randomize called on expression of non-class type "
<< fromDTypep->skipRefp()->prettyDTypeNameQ()
<< " (it should be detected earlier)");
classp = classrefdtypep->classp();
UASSERT_OBJ(classp, classrefdtypep, "Class type is unlinked to its ref type");
} else {

View File

@ -109,6 +109,8 @@ module mwith();
int c = 30;
Foo foo = new(c);
Baz baz = new;
typedef Baz baz_t;
baz_t baz1 = new;
Baz2 baz2 = new;
Bar bar = new;
Cls2 cls2 = new;
@ -149,6 +151,7 @@ module mwith();
if (foo.randomize() with { a > return_2(); } != 1) $stop;
// Check randomization of class with no constraints
if (baz.randomize() with { v inside {[2:10]}; } != 1) $stop;
if (baz1.randomize() with { v inside {[2:10]}; } != 1) $stop;
// Check randomization with captured non-static variable from different AstNodeModule
if (!bar.test_capture_of_callers_derived_var(foo)) $stop;
// Check randomization with non-captured non-static variable from different AstNodeModule