From 64af83161a6206dded99cbee812dd7991070d057 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Thu, 26 Oct 2023 23:17:23 +0200 Subject: [PATCH] Fix rand fields of reference types (#4627) --- src/V3Randomize.cpp | 5 +++-- test_regress/t/t_randomize_method.v | 16 ++++++++++++++++ test_regress/t/t_uvm_pkg_todo.vh | 20 +++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index af72b95c0d..31f72fc1e9 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -55,7 +55,8 @@ class RandomizeMarkVisitor final : public VNVisitorConst { for (auto* memberp = classp->stmtsp(); memberp; memberp = memberp->nextp()) { // If member is rand and of class type, mark its class if (VN_IS(memberp, Var) && VN_AS(memberp, Var)->isRand()) { - if (const auto* const classRefp = VN_CAST(memberp->dtypep(), ClassRefDType)) { + if (const auto* const classRefp + = VN_CAST(memberp->dtypep()->skipRefp(), ClassRefDType)) { auto* const rclassp = classRefp->classp(); if (!rclassp->user1()) { rclassp->user1(true); @@ -100,7 +101,7 @@ class RandomizeMarkVisitor final : public VNVisitorConst { iterateChildrenConst(nodep); if (nodep->name() != "randomize") return; if (const AstClassRefDType* const classRefp - = VN_CAST(nodep->fromp()->dtypep(), ClassRefDType)) { + = VN_CAST(nodep->fromp()->dtypep()->skipRefp(), ClassRefDType)) { AstClass* const classp = classRefp->classp(); classp->user1(true); markMembers(classp); diff --git a/test_regress/t/t_randomize_method.v b/test_regress/t/t_randomize_method.v index dc3fa9561e..69868eb485 100644 --- a/test_regress/t/t_randomize_method.v +++ b/test_regress/t/t_randomize_method.v @@ -113,6 +113,19 @@ class DeriveAndContainClsWithInt extends ClsWithInt; endfunction endclass +class ClsUsedOnlyHere; + rand int a; +endclass + +typedef ClsUsedOnlyHere cls_used_only_here_t; + +class ClsContainUsedOnlyHere; + rand cls_used_only_here_t c; + function new; + c = new; + endfunction +endclass + module t (/*AUTOARG*/); DerivedCls derived; @@ -121,6 +134,7 @@ module t (/*AUTOARG*/); ContainsNull cont; DeriveClsWithInt der_int; DeriveAndContainClsWithInt der_contain; + ClsContainUsedOnlyHere cls_cont_used; initial begin int rand_result; @@ -130,6 +144,7 @@ module t (/*AUTOARG*/); der_int = new; der_contain = new; base = derived; + cls_cont_used = new; for (int i = 0; i < 10; i++) begin rand_result = base.randomize(); rand_result = other.randomize(); @@ -166,6 +181,7 @@ module t (/*AUTOARG*/); `check_rand(der_int, der_int.a); `check_rand(der_contain, der_contain.cls1.a); `check_rand(der_contain, der_contain.a); + `check_rand(cls_cont_used, cls_cont_used.c.a); $write("*-* All Finished *-*\n"); $finish; diff --git a/test_regress/t/t_uvm_pkg_todo.vh b/test_regress/t/t_uvm_pkg_todo.vh index a2a4c6ff7e..58823aa812 100644 --- a/test_regress/t/t_uvm_pkg_todo.vh +++ b/test_regress/t/t_uvm_pkg_todo.vh @@ -21074,15 +21074,21 @@ typedef class uvm_tlm_extension_base; class uvm_tlm_generic_payload extends uvm_sequence_item; rand bit [63:0] m_address; rand uvm_tlm_command_e m_command; - rand byte unsigned m_data[]; + //TODO issue-4625 - Rand fields of dynamic array types + //TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'byte[]' + /*TODO rand*/ byte unsigned m_data[]; rand int unsigned m_length; rand uvm_tlm_response_status_e m_response_status; bit m_dmi; - rand byte unsigned m_byte_enable[]; + //TODO issue-4625 - Rand fields of dynamic array types + //TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'byte[]' + /*TODO rand*/ byte unsigned m_byte_enable[]; rand int unsigned m_byte_enable_length; rand int unsigned m_streaming_width; protected uvm_tlm_extension_base m_extensions [uvm_tlm_extension_base]; - local rand uvm_tlm_extension_base m_rand_exts[]; + //TODO issue-4625 - Rand fields of dynamic array types + //TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'CLASSREFDTYPE 'uvm_tlm_extension_base'[]' + local /*rand*/ uvm_tlm_extension_base m_rand_exts[]; typedef uvm_object_registry#(uvm_tlm_generic_payload,"uvm_tlm_generic_payload") type_id; static function uvm_tlm_generic_payload type_id_create (string name="", uvm_component parent=null, @@ -22446,7 +22452,9 @@ class uvm_reg_item extends uvm_sequence_item; uvm_elem_kind_e element_kind; uvm_object element; rand uvm_access_e kind; - rand uvm_reg_data_t value[]; + //TODO issue-4625 - Rand fields of dynamic array types + //TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'bit[]' + /*rand*/ uvm_reg_data_t value[]; constraint max_values { value.size() > 0 && value.size() < 1000; } rand uvm_reg_addr_t offset; uvm_status_e status; @@ -26866,7 +26874,9 @@ class uvm_reg_fifo extends uvm_reg; local uvm_reg_field value; local int m_set_cnt; local int unsigned m_size; - rand uvm_reg_data_t fifo[$]; + //TODO issue-4625 - Rand fields of dynamic array types + //TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'bit[$]' + /*rand*/ uvm_reg_data_t fifo[$]; constraint valid_fifo_size { fifo.size() <= m_size; }