diff --git a/Changes b/Changes index a47207a0c..df9fab7bd 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,7 @@ Verilator 5.023 devel **Minor:** * Add DFG 'regularize' pass, and improve variable removal (#4937). [Geza Lore] +* Add error on calling static function without object (#4962). * Support public packed struct / union (#860) (#4878). [Kefa Chen] * Change installation to be relocatable (#4927). [Geza Lore] * Fix __Vlip undefined error in --freloop (#4824). [Justin Yao Du] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 696b881a3..aee14cc61 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -5793,6 +5793,12 @@ class WidthVisitor final : public VNVisitor { } UASSERT_OBJ(nodep->taskp(), nodep, "Unlinked"); if (nodep->didWidth()) return; + if ((nodep->taskp()->classMethod() && !nodep->taskp()->isStatic()) + && !VN_IS(m_procedurep, InitialAutomatic) + && (!m_ftaskp || !m_ftaskp->classMethod() || m_ftaskp->isStatic())) { + nodep->v3error("Cannot call non-static member function " + << nodep->prettyNameQ() << " without object (IEEE 1800-2023 8.10)"); + } userIterate(nodep->taskp(), nullptr); // And do the arguments to the task/function too processFTaskRefArgs(nodep); diff --git a/test_regress/t/t_class_member_bad3.out b/test_regress/t/t_class_member_bad3.out deleted file mode 100644 index 4712e0838..000000000 --- a/test_regress/t/t_class_member_bad3.out +++ /dev/null @@ -1,7 +0,0 @@ -%Error: t/t_class_member_bad3.v:16:12: Static access to non-static member variable 'member' - 16 | Foo::member = 1; - | ^~~~~~ -%Error: t/t_class_member_bad3.v:17:12: Static access to non-static task/function 'method' - 17 | Foo::method(); - | ^~~~~~ -%Error: Exiting due to diff --git a/test_regress/t/t_class_member_bad3.v b/test_regress/t/t_class_member_bad3.v deleted file mode 100644 index ccde97456..000000000 --- a/test_regress/t/t_class_member_bad3.v +++ /dev/null @@ -1,19 +0,0 @@ -// 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 - -class Foo; - int member; - - task method; endtask -endclass - -module t; - initial begin - Foo foo = new; - Foo::member = 1; - Foo::method(); - end -endmodule diff --git a/test_regress/t/t_class_misstatic_bad.out b/test_regress/t/t_class_misstatic_bad.out new file mode 100644 index 000000000..dbb381827 --- /dev/null +++ b/test_regress/t/t_class_misstatic_bad.out @@ -0,0 +1,13 @@ +%Error: t/t_class_misstatic_bad.v:31:7: Cannot call non-static member function 'nonstatic' without object (IEEE 1800-2023 8.10) + : ... note: In instance 't' + 31 | nonstatic(); + | ^~~~~~~~~ +%Error: t/t_class_misstatic_bad.v:38:12: Cannot call non-static member function 'nonstatic' without object (IEEE 1800-2023 8.10) + : ... note: In instance 't' + 38 | Cls::nonstatic(); + | ^~~~~~~~~ +%Error: t/t_class_misstatic_bad.v:44:12: Cannot call non-static member function 'nonstatic' without object (IEEE 1800-2023 8.10) + : ... note: In instance 't' + 44 | Cls::nonstatic(); + | ^~~~~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_class_member_bad3.pl b/test_regress/t/t_class_misstatic_bad.pl similarity index 74% rename from test_regress/t/t_class_member_bad3.pl rename to test_regress/t/t_class_misstatic_bad.pl index 55ca436af..9c9fb65a0 100755 --- a/test_regress/t/t_class_member_bad3.pl +++ b/test_regress/t/t_class_misstatic_bad.pl @@ -2,7 +2,7 @@ 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 +# 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. @@ -11,8 +11,8 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di scenarios(linter => 1); lint( - # fails => 1, # TODO bug4077 - # expect_filename => $Self->{golden_filename}, + fails => 1, + expect_filename => $Self->{golden_filename}, ); ok(1); diff --git a/test_regress/t/t_class_misstatic_bad.v b/test_regress/t/t_class_misstatic_bad.v new file mode 100644 index 000000000..3d4b0b0cd --- /dev/null +++ b/test_regress/t/t_class_misstatic_bad.v @@ -0,0 +1,49 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2024 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +class Cls; + int m_field = get_ok(); + function int get_ok(); + return 1; + endfunction + function void nonstatic(); + endfunction + static function void isst(); + endfunction +endclass + +class Bar; + function void bar(); + Cls::nonstatic(); // <--- bad static ref + Cls::isst(); + endfunction +endclass + +class Extends extends Cls; + function void ok(); + nonstatic(); + isst(); + endfunction + static function extstatic(); + nonstatic(); // <--- bad static ref + isst(); + endfunction +endclass + +module t; + function nonclassfunc(); + Cls::nonstatic(); // <--- bad static ref + Cls::isst(); + endfunction + initial begin + Bar obj = new(); + obj.bar(); + Cls::nonstatic(); // <--- bad static ref + Cls::isst(); + Extends::isst(); + $stop; + end +endmodule