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 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 --trace-lxt2 compile error on MinGW, msg2711. [HyungKi Jeong]
**** Fix hang on bad pattern keys, bug1364. [Matt Myers] **** 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 --version
verilator --cc [options] [source_files.v]... [opt_c_files.cpp/c/cc/a/o/so] 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 --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 =head1 DESCRIPTION
@ -1414,8 +1414,8 @@ received from third parties.
Disable all code style related warning messages (note by default they are Disable all code style related warning messages (note by default they are
already disabled). This is equivalent to "-Wno-DECLFILENAME -Wno-DEFPARAM already disabled). This is equivalent to "-Wno-DECLFILENAME -Wno-DEFPARAM
-Wno-INCABSPATH -Wno-PINCONNECTEMPTY -Wno-PINNOCONNECT -Wno-SYNCASYNCNET -Wno-IMPORTSTAR -Wno-INCABSPATH -Wno-PINCONNECTEMPTY -Wno-PINNOCONNECT
-Wno-UNDRIVEN -Wno-UNUSED -Wno-VARHIDDEN". -Wno-SYNCASYNCNET -Wno-UNDRIVEN -Wno-UNUSED -Wno-VARHIDDEN".
=item -Wno-fatal =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 Ignoring this warning will only suppress the lint check, it will simulate
correctly. 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 =item IMPURE
Warns that a task or function that has been marked with /*verilator Warns that a task or function that has been marked with /*verilator

View File

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

View File

@ -1020,7 +1020,11 @@ class LinkDotFindVisitor : public AstNVisitor {
virtual void visit(AstPackageImport* nodep) { virtual void visit(AstPackageImport* nodep) {
UINFO(4," Link: "<<nodep<<endl); UINFO(4," Link: "<<nodep<<endl);
VSymEnt* srcp = m_statep->getNodeSym(nodep->packagep()); 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()); VSymEnt* impp = srcp->findIdFlat(nodep->name());
if (!impp) { if (!impp) {
nodep->v3error("Import object not found: "<<nodep->packagep()->prettyName()<<"::"<<nodep->prettyName()); 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