diff --git a/Changes b/Changes index 869d015ab..e5c1ca47c 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ The contributors that suggested a given feature are shown in []. Thanks! * Verilator 4.027 devel +**** Add error on misused define. [Topa Tota] + * Verilator 4.026 2020-01-11 diff --git a/src/V3PreLex.l b/src/V3PreLex.l index b827e19f8..afd2329f7 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -244,6 +244,11 @@ bom [\357\273\277] // Note paren level 0 means before "(" of starting args // Level 1 means "," between arguments // Level 2+ means one inside the () of an argument + if (LEXP->m_parenLevel == 1) { // Starting ( + if (!VString::isWhitespace(LEXP->m_defValue)) { + yyerrorf("Illegal text before '(' that starts define arguments"); + } + } if (LEXP->m_parenLevel>1) { appendDefValue(yytext, yyleng); FL_BRK; } else { diff --git a/src/V3String.cpp b/src/V3String.cpp index 9c2849872..0a4bba3c8 100644 --- a/src/V3String.cpp +++ b/src/V3String.cpp @@ -114,6 +114,13 @@ string VString::spaceUnprintable(const string& str) { return out; } +bool VString::isWhitespace(const string& str) { + for (string::const_iterator pos = str.begin(); pos != str.end(); ++pos) { + if (!isspace(*pos)) return false; + } + return true; +} + //###################################################################### // VHashSha256 diff --git a/src/V3String.h b/src/V3String.h index fc20a418a..e473b2b77 100644 --- a/src/V3String.h +++ b/src/V3String.h @@ -74,6 +74,8 @@ public: // Replace any unprintable with space // This includes removing tabs, so column tracking is correct static string spaceUnprintable(const string& str); + // Return true if only whitespace or "" + static bool isWhitespace(const string& str); }; //###################################################################### diff --git a/test_regress/t/t_pp_defparen_bad.out b/test_regress/t/t_pp_defparen_bad.out new file mode 100644 index 000000000..58bbefbb8 --- /dev/null +++ b/test_regress/t/t_pp_defparen_bad.out @@ -0,0 +1,7 @@ +%Error: t/t_pp_defparen_bad.v:9: Illegal text before '(' that starts define arguments + ( 1,2) + ^ +%Error: t/t_pp_defparen_bad.v:9: syntax error, unexpected '(' +((val 1) + (2)) + ^ +%Error: Exiting due to diff --git a/test_regress/t/t_pp_defparen_bad.pl b/test_regress/t/t_pp_defparen_bad.pl new file mode 100755 index 000000000..18439afa9 --- /dev/null +++ b/test_regress/t/t_pp_defparen_bad.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +scenarios(vlt => 1); + +lint( + verilator_flags2 => ["-Wpedantic"], + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_pp_defparen_bad.v b/test_regress/t/t_pp_defparen_bad.v new file mode 100644 index 000000000..232d54dbc --- /dev/null +++ b/test_regress/t/t_pp_defparen_bad.v @@ -0,0 +1,9 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2020 by Wilson Snyder. + +`define test(a1,a2) ((a1) + (a2)) + +`test val + ( 1,2)