Fix preprocessor to respect strings in joins (#5007)

This adheres more to the wording used in IEEE 1800-2017 22.5.1,
specifying the join operator to be more of a delimiter than join:

> A `` delimits lexical tokens without introducing white space,
> allowing identifiers to be constructed from arguments.

Before, string RHS arguments to the join operator were silently dropped.

Signed-off-by: Arkadiusz Kozdra <akozdra@antmicro.com>
This commit is contained in:
Arkadiusz Kozdra 2024-03-20 13:54:23 +01:00 committed by GitHub
parent 26f15e11c4
commit 88831ca21b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 4 deletions

View File

@ -1411,7 +1411,7 @@ int V3PreProcImp::getStateToken() {
}
}
case ps_JOIN: {
if (tok == VP_SYMBOL || tok == VP_TEXT) {
if (tok == VP_SYMBOL || tok == VP_TEXT || tok == VP_STRING) {
UASSERT(!m_joinStack.empty(), "`` join stack empty, but in a ``");
const string lhs = m_joinStack.top();
m_joinStack.pop();
@ -1423,7 +1423,7 @@ int V3PreProcImp::getStateToken() {
unputString(out);
statePop();
goto next_tok;
} else if (tok == VP_EOF || tok == VP_WHITE || tok == VP_COMMENT || tok == VP_STRING) {
} else if (tok == VP_EOF || tok == VP_WHITE || tok == VP_COMMENT) {
// Other compilers just ignore this, so no warning
// "Expecting symbol to terminate ``; whitespace etc cannot
// follow ``. Found: "+tokenName(tok)+"\n"

View File

@ -1025,6 +1025,11 @@ Second line"""
`line 707 "t/t_preproc.v" 0
"string argument"
`line 711 "t/t_preproc.v" 0
predef 0 0
predef 1 1
@ -1045,4 +1050,4 @@ predef 2 2
`line 729 "t/t_preproc.v" 0
`line 733 "t/t_preproc.v" 0

View File

@ -704,6 +704,10 @@ Second line"""
`QQQ
`QQQS("""QQQ defval""")
// string concat bug
`define IDENTITY(arg) ``arg
`IDENTITY("string argument")
//======================================================================
// IEEE mandated predefines
`undefineall // undefineall should have no effect on these

View File

@ -1028,6 +1028,11 @@ Second line"""
"""QQQ defval"""
`line 707 "t/t_preproc.v" 0
// string concat bug
"string argument"
`line 711 "t/t_preproc.v" 0
//======================================================================
// IEEE mandated predefines
// undefineall should have no effect on these
@ -1050,4 +1055,4 @@ predef 2 2
// After `undefineall above, for testing --dump-defines
`line 729 "t/t_preproc.v" 0
`line 733 "t/t_preproc.v" 0