From 88bd479bc76e156a5afb629e343a06ab1a50866f Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 22 Sep 2024 12:25:35 -0400 Subject: [PATCH] Add error on instances without parenthesis. --- Changes | 1 + src/V3LinkCells.cpp | 13 +++++++------ test_regress/t/t_class_membersel_int.v | 2 +- test_regress/t/t_class_packed.v | 10 +++++----- test_regress/t/t_event_control_expr.v | 2 +- test_regress/t/t_fallback_bad.v | 4 ++-- test_regress/t/t_func_const2_bad.v | 8 ++++---- test_regress/t/t_func_const3_bad.v | 8 ++++---- test_regress/t/t_func_dotted.v | 2 +- test_regress/t/t_gen_missing.v | 4 ++-- test_regress/t/t_hier_task.v | 4 ++-- test_regress/t/t_implements_noninterface_bad.v | 2 +- test_regress/t/t_inc_relink.v | 2 +- test_regress/t/t_inst_paren_bad.out | 5 +++++ test_regress/t/t_inst_paren_bad.py | 16 ++++++++++++++++ test_regress/t/t_inst_paren_bad.v | 12 ++++++++++++ test_regress/t/t_interface_paren_missing_bad.out | 2 +- test_regress/t/t_interface_typo_bad.out | 2 +- test_regress/t/t_interface_typo_bad.v | 2 +- test_regress/t/t_math_real_public.v | 2 +- test_regress/t/t_mod_recurse1.v | 6 +++--- test_regress/t/t_param_avec.v | 6 +++--- test_regress/t/t_param_width_loc_bad.v | 2 +- test_regress/t/t_split_var_1_bad.v | 4 ++-- test_regress/t/t_var_static_assign_decl_bad.v | 2 +- 25 files changed, 79 insertions(+), 44 deletions(-) create mode 100644 test_regress/t/t_inst_paren_bad.out create mode 100755 test_regress/t/t_inst_paren_bad.py create mode 100644 test_regress/t/t_inst_paren_bad.v diff --git a/Changes b/Changes index 2b14c8b99..577bc616a 100644 --- a/Changes +++ b/Changes @@ -27,6 +27,7 @@ Verilator 5.029 devel * Support named event locals (#5422). [Krzysztof Bieganski, Antmicro Ltd.] * Support basic dist constraints (#5431). [Arkadiusz Kozdra, Antmicro Ltd.] * Support inside array constraints (#5448). [Arkadiusz Kozdra, Antmicro Ltd.] +* Add error on instances without parenthesis. * Add partial coverage symbol and branch data in lcov info files (#5388). [Andrew Nolte] * Add method to check if there are VPI callbacks of the given type (#5399). [Kaleb Barrett] * Remove warning on unsized numbers exceeding 32-bits. diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index 1e543197e..c5ed8bc35 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -490,12 +490,13 @@ class LinkCellsVisitor final : public VNVisitor { nodep->addNextHere(varp); nodep->hasIfaceVar(true); } - if (nodep->hasNoParens()) { - nodep->v3error("Interface instantiation " - << nodep->prettyNameQ() << " requires parenthesis\n" - << nodep->warnMore() << "... Suggest use '" << nodep->prettyName() - << "()'"); - } + } + if (nodep->hasNoParens()) { + // Need in the grammar, otherwise it looks like "id/*data_type*/ id/*new_var*/;" + nodep->v3error("Instantiation " << nodep->prettyNameQ() + << " requires parenthesis (IEEE 1800-2023 23.3.2)\n" + << nodep->warnMore() << "... Suggest use '" + << nodep->prettyName() << "()'"); } if (nodep->modp()) { // iterateChildren(nodep); diff --git a/test_regress/t/t_class_membersel_int.v b/test_regress/t/t_class_membersel_int.v index a0367f11d..68e70f22b 100644 --- a/test_regress/t/t_class_membersel_int.v +++ b/test_regress/t/t_class_membersel_int.v @@ -20,5 +20,5 @@ module Sub; endmodule module t; - Sub foo; + Sub foo(); endmodule diff --git a/test_regress/t/t_class_packed.v b/test_regress/t/t_class_packed.v index 676557e43..daef3ec55 100644 --- a/test_regress/t/t_class_packed.v +++ b/test_regress/t/t_class_packed.v @@ -10,11 +10,11 @@ module t (/*AUTOARG*/ ); input clk; - //TODO sub #(.WIDTH(1)) w1; - //TODO sub #(.WIDTH(2)) w2; - //TODO sub #(.WIDTH(3)) w3; - //TODO sub #(.WIDTH(4)) w4; - sub #(.WIDTH(5)) w5; + //TODO sub #(.WIDTH(1)) w1(); + //TODO sub #(.WIDTH(2)) w2(); + //TODO sub #(.WIDTH(3)) w3(); + //TODO sub #(.WIDTH(4)) w4(); + sub #(.WIDTH(5)) w5(); always @ (posedge clk) begin $write("*-* All Finished *-*\n"); diff --git a/test_regress/t/t_event_control_expr.v b/test_regress/t/t_event_control_expr.v index 23fc5bc55..74456d898 100644 --- a/test_regress/t/t_event_control_expr.v +++ b/test_regress/t/t_event_control_expr.v @@ -142,7 +142,7 @@ module t(/*AUTOARG*/ `endif `endif - t_cstmt u_cstmt; + t_cstmt u_cstmt(); int cyc = 0; diff --git a/test_regress/t/t_fallback_bad.v b/test_regress/t/t_fallback_bad.v index 522f0c565..6722238a7 100644 --- a/test_regress/t/t_fallback_bad.v +++ b/test_regress/t/t_fallback_bad.v @@ -14,11 +14,11 @@ module subm; endmodule module submo; - subm sub2; + subm sub2(); endmodule module t; - submo sub1; + submo sub1(); class Base;endclass class Cls extends Base; diff --git a/test_regress/t/t_func_const2_bad.v b/test_regress/t/t_func_const2_bad.v index c90343878..f4515b317 100644 --- a/test_regress/t/t_func_const2_bad.v +++ b/test_regress/t/t_func_const2_bad.v @@ -29,7 +29,7 @@ module b8 c9 #(.A (A), .B (8)) - c9; + c9(); endmodule @@ -39,9 +39,9 @@ module t; localparam P14 = f_add2(2, 3, f_add(4, 5)); //localparam P24 = f_add2(7, 8, 9); - b8 b8; - b8 #(.A (6)) b8_a6; - b8 #(.A (7)) b8_a7; + b8 b8(); + b8 #(.A (6)) b8_a6(); + b8 #(.A (7)) b8_a7(); initial begin // Should never get here diff --git a/test_regress/t/t_func_const3_bad.v b/test_regress/t/t_func_const3_bad.v index 9d6d7fe32..9d45b03a9 100644 --- a/test_regress/t/t_func_const3_bad.v +++ b/test_regress/t/t_func_const3_bad.v @@ -19,15 +19,15 @@ module b9 c9 #(.A (A), .B (9)) - c9; + c9(); endmodule module t; - b9 b9; - b9 #(.A (100)) b900; - b9 #(.A (1000)) b9k; + b9 b9(); + b9 #(.A (100)) b900(); + b9 #(.A (1000)) b9k(); initial begin // Should never get here diff --git a/test_regress/t/t_func_dotted.v b/test_regress/t/t_func_dotted.v index e858b2ef8..17653192b 100644 --- a/test_regress/t/t_func_dotted.v +++ b/test_regress/t/t_func_dotted.v @@ -156,4 +156,4 @@ module b; endmodule : b -bind ma b u_b[0:1]; +bind ma b u_b[0:1](); diff --git a/test_regress/t/t_gen_missing.v b/test_regress/t/t_gen_missing.v index 44dad55f1..459c7fb65 100644 --- a/test_regress/t/t_gen_missing.v +++ b/test_regress/t/t_gen_missing.v @@ -7,9 +7,9 @@ module t; // verilator lint_off PINMISSING `ifdef T_GEN_MISSING_BAD - foobar #(.FOO_TYPE(1)) foobar; // This means we should instatiate missing module + foobar #(.FOO_TYPE(1)) foobar(); // This means we should instatiate missing module `elsif T_GEN_MISSING - foobar #(.FOO_TYPE(0)) foobar; // This means we should instatiate foo0 + foobar #(.FOO_TYPE(0)) foobar(); // This means we should instatiate foo0 `else `error "Bad Test" `endif diff --git a/test_regress/t/t_hier_task.v b/test_regress/t/t_hier_task.v index 42fe3eff2..ec20d1d63 100644 --- a/test_regress/t/t_hier_task.v +++ b/test_regress/t/t_hier_task.v @@ -5,8 +5,8 @@ // SPDX-License-Identifier: CC0-1.0 module mod_a; - mod_inner u_inner; - mod_a_mon u_a_mon; + mod_inner u_inner(); + mod_a_mon u_a_mon(); initial begin bit x; diff --git a/test_regress/t/t_implements_noninterface_bad.v b/test_regress/t/t_implements_noninterface_bad.v index 95ff76301..51c036928 100644 --- a/test_regress/t/t_implements_noninterface_bad.v +++ b/test_regress/t/t_implements_noninterface_bad.v @@ -17,5 +17,5 @@ class ClsBad2 extends Icls; endclass module t (/*AUTOARG*/); - Cls c; + ClsBad2 c; endmodule diff --git a/test_regress/t/t_inc_relink.v b/test_regress/t/t_inc_relink.v index fcaf80289..089f1cf34 100644 --- a/test_regress/t/t_inc_relink.v +++ b/test_regress/t/t_inc_relink.v @@ -28,7 +28,7 @@ module C; // Like above but in a module endmodule module t; // Actually use those to test relinking - C c; + C c(); initial begin A::t(); diff --git a/test_regress/t/t_inst_paren_bad.out b/test_regress/t/t_inst_paren_bad.out new file mode 100644 index 000000000..e19bc13b5 --- /dev/null +++ b/test_regress/t/t_inst_paren_bad.out @@ -0,0 +1,5 @@ +%Error: t/t_inst_paren_bad.v:11:8: Instantiation 'sub_inst' requires parenthesis (IEEE 1800-2023 23.3.2) + : ... Suggest use 'sub_inst()' + 11 | sub sub_inst; + | ^~~~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_inst_paren_bad.py b/test_regress/t/t_inst_paren_bad.py new file mode 100755 index 000000000..31228c9a7 --- /dev/null +++ b/test_regress/t/t_inst_paren_bad.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2024 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 + +import vltest_bootstrap + +test.scenarios('linter') + +test.lint(fails=True, expect_filename=test.golden_filename) + +test.passes() diff --git a/test_regress/t/t_inst_paren_bad.v b/test_regress/t/t_inst_paren_bad.v new file mode 100644 index 000000000..c7f6c7775 --- /dev/null +++ b/test_regress/t/t_inst_paren_bad.v @@ -0,0 +1,12 @@ +// 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 + +module sub; +endmodule + +module t(/*AUTOARG*/); + sub sub_inst; // No () +endmodule diff --git a/test_regress/t/t_interface_paren_missing_bad.out b/test_regress/t/t_interface_paren_missing_bad.out index 161dad3fc..70a167b83 100644 --- a/test_regress/t/t_interface_paren_missing_bad.out +++ b/test_regress/t/t_interface_paren_missing_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_interface_paren_missing_bad.v:13:9: Interface instantiation 'intf_i' requires parenthesis +%Error: t/t_interface_paren_missing_bad.v:13:9: Instantiation 'intf_i' requires parenthesis (IEEE 1800-2023 23.3.2) : ... Suggest use 'intf_i()' 13 | intf intf_i; | ^~~~~~ diff --git a/test_regress/t/t_interface_typo_bad.out b/test_regress/t/t_interface_typo_bad.out index 3f80ecf61..f2efc97e3 100644 --- a/test_regress/t/t_interface_typo_bad.out +++ b/test_regress/t/t_interface_typo_bad.out @@ -2,7 +2,7 @@ 14 | foo_intf foo | ^~~~~~~~ %Error: t/t_interface_typo_bad.v:22:4: Cannot find file containing interface: 'fo_intf' - 22 | fo_intf the_foo; + 22 | fo_intf the_foo(); | ^~~~~~~ %Error: t/t_interface_typo_bad.v:27:15: Found definition of 'the_foo' as a CELL but expected a variable 27 | .foo (the_foo) diff --git a/test_regress/t/t_interface_typo_bad.v b/test_regress/t/t_interface_typo_bad.v index f684ba85c..542715b91 100644 --- a/test_regress/t/t_interface_typo_bad.v +++ b/test_regress/t/t_interface_typo_bad.v @@ -19,7 +19,7 @@ endmodule module t (/*AUTOARG*/); // Intentional typo, compiler should point this out, or that fo_intf does // not match foo_intf on the submod port map - fo_intf the_foo; + fo_intf the_foo(); submod submod_inst diff --git a/test_regress/t/t_math_real_public.v b/test_regress/t/t_math_real_public.v index 8f5e46fd2..58f4c2017 100644 --- a/test_regress/t/t_math_real_public.v +++ b/test_regress/t/t_math_real_public.v @@ -5,7 +5,7 @@ // SPDX-License-Identifier: CC0-1.0 module t; - sub #(.REAL(2.0)) sub; + sub #(.REAL(2.0)) sub(); endmodule module sub (); diff --git a/test_regress/t/t_mod_recurse1.v b/test_regress/t/t_mod_recurse1.v index 785e38869..1c0c742d5 100644 --- a/test_regress/t/t_mod_recurse1.v +++ b/test_regress/t/t_mod_recurse1.v @@ -15,13 +15,13 @@ module rec; generate if (DEPTH==1) begin - rec #(.DEPTH(DEPTH+1)) sub; + rec #(.DEPTH(DEPTH+1)) sub(); end else if (DEPTH==2) begin - rec #(.DEPTH(DEPTH+1)) subb; + rec #(.DEPTH(DEPTH+1)) subb(); end else if (DEPTH==3) begin - bottom #(.DEPTH(DEPTH+1)) bot; + bottom #(.DEPTH(DEPTH+1)) bot(); end endgenerate endmodule diff --git a/test_regress/t/t_param_avec.v b/test_regress/t/t_param_avec.v index d56974f9a..87f70486d 100644 --- a/test_regress/t/t_param_avec.v +++ b/test_regress/t/t_param_avec.v @@ -12,9 +12,9 @@ module t (/*AUTOARG*/ clk ); input clk; - sub #(.IDX(0), .CHK(10)) i0; - sub #(.IDX(2), .CHK(12)) i2; - sub #(.IDX(7), .CHK(17)) i7; + sub #(.IDX(0), .CHK(10)) i0(); + sub #(.IDX(2), .CHK(12)) i2(); + sub #(.IDX(7), .CHK(17)) i7(); always @ (posedge clk) begin $write("*-* All Finished *-*\n"); $finish; diff --git a/test_regress/t/t_param_width_loc_bad.v b/test_regress/t/t_param_width_loc_bad.v index 3d61f5d93..df9cdf5b4 100644 --- a/test_regress/t/t_param_width_loc_bad.v +++ b/test_regress/t/t_param_width_loc_bad.v @@ -12,7 +12,7 @@ module t (/*AUTOARG*/ input clk; // bug1624 - test #(.param(32'd0)) test_i; + test #(.param(32'd0)) test_i(); initial begin $write("*-* All Finished *-*\n"); diff --git a/test_regress/t/t_split_var_1_bad.v b/test_regress/t/t_split_var_1_bad.v index 110bd2c68..32f1f2107 100644 --- a/test_regress/t/t_split_var_1_bad.v +++ b/test_regress/t/t_split_var_1_bad.v @@ -24,8 +24,8 @@ module t(); sub0 i_sub0(.addr(addr), .rd_data(rd_data0)); sub1 i_sub1(.addr(addr), .rd_data(rd_data2)); - sub2 i_sub2; - sub3 i_sub3; + sub2 i_sub2(); + sub3 i_sub3(); ifs i_ifs(); function int bad_func(inout logic [3:0] inout_port /*verilator split_var*/, diff --git a/test_regress/t/t_var_static_assign_decl_bad.v b/test_regress/t/t_var_static_assign_decl_bad.v index 2c4217372..db25de778 100644 --- a/test_regress/t/t_var_static_assign_decl_bad.v +++ b/test_regress/t/t_var_static_assign_decl_bad.v @@ -139,7 +139,7 @@ module t(input clk); endfunction iface iface(); - prog prog; + prog prog(); logic in; no_warn no_warn(.in(in), .clk(clk));