From e465a30eee8957cb1986f81a2af669b7d662041e Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 1 Dec 2022 18:27:36 -0500 Subject: [PATCH] Fix lint_off EOFNEWLINE in .vlt files (#3796). --- Changes | 1 + src/V3Config.cpp | 2 +- src/V3PreProc.cpp | 2 ++ test_regress/t/t_lint_eofline_vlt.pl | 36 +++++++++++++++++++++++++++ test_regress/t/t_lint_eofline_vlt.vlt | 9 +++++++ test_regress/t/t_vlt_warn.pl | 2 +- 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100755 test_regress/t/t_lint_eofline_vlt.pl create mode 100755 test_regress/t/t_lint_eofline_vlt.vlt diff --git a/Changes b/Changes index 3dfd580ca..63f6a978b 100644 --- a/Changes +++ b/Changes @@ -30,6 +30,7 @@ Verilator 5.003 devel * Fix wait 0. * Fix comparing ranged slices of unpacked arrays. * Fix empty string literals converting to string types (#3774). [miree] +* Fix lint_off EOFNEWLINE in .vlt files (#3796). [Andrew Nolte] Verilator 5.002 2022-10-29 diff --git a/src/V3Config.cpp b/src/V3Config.cpp index 1cefb40cf..1c98e2725 100644 --- a/src/V3Config.cpp +++ b/src/V3Config.cpp @@ -319,7 +319,7 @@ public: const int curlineno = filelinep->lastLineno(); for (; m_lastIgnore.it != m_ignLines.end(); ++m_lastIgnore.it) { if (m_lastIgnore.it->m_lineno > curlineno) break; - // UINFO(9, " Hit " << *m_lastIt << endl); + // UINFO(9, " Hit " << *m_lastIgnore.it << endl); filelinep->warnOn(m_lastIgnore.it->m_code, m_lastIgnore.it->m_on); } if (false && debug() >= 9) { diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 2236eb934..6957331fd 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -19,6 +19,7 @@ #include "V3PreProc.h" +#include "V3Config.h" #include "V3Error.h" #include "V3File.h" #include "V3Global.h" @@ -843,6 +844,7 @@ void V3PreProcImp::openFile(FileLine*, VInFilter* filterp, const string& filenam FileLine* const fl = new FileLine{flsp}; fl->contentLineno(eof_lineno); fl->column(eof_newline + 1, eof_newline + 1); + V3Config::applyIgnores(fl); // As preprocessor hasn't otherwise applied yet fl->v3warn(EOFNEWLINE, "Missing newline at end of file (POSIX 3.206).\n" << fl->warnMore() << "... Suggest add newline."); } diff --git a/test_regress/t/t_lint_eofline_vlt.pl b/test_regress/t/t_lint_eofline_vlt.pl new file mode 100755 index 000000000..9bea83d86 --- /dev/null +++ b/test_regress/t/t_lint_eofline_vlt.pl @@ -0,0 +1,36 @@ +#!/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 + +use IO::File; +use strict; +use vars qw($Self); + +scenarios(vlt => 1); + +sub gen { + my $filename = shift; + + my $fh = IO::File->new(">$filename"); + $fh->print("// Generated by t_lint_eofline_bad.pl\n"); + $fh->print("module t;\n"); + $fh->print("// No newline below:\n"); + $fh->print("endmodule"); # Intentionally no newline +} + +top_filename("$Self->{obj_dir}/t_lint_eofline_bad.v"); + +gen($Self->{top_filename}); + +lint( + verilator_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME t/t_lint_eofline_vlt.vlt"], + ); + +ok(1); +1; diff --git a/test_regress/t/t_lint_eofline_vlt.vlt b/test_regress/t/t_lint_eofline_vlt.vlt new file mode 100755 index 000000000..7c575bb83 --- /dev/null +++ b/test_regress/t/t_lint_eofline_vlt.vlt @@ -0,0 +1,9 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2010 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +`verilator_config + +lint_off -rule EOFNEWLINE --file "*.v" diff --git a/test_regress/t/t_vlt_warn.pl b/test_regress/t/t_vlt_warn.pl index 9d2a06917..32163cf4e 100755 --- a/test_regress/t/t_vlt_warn.pl +++ b/test_regress/t/t_vlt_warn.pl @@ -11,7 +11,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(vlt => 1); lint( - verilator_flags2 => ["--lint-only t/t_vlt_warn.vlt -Wall"], + verilator_flags2 => ["--lint-only -Wall t/t_vlt_warn.vlt"], ); ok(1);