Fix preserving macro argument depth during stringification (#8592) (#8596)

This commit is contained in:
Martin Velay
2026-10-03 09:54:36 -04:00
committed by GitHub
parent 5c9a804e8b
commit 9f72509635
3 changed files with 27 additions and 1 deletions
+2 -1
View File
@@ -1425,7 +1425,8 @@ int V3PreProcImp::getStateToken() {
else if (stateIsDefname()) {
unputDefrefString("__IF_OFF_IGNORED_DEFINE");
}
m_lexp->m_parenLevel = 0;
// Stringification may still be inside another macro's argument list.
m_lexp->m_parenLevel = m_defRefs.empty() ? 0 : m_defRefs.top().parenLevel();
} else { // Finished a defref inside a upper defref,
// and not under stringification or join.
// Can't subst now, or
+6
View File
@@ -1,3 +1,9 @@
"foo-bar-qux"
""foo-bar-qux""
""
begin if (!((a_size) <= 2)) ; else begin msg = {"id", " ", $sformatf("Check failed (%s) %s", "!((a_size) <= 2)", "")}; end end
begin if (!((a_size) <= 2)) ; else begin msg = {"id", " ", $sformatf("Check failed (%s) %s", "!((a_size) <= 2)", "")}; end end
begin if (!((a_size) <= 2)) ; else begin msg = {"tag", " ", $sformatf("Check failed (%s) %s", "!((a_size) <= 2)", "message, )")}; end end
begin if (!((a_size) <= 2)) ; else begin msg = {"tag", " ", $sformatf("Check failed (%s) %s", "!((a_size) <= 2)", "nested")}; end end
begin if (!((a_size) <= 2) && !((other_size) <= 2)) ; else begin msg = {"tag", " ", $sformatf("Check failed (%s) %s", "!((a_size) <= 2) && !((other_size) <= 2)", "two macros")}; end end
received(($sformatf("%s", "value")), "tail", 7)
+19
View File
@@ -17,3 +17,22 @@
`STRIFY
`NESTED_STRIFY
`EMPTY_STRIFY
// Preserve the outer argument nesting across parameterized macros in stringification.
// verilog_format: off
`define BELOW_MAX(s_) ((s_) <= 2)
`define IDENTITY(x_) x_
`define rpt_fatal(MSG_, ID_) msg = {ID_, " ", MSG_};
`define CHECK(T_, MSG_="", SEV_=error, ID_="id") begin if (T_) ; else begin `rpt_``SEV_($sformatf("Check failed (%s) %s", `"T_`", MSG_), ID_) end end
`define CHECK_FATAL(T_, MSG_="", ID_="id") `CHECK(T_, MSG_, fatal, ID_)
`CHECK_FATAL(!((a_size) <= 2))
`CHECK_FATAL(!`BELOW_MAX(a_size))
`CHECK_FATAL(!`BELOW_MAX(a_size), "message, )", "tag")
`CHECK_FATAL(!`BELOW_MAX(`IDENTITY(a_size)), "nested", "tag")
`CHECK_FATAL(!`BELOW_MAX(a_size) && !`BELOW_MAX(other_size), "two macros", "tag")
`define STRING_ARG(x_) `"`IDENTITY(x_)`"
`define TAKE_ARGS(a_, b_, c_) received(a_, b_, c_)
`TAKE_ARGS(($sformatf("%s", `STRING_ARG(value))), "tail", 7)
// verilog_format: on