Fix missing error on negative replicate (#3963).

This commit is contained in:
Wilson Snyder 2023-02-22 19:11:02 -05:00
parent 47a7e75841
commit 7559af5879
5 changed files with 66 additions and 6 deletions

View File

@ -47,7 +47,8 @@ Verilator 5.007 devel
* Fix constant format field widths (#3946). [Todd Strader]
* Fix class field linking when a super classes is a param (#3949). [Ryszard Rozak, Antmicro Ltd]
* Fix CMake bad C identifiers (#3948) (#3951). [Zixi Li]
* Fix build on HP PA architecture. (#3954) [John David Anglin]
* Fix build on HP PA architecture (#3954). [John David Anglin]
* Fix missing error on negative replicate (#3963). [Benjamin Menküc]
* Fix packed array structure replication.

View File

@ -1435,15 +1435,19 @@ V3Number& V3Number::opRepl(const V3Number& lhs,
// i op repl, L(i)*value(rhs) bit return
NUM_ASSERT_OP_ARGS1(lhs);
NUM_ASSERT_LOGIC_ARGS1(lhs);
setZero();
if (rhsval > 8192) {
if (rhsval > (1UL << 24)) {
v3error("More than a 16 Mbit replication, perhaps the replication factor"
" was two's-complement negative: "
<< rhsval);
} else if (rhsval > 8192) {
v3warn(WIDTHCONCAT, "More than a 8k bit replication is probably wrong: " << rhsval);
}
setZero();
int obit = 0;
for (unsigned times = 0; times < rhsval; times++) {
for (int bit = 0; bit < lhs.width(); bit++) {
for (unsigned times = 0; times < rhsval; ++times) {
for (int bit = 0; bit < lhs.width(); ++bit) {
setBit(obit, lhs.bitIs(bit));
obit++;
++obit;
}
}
return *this;

View File

@ -0,0 +1,5 @@
%Error: t/t_math_repl2_bad.v:28:30: More than a 16 Mbit replication, perhaps the replication factor was two's-complement negative: 4294967291
: ... In instance t
28 | out <= {{(P24 - P29){1'b0}}, in};
| ^
%Error: Internal Error: ../V3Number.h:#: `num` member accessed when data type is UNINITIALIZED

View File

@ -0,0 +1,19 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2010 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
scenarios(linter => 1);
lint(
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,31 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
module t(/*AUTOARG*/
// Outputs
out,
// Inputs
clk, in
);
parameter P32 = 32;
parameter P24 = 24;
localparam P29 = P24 + 5;
input clk;
output reg [P24-1:0] out;
input [P29 - 1:0] in;
always @(posedge clk) begin
if (P29 >= P24) begin
out <= in[P29 - 1 -: P24];
end
else begin
out <= {{(P24 - P29){1'b0}}, in};
end
end
endmodule