Support $sformat with runtime format string (#7212). (#7257)

Fixes #7212.
This commit is contained in:
Wilson Snyder
2026-03-14 22:43:56 -04:00
committed by GitHub
parent 42cf5d3be2
commit 602ee384de
32 changed files with 1389 additions and 957 deletions
+10 -4
View File
@@ -319,10 +319,16 @@ class PremitVisitor final : public VNVisitor {
iterateChildren(nodep);
// Any strings sent to a display must be var of string data type,
// to avoid passing a pointer to a temporary.
for (AstNodeExpr *expp = nodep->exprsp(), *nextp; expp; expp = nextp) {
nextp = VN_AS(expp->nextp(), NodeExpr);
if (expp->isString() && !VN_IS(expp, VarRef)) {
AstVar* const varp = createTemp(expp);
AstNodeExpr* exprsp = nodep->exprsp();
if (nodep->exprFormat()) exprsp = VN_AS(exprsp->nextp(), NodeExpr);
for (AstNodeExpr *argp = exprsp, *nextp; argp; argp = nextp) {
nextp = VN_AS(argp->nextp(), NodeExpr);
AstSFormatArg* const fargp = VN_CAST(argp, SFormatArg);
AstNodeExpr* const subargp = fargp ? fargp->exprp() : argp;
// Must avoid taking address of rvalue, so even Const needs a temp
if (subargp->isString() && !VN_IS(subargp, VarRef)) {
AstVar* const varp = createTemp(subargp);
// Do not remove VarRefs to this in V3Const
varp->noSubst(true);
}