diff --git a/.gitignore b/.gitignore index 7545baa1d..2bfa23d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ verilator-config-version.cmake **/__pycache__/* **/_build/* **/obj_dir/* +/.vscode/ diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 125977415..ca842b952 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -64,6 +64,7 @@ Marshal Qiao Martin Schmidt Matthew Ballance Michael Killough +Michaël Lefebvre Mike Popoloski Miodrag Milanović Morten Borup Petersen diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 69a212c84..470120f63 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -3430,7 +3430,7 @@ private: virtual void visit(AstNode* nodep) override { // Default: Just iterate if (m_required) { - if (VN_IS(nodep, NodeDType) || VN_IS(nodep, Range)) { + if (VN_IS(nodep, NodeDType) || VN_IS(nodep, Range) || VN_IS(nodep, SliceSel)) { // Ignore dtypes for parameter type pins } else { nodep->v3error("Expecting expression to be constant, but can't convert a " diff --git a/test_regress/t/t_const_slicesel.pl b/test_regress/t/t_const_slicesel.pl new file mode 100755 index 000000000..becd8a5aa --- /dev/null +++ b/test_regress/t/t_const_slicesel.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl + +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 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 + +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } + +scenarios(linter => 1); + +lint( +); + +ok(1); +1; diff --git a/test_regress/t/t_const_slicesel.v b/test_regress/t/t_const_slicesel.v new file mode 100644 index 000000000..244fa28ae --- /dev/null +++ b/test_regress/t/t_const_slicesel.v @@ -0,0 +1,20 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2021 by Michael Lefebvre. + + +module t(/*AUTOARG*/); + +localparam int unsigned A2 [1:0] = '{5,6}; +localparam int unsigned A3 [2:0] = '{4,5,6}; + +// Matching sizes with slicesel are okay. +localparam int unsigned B22 [1:0] = A2[1:0]; +localparam int unsigned B33 [2:0] = A3[2:0]; + +// bug #3186 +localparam int unsigned B32_B [1:0] = A3[1:0]; +localparam int unsigned B32_T [1:0] = A3[2:1]; + +endmodule diff --git a/test_regress/t/t_const_slicesel_bad.pl b/test_regress/t/t_const_slicesel_bad.pl new file mode 100755 index 000000000..9d8b88724 --- /dev/null +++ b/test_regress/t/t_const_slicesel_bad.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003-2009 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 + +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } + +scenarios(linter => 1); + +lint( + fails => 1 +); + +ok(1); +1; diff --git a/test_regress/t/t_const_slicesel_bad.v b/test_regress/t/t_const_slicesel_bad.v new file mode 100644 index 000000000..15a7e0dc1 --- /dev/null +++ b/test_regress/t/t_const_slicesel_bad.v @@ -0,0 +1,14 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2021 by Michael Lefebvre. + + +module t(/*AUTOARG*/); + +localparam int unsigned A3 [2:0] = '{4,5,6}; + +// slicesel out of range should fail +localparam int unsigned B32_T [1:0] = A3[3:1]; + +endmodule