Add IMPORTSTAR warning on import::* inside scope.

This commit is contained in:
Wilson Snyder 2018-11-28 18:25:34 -05:00
parent 15af706286
commit 61e4b0a472
7 changed files with 67 additions and 10 deletions

View File

@ -12,6 +12,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
**** Add PROCASSWIRE error on behavioral assignments to wires, msg2737. [Neil Turton]
**** Add IMPORTSTAR warning on import::* inside $unit scope.
**** Fix --trace-lxt2 compile error on MinGW, msg2711. [HyungKi Jeong]
**** Fix hang on bad pattern keys, bug1364. [Matt Myers]

View File

@ -226,7 +226,7 @@ Verilator - Convert Verilog code to C++/SystemC
verilator --version
verilator --cc [options] [source_files.v]... [opt_c_files.cpp/c/cc/a/o/so]
verilator --sc [options] [source_files.v]... [opt_c_files.cpp/c/cc/a/o/so]
verilator --lint-only [source_files.v]...
verilator --lint-only -Wall [source_files.v]...
=head1 DESCRIPTION
@ -1414,8 +1414,8 @@ received from third parties.
Disable all code style related warning messages (note by default they are
already disabled). This is equivalent to "-Wno-DECLFILENAME -Wno-DEFPARAM
-Wno-INCABSPATH -Wno-PINCONNECTEMPTY -Wno-PINNOCONNECT -Wno-SYNCASYNCNET
-Wno-UNDRIVEN -Wno-UNUSED -Wno-VARHIDDEN".
-Wno-IMPORTSTAR -Wno-INCABSPATH -Wno-PINCONNECTEMPTY -Wno-PINNOCONNECT
-Wno-SYNCASYNCNET -Wno-UNDRIVEN -Wno-UNUSED -Wno-VARHIDDEN".
=item -Wno-fatal
@ -3579,6 +3579,16 @@ Emacs, available from L<http://www.veripool.org/>
Ignoring this warning will only suppress the lint check, it will simulate
correctly.
=item IMPORTSTAR
Warns that an "import I<package>::*" statement is in $unit scope. This
causes the imported symbols to polute the global namespace, defeating much
of the purpose of having a package. Generally "import ::*" should only be
used inside a lower scope such as a package or module.
Disabled by default as this is a code style warning; it will simulate
correctly.
=item IMPURE
Warns that a task or function that has been marked with /*verilator

View File

@ -77,8 +77,9 @@ public:
GENCLK, // Generated Clock
IFDEPTH, // If statements too deep
IMPERFECTSCH, // Imperfect schedule (disabled by default)
IMPLICIT, // Implicit wire
IMPURE, // Impure function not being inlined
IMPLICIT, // Implicit wire
IMPORTSTAR, // Import::* in $unit
IMPURE, // Impure function not being inlined
INCABSPATH, // Include has absolute path
INFINITELOOP, // Infinite loop
INITIALDLY, // Initial delayed statement
@ -136,7 +137,7 @@ public:
"CMPCONST", "COLONPLUS", "COMBDLY",
"DEFPARAM", "DECLFILENAME",
"ENDLABEL", "GENCLK",
"IFDEPTH", "IMPERFECTSCH", "IMPLICIT", "IMPURE",
"IFDEPTH", "IMPERFECTSCH", "IMPLICIT", "IMPORTSTAR", "IMPURE",
"INCABSPATH", "INFINITELOOP", "INITIALDLY",
"LITENDIAN", "MODDUP",
"MULTIDRIVEN",
@ -185,9 +186,10 @@ public:
|| m_e==BLKSEQ
|| m_e==DEFPARAM
|| m_e==DECLFILENAME
|| m_e==INCABSPATH
|| m_e==PINCONNECTEMPTY
|| m_e==PINNOCONNECT
|| m_e==IMPORTSTAR
|| m_e==INCABSPATH
|| m_e==PINCONNECTEMPTY
|| m_e==PINNOCONNECT
|| m_e==SYNCASYNCNET
|| m_e==UNDRIVEN
|| m_e==UNUSED

View File

@ -1020,7 +1020,11 @@ class LinkDotFindVisitor : public AstNVisitor {
virtual void visit(AstPackageImport* nodep) {
UINFO(4," Link: "<<nodep<<endl);
VSymEnt* srcp = m_statep->getNodeSym(nodep->packagep());
if (nodep->name()!="*") {
if (nodep->name()=="*") {
if (m_curSymp == m_statep->dunitEntp()) {
nodep->v3warn(IMPORTSTAR,"Import::* in $unit scope may pollute global namespace");
}
} else {
VSymEnt* impp = srcp->findIdFlat(nodep->name());
if (!impp) {
nodep->v3error("Import object not found: "<<nodep->packagep()->prettyName()<<"::"<<nodep->prettyName());

View File

@ -0,0 +1,3 @@
%Warning-IMPORTSTAR: t/t_lint_importstar_bad.v:10: Import::* in $unit scope may pollute global namespace
%Warning-IMPORTSTAR: Use "/* verilator lint_off IMPORTSTAR */" and lint_on around source to disable this message.
%Error: Exiting due to

View File

@ -0,0 +1,23 @@
#!/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.
scenarios(vlt_all => 1);
compile(
v_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME"],
fails => 1,
verilator_make_gcc => 0,
make_top_shell => 0,
make_main => 0,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,13 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2018 by Wilson Snyder.
package defs;
int sig;
endpackage
import defs::*;
module t;
endmodule