diff --git a/Changes b/Changes index 6cefe24ee..2c30c431c 100644 --- a/Changes +++ b/Changes @@ -25,6 +25,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix trace overflow on huge arrays, bug834. [Geoff Barrett] +**** Fix quoted comment slashes in defines, bug845. [Adam Krolnik] + * Verilator 3.864 2014-09-21 diff --git a/src/V3PreLex.h b/src/V3PreLex.h index 17e20e6b0..1c5cf17ca 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -169,6 +169,7 @@ class V3PreLex { int m_pslParenLevel;// PSL Parenthesis (){} counting, so we can find final ; bool m_pslMoreNeeded;// Next // comment is really psl bool m_defCmtSlash; // /*...*/ comment in define had \ ending + bool m_defQuote; // Definition value inside quote string m_defValue; // Definition value being built. int m_enterExit; // For VL_LINE, the enter/exit level @@ -181,6 +182,7 @@ class V3PreLex { m_pedantic = false; m_formalLevel = 0; m_parenLevel = 0; + m_defQuote = false; m_defCmtSlash = false; m_tokFilelinep = filelinep; m_enterExit = 0; diff --git a/src/V3PreLex.l b/src/V3PreLex.l index b58b67132..58191a968 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -125,7 +125,7 @@ psl [p]sl {backslash}{crnl} { linenoInc(); yymore(); } {backslash}. { yymore(); } {quote} { yy_pop_state(); - if (LEXP->m_parenLevel || LEXP->m_formalLevel) { appendDefValue(yytext,yyleng); yyleng=0; } + if (LEXP->m_parenLevel || LEXP->m_defQuote) { LEXP->m_defQuote=false; appendDefValue(yytext,yyleng); yyleng=0; } else return (VP_STRING); } /* Stringification */ @@ -162,7 +162,7 @@ psl [p]sl <> { linenoInc(); yy_pop_state(); yyerrorf("Unterminated ( in define formal arguments."); yyleng=0; return VP_DEFFORM; } {crnl} { linenoInc(); appendDefValue((char*)"\n",1); } /* Include return so can maintain output line count */ [\\]{crnl} { linenoInc(); appendDefValue((char*)"\\\n",2); } /* Include return so can maintain output line count */ -{quote} { yy_push_state(STRMODE); yymore(); } /* Legal only in default values */ +{quote} { LEXP->m_defQuote=true; yy_push_state(STRMODE); yymore(); } /* Legal only in default values */ "`\\`\"" { appendDefValue(yytext,yyleng); } /* Maybe illegal, otherwise in default value */ {tickquote} { appendDefValue(yytext,yyleng); } /* Maybe illegal, otherwise in default value */ [{\[] { LEXP->m_formalLevel++; appendDefValue(yytext,yyleng); } @@ -179,7 +179,8 @@ psl [p]sl <> { linenoInc(); yy_pop_state(); yytext=(char*)"\n"; yyleng=1; return (VP_DEFVALUE); } /* Technically illegal, but people complained */ {crnl} { linenoInc(); yy_pop_state(); yytext=(char*)"\n"; yyleng=1; return (VP_DEFVALUE); } [\\]{crnl} { linenoInc(); appendDefValue((char*)"\\\n",2); } /* Return, AND \ is part of define value */ -[^\/\*\n\r\\]+ | +{quote} { LEXP->m_defQuote=true; yy_push_state(STRMODE); yymore(); } +[^\/\*\n\r\\\"]+ | [\\][^\n\r] | . { appendDefValue(yytext,yyleng); } diff --git a/test_regress/t/t_preproc.out b/test_regress/t/t_preproc.out index 5c918d41f..7e0bddfd2 100644 --- a/test_regress/t/t_preproc.out +++ b/test_regress/t/t_preproc.out @@ -788,6 +788,10 @@ module t; initial $write("GOT='%s' EXP='%s'\n", "foo `A(bar) baz", "foo `A(bar) baz"); + + + + initial $write("Slashed=`%s'\n", "1//2.3"); endmodule @@ -809,4 +813,4 @@ predef 1 1 predef 2 2 -`line 544 "t/t_preproc.v" 2 +`line 548 "t/t_preproc.v" 2 diff --git a/test_regress/t/t_preproc.v b/test_regress/t/t_preproc.v index 25ad54031..7137314f2 100644 --- a/test_regress/t/t_preproc.v +++ b/test_regress/t/t_preproc.v @@ -520,6 +520,10 @@ module t; `define A(name) boo name hiss initial $write("GOT='%s' EXP='%s'\n", `STR(`A(bar)), "foo `A(bar) baz"); `undef A `undef STR + //---- + // bug845 +`define SLASHED "1//2.3" + initial $write("Slashed=`%s'\n", `SLASHED); endmodule //====================================================================== // IEEE mandated predefines