From 1c738c6b83867d220f2338f2ea9eaa4e9e3d20b0 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Thu, 5 Oct 2023 13:21:33 +0200 Subject: [PATCH] Fix object destruction after a copy constructor (#4540) (#4541) --- include/verilated_types.h | 2 +- test_regress/t/t_class_copy2.pl | 21 +++++++++++++++++++ test_regress/t/t_class_copy2.v | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 test_regress/t/t_class_copy2.pl create mode 100644 test_regress/t/t_class_copy2.v diff --git a/include/verilated_types.h b/include/verilated_types.h index cb40b0e82..9eae185d5 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -1478,7 +1478,7 @@ class VlClass VL_NOT_FINAL : public VlDeletable { public: // CONSTRUCTORS VlClass() { refCountInc(); } - VlClass(const VlClass& copied) {} + VlClass(const VlClass& copied) { refCountInc(); } ~VlClass() override = default; }; diff --git a/test_regress/t/t_class_copy2.pl b/test_regress/t/t_class_copy2.pl new file mode 100755 index 000000000..aabcde63e --- /dev/null +++ b/test_regress/t/t_class_copy2.pl @@ -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 2020 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; diff --git a/test_regress/t/t_class_copy2.v b/test_regress/t/t_class_copy2.v new file mode 100644 index 000000000..9fb72e670 --- /dev/null +++ b/test_regress/t/t_class_copy2.v @@ -0,0 +1,36 @@ +// 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 + +`define stop $stop +`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); $stop; end while(0); + +class Cls; + bit x = 1; +endclass + +module t (/*AUTOARG*/); + Cls obj1; + Cls obj2; + + initial begin + obj1 = new; + `checkh(obj1.x, 1); + + obj1.x = 0; + obj2 = new obj1; + `checkh(obj2.x, 0); + + obj2.x = 1; + `checkh(obj1.x, 0); + `checkh(obj2.x, 1); + + obj2.x = 0; + `checkh(obj2.x, 0); + + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule