diff --git a/Changes b/Changes
index e57aa65b2..06cc6c4cf 100644
--- a/Changes
+++ b/Changes
@@ -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]
diff --git a/bin/verilator b/bin/verilator
index 3da979c51..c343f45f1 100755
--- a/bin/verilator
+++ b/bin/verilator
@@ -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
Ignoring this warning will only suppress the lint check, it will simulate
correctly.
+=item IMPORTSTAR
+
+Warns that an "import I::*" 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
diff --git a/src/V3Error.h b/src/V3Error.h
index 6f54b645b..c79c5e3f0 100644
--- a/src/V3Error.h
+++ b/src/V3Error.h
@@ -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
diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp
index 9d1a3656d..0a75171a8 100644
--- a/src/V3LinkDot.cpp
+++ b/src/V3LinkDot.cpp
@@ -1020,7 +1020,11 @@ class LinkDotFindVisitor : public AstNVisitor {
virtual void visit(AstPackageImport* nodep) {
UINFO(4," Link: "<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: "<packagep()->prettyName()<<"::"<prettyName());
diff --git a/test_regress/t/t_lint_importstar_bad.out b/test_regress/t/t_lint_importstar_bad.out
new file mode 100644
index 000000000..d0a800b7d
--- /dev/null
+++ b/test_regress/t/t_lint_importstar_bad.out
@@ -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
diff --git a/test_regress/t/t_lint_importstar_bad.pl b/test_regress/t/t_lint_importstar_bad.pl
new file mode 100755
index 000000000..413db0e11
--- /dev/null
+++ b/test_regress/t/t_lint_importstar_bad.pl
@@ -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;
+
diff --git a/test_regress/t/t_lint_importstar_bad.v b/test_regress/t/t_lint_importstar_bad.v
new file mode 100644
index 000000000..bea7837a3
--- /dev/null
+++ b/test_regress/t/t_lint_importstar_bad.v
@@ -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