Skip to content

Commit

Permalink
Fix insertion at queue's end (verilator#4619)
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Boronski <[email protected]>
Co-authored-by: Wilson Snyder <[email protected]>
  • Loading branch information
kboronski-ant and wsnyder authored Oct 25, 2023
1 parent cf6e362 commit f91259f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/verilated_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ class VlQueue final {

// function void q.insert(index, value);
void insert(int32_t index, const T_Value& value) {
if (VL_UNLIKELY(index < 0 || index >= m_deque.size())) return;
if (VL_UNLIKELY(index < 0 || index > m_deque.size())) return;
m_deque.insert(m_deque.begin() + index, value);
}

Expand Down
21 changes: 21 additions & 0 deletions test_regress/t/t_queue_insert_at_end.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2023 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(simulator => 1);

compile(
);

execute(
check_finished => 1,
);

ok(1);
1;
23 changes: 23 additions & 0 deletions test_regress/t/t_queue_insert_at_end.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Antmicro Ltd.
// SPDX-License-Identifier: CC0-1.0

module t();
initial begin
int queue[$];

queue.insert(0, 0);
if (queue.size() != 1) $stop;

queue.insert(1, 1);
if (queue.size() != 2) $stop;

if (queue[0] != 0) $stop;
if (queue[1] != 1) $stop;

$write("*-* All Finished *-*\n");
$finish;
end
endmodule

0 comments on commit f91259f

Please sign in to comment.