From 974020348553d617c83f1a787f736a3a25103d3f Mon Sep 17 00:00:00 2001 From: Kornel Uriasz Date: Thu, 9 Jul 2026 17:40:24 +0200 Subject: [PATCH] Fix VL_TO_STRING function for array of structs (#7912) Signed-off-by: Kornel Uriasz --- src/V3Width.cpp | 8 +++++++- test_regress/t/t_sys_sformat.v | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 8d3c00e74..ac0cfdcf5 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -6680,7 +6680,13 @@ class WidthVisitor final : public VNVisitor { } else if (dtypep->isString()) { formatAttr = VFormatAttr::STRING; } else if (isFormatNonNumericArg(dtypep)) { - if (AstVarRef* const varRefp = VN_CAST(argp, VarRef)) { + const AstNodeExpr* formatTypeArgp = argp; + if (const AstCMethodHard* const cmethp = VN_CAST(formatTypeArgp, CMethodHard)) { + if (cmethp->method() == VCMethod::ARRAY_AT) formatTypeArgp = cmethp->fromp(); + } else if (const AstArraySel* const arselp = VN_CAST(formatTypeArgp, ArraySel)) { + formatTypeArgp = arselp->fromp(); + } + if (const AstVarRef* const varRefp = VN_CAST(formatTypeArgp, VarRef)) { if (AstClassRefDType* const classRefp = VN_CAST(varRefp->dtypep(), ClassRefDType)) { if (classRefp->classp()) { diff --git a/test_regress/t/t_sys_sformat.v b/test_regress/t/t_sys_sformat.v index 8dbe49b34..d0f5f0e44 100644 --- a/test_regress/t/t_sys_sformat.v +++ b/test_regress/t/t_sys_sformat.v @@ -43,10 +43,17 @@ module t ( int mem[2] = '{1, 2}; string s; + typedef struct{ + integer dummy; + } test_struct_t; + + test_struct_t structs[1]; + initial begin n = 4'b1100; q = 64'h1234_5678_abcd_0123; wide = "hello-there12345"; + $sformat(str, "n=%b q=%d w=%s", n, q, wide); `checks(str, "n=1100 q= 1311768467750060323 w=hello-there12345"); @@ -135,6 +142,11 @@ module t ( $display(mem); // Implied %p + structs[0].dummy = 0; + + s = $sformatf("%p", structs[0]); + `checks(s, "'{dummy:'h0}"); + $write("*-* All Finished *-*\n"); $finish; end