From efdc8d1cbf88e78e8dc75e2c33445ee2393f147c Mon Sep 17 00:00:00 2001 From: Pawel Klopotek Date: Tue, 19 May 2026 15:51:23 +0200 Subject: [PATCH] Fix unique_index method on assoc arrays with values differing from the keys (#7616) Signed-off-by: Pawel Klopotek --- docs/CONTRIBUTORS | 1 + include/verilated_types.h | 2 +- test_regress/t/t_assoc_method.v | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 834fb934f..5900260e4 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -218,6 +218,7 @@ Paul Bowen-Huggett Paul Swirhun Paul Wright Pawel Jewstafjew +Pawel Klopotek Pawel Kojma Pawel Sagan Pengcheng Xu diff --git a/include/verilated_types.h b/include/verilated_types.h index 8a3360016..1d721d3e5 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -1090,7 +1090,7 @@ public: } VlQueue unique_index() const { VlQueue out; - std::set saw; + std::set saw; for (const auto& i : m_map) { auto it = saw.find(i.second); if (it == saw.end()) { diff --git a/test_regress/t/t_assoc_method.v b/test_regress/t/t_assoc_method.v index 5405d1e37..3a7ecdfde 100644 --- a/test_regress/t/t_assoc_method.v +++ b/test_regress/t/t_assoc_method.v @@ -23,6 +23,7 @@ module t; int qv[$]; // Value returns int qi[$]; // Index returns point points_q[int]; + point points_qe[int]; // Empty points point points_qv[$]; int i; bit b; @@ -58,6 +59,12 @@ module t; qi.sort; `checkp(qi, "'{'h0, 'h1, 'h5}"); + qi = points_qe.unique_index(); + `checkp(qi, "'{}"); + + qi = points_q.unique_index(); + `checkh(qi.size, 3); + qi = points_q.find_first_index with (item.x == 1); `checkp(qi, "'{'h0}"); qi = points_q.find_first_index with (item.x == 10);