From a21bd8a417179ae2dd2be42251e7f2a0d6afac98 Mon Sep 17 00:00:00 2001 From: Adam Kostrzewski Date: Thu, 9 Jul 2026 16:33:28 +0200 Subject: [PATCH] Fix VlQueue falling into wrong template spec (#7914) --- include/verilated_random.h | 18 +++++++++--------- test_regress/t/t_randomize_queue_constraints.v | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/verilated_random.h b/include/verilated_random.h index 648ea560e..7c92c9aa1 100644 --- a/include/verilated_random.h +++ b/include/verilated_random.h @@ -377,12 +377,12 @@ public: } // Register queue of non-struct types - template + template typename std::enable_if::value, void>::type - write_var(VlQueue& var, int width, const char* name, int dimension, + write_var(VlQueue& var, int width, const char* name, int dimension, std::uint32_t randmodeIdx = std::numeric_limits::max()) { if (m_vars.find(name) == m_vars.end()) { - m_vars[name] = std::make_shared>>( + m_vars[name] = std::make_shared>>( name, width, &var, dimension, randmodeIdx); } if (dimension > 0) { @@ -394,9 +394,9 @@ public: } // Register queue of structs - template + template typename std::enable_if::value, void>::type - write_var(VlQueue& var, int width, const char* name, int dimension, + write_var(VlQueue& var, int width, const char* name, int dimension, std::uint32_t randmodeIdx = std::numeric_limits::max()) { if (dimension > 0) record_struct_arr(var, name, dimension, {}, {}); } @@ -488,8 +488,8 @@ public: } // Recursively record all elements in a queue - template - void record_arr_table(VlQueue& var, const std::string& name, int dimension, + template + void record_arr_table(VlQueue& var, const std::string& name, int dimension, std::vector indices, std::vector idxWidths) { if ((dimension > 0) && (var.size() != 0)) { idxWidths.push_back(32); @@ -562,8 +562,8 @@ public: } // Recursively process VlQueue of structs - template - void record_struct_arr(VlQueue& var, const std::string& name, int dimension, + template + void record_struct_arr(VlQueue& var, const std::string& name, int dimension, std::vector indices, std::vector idxWidths) { if ((dimension > 0) && (var.size() != 0)) { idxWidths.push_back(32); diff --git a/test_regress/t/t_randomize_queue_constraints.v b/test_regress/t/t_randomize_queue_constraints.v index 6677b110e..081b6c3a2 100644 --- a/test_regress/t/t_randomize_queue_constraints.v +++ b/test_regress/t/t_randomize_queue_constraints.v @@ -24,10 +24,12 @@ end class Foo; rand int m_intQueue[$]; + rand int m_intQueueSized[$:9]; rand int m_idx; function new; m_intQueue = '{10{0}}; + m_intQueueSized = '{10{0}}; endfunction constraint int_queue_c { @@ -37,6 +39,13 @@ class Foo; m_intQueue[i] inside {[0:127]}; } } + constraint int_queue_sized_c { + m_idx inside {[0:9]}; + m_intQueueSized[m_idx] == m_idx + 1; + foreach (m_intQueueSized[i]) { + m_intQueueSized[i] inside {[0:127]}; + } + } endclass module t_randomize_queue_constraints; @@ -47,6 +56,12 @@ module t_randomize_queue_constraints; $display("Queue: %p", foo.m_intQueue); `check_rand(foo, foo.m_intQueue[3], foo.m_intQueue[5] inside {[0:127]}); $display("Queue: %p", foo.m_intQueue); + + `check_rand(foo, foo.m_idx, foo.m_idx inside {[0:9]} && foo.m_intQueueSized[foo.m_idx] == foo.m_idx + 1); + $display("Queue: %p", foo.m_intQueueSized); + `check_rand(foo, foo.m_intQueueSized[3], foo.m_intQueueSized[5] inside {[0:127]}); + $display("Queue: %p", foo.m_intQueueSized); + $write("*-* All Finished *-*\n"); $finish; end