diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index 4d705e1cf..8365a9ad0 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -89,7 +89,7 @@ void V3ParseImp::timescalePreproc(FileLine* fl, const char* textp) { VTimescale prec; VTimescale::parseSlashed(fl, textp, unit /*ref*/, prec /*ref*/); m_timeLastUnit = v3Global.opt.timeComputeUnit(unit); - v3Global.rootp()->timeprecisionMerge(fileline(), prec); + v3Global.rootp()->timeprecisionMerge(fl, prec); } void V3ParseImp::timescaleMod(FileLine* fl, AstNodeModule* modp, bool unitSet, double unitVal, bool precSet, double precVal) { @@ -118,7 +118,7 @@ void V3ParseImp::timescaleMod(FileLine* fl, AstNodeModule* modp, bool unitSet, d fl->v3error("timeunit/timeprecision not under a module"); } } - v3Global.rootp()->timeprecisionMerge(fileline(), prec); + v3Global.rootp()->timeprecisionMerge(fl, prec); } void V3ParseImp::verilatorCmtLintSave() { m_lintState.push_back(*parsep()->fileline()); } @@ -134,15 +134,16 @@ void V3ParseImp::verilatorCmtLintRestore(FileLine* fl) { void V3ParseImp::verilatorCmtLint(FileLine* fl, const char* textp, bool warnOff) { const char* sp = textp; - while (*sp && !isspace(*sp)) sp++; - while (*sp && isspace(*sp)) sp++; - while (*sp && !isspace(*sp)) sp++; - while (*sp && isspace(*sp)) sp++; + while (*sp && !isspace(*sp)) ++sp; + while (*sp && isspace(*sp)) ++sp; + while (*sp && !isspace(*sp)) ++sp; + while (*sp && isspace(*sp)) ++sp; string msg = sp; string::size_type pos; if ((pos = msg.find('*')) != string::npos) msg.erase(pos); + // Use parsep()->fileline() as want to affect later FileLine's warnings if (!(parsep()->fileline()->warnOff(msg, warnOff))) { - if (!parsep()->optFuture(msg)) { + if (!v3Global.opt.isFuture(msg)) { fl->v3error("Unknown verilator lint message code: '" << msg << "', in '" << textp << "'"); } @@ -157,10 +158,12 @@ void V3ParseImp::verilatorCmtBad(FileLine* fl, const char* textp) { while (isspace(cmtparse[0])) cmtparse.replace(0, 1, ""); string cmtname; for (int i = 0; isalnum(cmtparse[i]); i++) { cmtname += cmtparse[i]; } - if (!parsep()->optFuture(cmtname)) fl->v3error("Unknown verilator comment: '" << textp << "'"); + if (!v3Global.opt.isFuture(cmtname)) { + fl->v3error("Unknown verilator comment: '" << textp << "'"); + } } -void V3ParseImp::errorPreprocDirective(const char* textp) { +void V3ParseImp::errorPreprocDirective(FileLine* fl, const char* textp) { // Find all `preprocessor spelling candidates // Can't make this static as might get more defines later when read cells VSpellCheck speller; @@ -171,9 +174,9 @@ void V3ParseImp::errorPreprocDirective(const char* textp) { } V3PreShell::candidateDefines(&speller); string suggest = speller.bestCandidateMsg(textp); - fileline()->v3error("Define or directive not defined: '" - << textp << "'\n" - << (suggest.empty() ? "" : fileline()->warnMore() + suggest)); + fl->v3error("Define or directive not defined: '" + << textp << "'\n" + << (suggest.empty() ? "" : fl->warnMore() + suggest)); } void V3ParseImp::tag(const char* text) { diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 26841ba70..51e73b82e 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -152,7 +152,7 @@ public: void verilatorCmtLintSave(); void verilatorCmtLintRestore(FileLine* fl); void verilatorCmtBad(FileLine* fl, const char* textp); - void errorPreprocDirective(const char* textp); + static void errorPreprocDirective(FileLine* fl, const char* textp); void tag(const char* text); void tagNodep(AstNode* nodep) { m_tagNodep = nodep; } AstNode* tagNodep() const { return m_tagNodep; } diff --git a/src/verilog.l b/src/verilog.l index b49e67add..1b1a93a3e 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -1021,7 +1021,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} /* Default rules - leave last */ { - "`"[a-zA-Z_0-9]+ { FL_FWD; PARSEP->errorPreprocDirective(yytext); FL_BRK; } + "`"[a-zA-Z_0-9]+ { FL; PARSEP->errorPreprocDirective(yylval.fl, yytext); FL_BRK; } "//"[^\n]* { FL_FWD; FL_BRK; } /* throw away single line comments */ . { FL; return yytext[0]; } /* return single char ops. */ } diff --git a/test_regress/t/t_flag_future_bad.out b/test_regress/t/t_flag_future_bad.out new file mode 100644 index 000000000..388ebe036 --- /dev/null +++ b/test_regress/t/t_flag_future_bad.out @@ -0,0 +1,10 @@ +%Error: t/t_flag_future.v:8:7: Unknown verilator lint message code: 'FUTURE1', in '/*verilator lint_off FUTURE1*/' + 8 | /*verilator lint_off FUTURE1*/ + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +%Error: t/t_flag_future.v:11:7: Unknown verilator comment: '/*verilator FUTURE2*/' + 11 | /*verilator FUTURE2*/ + | ^~~~~~~~~~~~~~~~~~~~~ +%Error: t/t_flag_future.v:12:7: Unknown verilator comment: '/*verilator FUTURE2 blah blah*/' + 12 | /*verilator FUTURE2 blah blah*/ + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_flag_future_bad.pl b/test_regress/t/t_flag_future_bad.pl new file mode 100755 index 000000000..60a812ac4 --- /dev/null +++ b/test_regress/t/t_flag_future_bad.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); + +top_filename("t/t_flag_future.v"); + +lint( + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); + +1;