Skip to content

Commit

Permalink
Fix randomizing current object with rand class instance member (ver…
Browse files Browse the repository at this point in the history
…ilator#5292)

Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
  • Loading branch information
kbieganski authored Jul 22, 2024
1 parent 8f44906 commit f5caa4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ class RandomizeMarkVisitor final : public VNVisitorConst {
m_baseToDerivedMap[basep].insert(nodep);
}
}
void visit(AstMethodCall* nodep) override {
void visit(AstNodeFTaskRef* nodep) override {
iterateChildrenConst(nodep);
if (nodep->name() != "randomize") return;
if (const AstClassRefDType* const classRefp
= VN_CAST(nodep->fromp()->dtypep()->skipRefp(), ClassRefDType)) {
AstClass* const classp = classRefp->classp();
AstClass* classp = m_classp;
if (const AstMethodCall* const methodCallp = VN_CAST(nodep, MethodCall)) {
if (const AstClassRefDType* const classRefp
= VN_CAST(methodCallp->fromp()->dtypep()->skipRefp(), ClassRefDType)) {
classp = classRefp->classp();
}
}
if (classp) {
classp->user1(true);
markMembers(classp);
}
iterateChildrenConst(nodep);
}
void visit(AstNodeFTaskRef* nodep) override {
iterateChildrenConst(nodep);
if (nodep->name() != "randomize") return;
if (m_classp) m_classp->user1(true);
}
void visit(AstConstraintExpr* nodep) override {
VL_RESTORER(m_constraintExprp);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@
// any use, without warranty, 2023 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0

class Member;
rand int m_val;
endclass

class Cls;
rand int m_val;
rand Member m_member;

function void test;
automatic int rand_result;
logic ok1 = 0, ok2 = 0;

m_val = 256;
m_member.m_val = 65535;
for (int i = 0; i < 20; i++) begin
rand_result = randomize();
if (rand_result != 1) $stop;
if (m_val != 256) ok1 = 1;
if (m_member.m_val != 65535) ok2 = 1;
end
if (!ok1) $stop;
if (!ok2) $stop;
endfunction

rand_result = randomize();
if (rand_result != 1) $stop;
function new;
m_member = new;
endfunction
endclass

Expand Down

0 comments on commit f5caa4b

Please sign in to comment.