From fedf347b1af6757dd1dc29eec20b170ff1545262 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 25 Dec 2010 15:50:07 -0500 Subject: [PATCH] With --Wall, add INCABSPATH warning on `include with absolute paths. --- Changes | 4 +++- bin/verilator | 11 +++++++++++ src/V3Error.h | 3 +++ src/V3PreShell.cpp | 3 +++ test_regress/t/t_lint_incabspath.pl | 19 ++++++++++++++++++ test_regress/t/t_lint_incabspath.v | 9 +++++++++ test_regress/t/t_lint_incabspath_bad.pl | 26 +++++++++++++++++++++++++ 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100755 test_regress/t/t_lint_incabspath.pl create mode 100644 test_regress/t/t_lint_incabspath.v create mode 100755 test_regress/t/t_lint_incabspath_bad.pl diff --git a/Changes b/Changes index a2e71d303..922d4d822 100644 --- a/Changes +++ b/Changes @@ -16,7 +16,9 @@ indicates the contributor was also the author of the fix; Thanks! *** Suppress WIDTH warnings when adding/subtracting 1'b1. -*** With --Wall, add DEFPARAM warning to find deprecated defparam statements. +*** With --Wall, add DEFPARAM warning on deprecated defparam statements. + +*** With --Wall, add INCABSPATH warning on `include with absolute paths. **** When running with VERILATOR_ROOT, optionally find binaries under bin. diff --git a/bin/verilator b/bin/verilator index 5210910b5..149dc06ed 100755 --- a/bin/verilator +++ b/bin/verilator @@ -2437,6 +2437,17 @@ Verilator cannot schedule these variables correctly. Ignoring this warning may make Verilator simulations differ from other simulators. +=item INCABSPATH + +Warns that an `include filename specifies an absolute path. This means the +code will not work on any other system with a different file system layout. +Instead of using absolute paths, relative paths (preferably without any +directory specified whatever) should be used, and +include used on the +command line to specify the top include source directory. + +Disabled by default as this is a code style warning, it will simulate +correctly. + =item LITENDIAN Warns that a vector is declared with little endian bit numbering diff --git a/src/V3Error.h b/src/V3Error.h index 922d1bfd4..a7e581d56 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -68,6 +68,7 @@ public: IMPERFECTSCH, // Imperfect schedule (disabled by default) IMPLICIT, // Implicit wire IMPURE, // Impure function not being inlined + INCABSPATH, // Include has absolute path LITENDIAN, // Little bit endian vector MODDUP, // Duplicate module MULTIDRIVEN, // Driven from multiple blocks @@ -103,6 +104,7 @@ public: "CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CMPCONST", "COMBDLY", "DEFPARAM", "STMTDLY", "SYMRSVDWORD", "GENCLK", "IMPERFECTSCH", "IMPLICIT", "IMPURE", + "INCABSPATH", "LITENDIAN", "MODDUP", "MULTIDRIVEN", "REDEFMACRO", "UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNSIGNED", "UNUSED", @@ -132,6 +134,7 @@ public: || m_e==WIDTH); } // Warnings that are style only bool styleError() const { return ( m_e==DEFPARAM + || m_e==INCABSPATH || m_e==VARHIDDEN ); } }; inline bool operator== (V3ErrorCode lhs, V3ErrorCode rhs) { return (lhs.m_e == rhs.m_e); } diff --git a/src/V3PreShell.cpp b/src/V3PreShell.cpp index 575bcba05..e2150a7f2 100644 --- a/src/V3PreShell.cpp +++ b/src/V3PreShell.cpp @@ -90,6 +90,9 @@ protected: } void preprocInclude (FileLine* fl, const string& modname) { + if (modname[0]=='/' || modname[0]=='\\') { + fl->v3warn(INCABSPATH,"`include with absolute path should be relative, and use +include: "< ["--lint-only"], + verilator_make_gcc => 0, + make_top_shell => 0, + make_main => 0, + ) if $Self->{v3}; + +ok(1); +1; + diff --git a/test_regress/t/t_lint_incabspath.v b/test_regress/t/t_lint_incabspath.v new file mode 100644 index 000000000..47a56c2b3 --- /dev/null +++ b/test_regress/t/t_lint_incabspath.v @@ -0,0 +1,9 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2010 by Wilson Snyder. + +`include "/dev/null" + +module t; +endmodule diff --git a/test_regress/t/t_lint_incabspath_bad.pl b/test_regress/t/t_lint_incabspath_bad.pl new file mode 100755 index 000000000..08aba95af --- /dev/null +++ b/test_regress/t/t_lint_incabspath_bad.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2008 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. + +top_filename("t/t_lint_incabspath.v"); + +compile ( + v_flags2 => ["--lint-only -Wall"], + fails=>1, + verilator_make_gcc => 0, + make_top_shell => 0, + make_main => 0, + expect=> +'%Warning-INCABSPATH: t/t_lint_incabspath.v:\d+: `include with absolute path should be relative, and use \+include: /dev/null +%Warning-INCABSPATH: Use .* to disable this message. +%Error: Exiting due to.*', + ) if $Self->{v3}; + +ok(1); +1; +