From ab74cafa20b143127156c0562eca24703193ed7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20I=2E=20B=C3=B6ttcher?= Date: Tue, 17 Mar 2026 19:39:51 +0100 Subject: [PATCH 01/11] Add option -gno-strict-parameter-declaration The standards requires that parameters must be declared before they are used. Using -gno-strict-parameter-declaration will allow using a parameter before declaration, e.g., in a port declaration, with the parameter declared in the body of the module. Prior to version 13 this was allowed, so there is a large body of existing code depending on the pre version 13 behaviour. --- Documentation/usage/command_line_flags.rst | 8 ++++++++ compiler.h | 6 ++++++ driver/iverilog.man.in | 6 ++++++ driver/main.c | 11 ++++++++++- main.cc | 7 +++++++ symbol_search.cc | 3 ++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 8f7f531b3..751818d42 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -131,6 +131,14 @@ These flags affect the general behavior of the compiler. containing an unsized constant number, and unsized constant numbers are not truncated to integer width. + * strict-parameter-declaration/no-strict-parameter-declaration + + The standards requires that parameters must be declared lexically + before they are used. Using -gno-strict-parameter-declaration + will allow using a parameter before declaration, e.g., in a port + declaration, with the parameter declared in the body of the + module. + * shared-loop-index/no-shared-loop-index Enable or disable the exclusion of for-loop control variables from diff --git a/compiler.h b/compiler.h index 307589aad..9548a85d0 100644 --- a/compiler.h +++ b/compiler.h @@ -210,6 +210,12 @@ extern bool gn_strict_expr_width_flag; loop. */ extern bool gn_shared_loop_index_flag; +/* If this flag is true (default), then parameters must be declared before + use. + use `-gno-strict-parameter-declaration` for pre version 13 behaviour. + */ +extern bool gn_strict_parameter_declaration; + static inline bool gn_system_verilog(void) { if (generation_flag >= GN_VER2005_SV) diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index be62ec10b..4f7bb40f2 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -150,6 +150,12 @@ parameter assignment is evaluated as a lossless expression, as is any expression containing an unsized constant number, and unsized constant numbers are not truncated to integer width. .TP 8 +.B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration +The standards requires that parameters must be declared lexically +before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP +will allow using a parameter before declaration, e.g., in a port +declaration, with the parameter declared in the body of the module. +.TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables from implicit event_expression lists. When enabled, if a for-loop control diff --git a/driver/main.c b/driver/main.c index 352ab9f45..c1de20333 100644 --- a/driver/main.c +++ b/driver/main.c @@ -134,6 +134,7 @@ const char*gen_strict_ca_eval = "no-strict-ca-eval"; const char*gen_strict_expr_width = "no-strict-expr-width"; const char*gen_shared_loop_index = "shared-loop-index"; const char*gen_verilog_ams = "no-verilog-ams"; +const char*gen_strict_parameter_declaration = "strict-parameter-declaration"; /* Boolean: true means use a default include dir, false means don't */ int gen_std_include = 1; @@ -815,6 +816,12 @@ static int process_generation(const char*name) else if (strcmp(name,"no-verilog-ams") == 0) gen_verilog_ams = "no-verilog-ams"; + else if (strcmp(name,"strict-parameter-declaration") == 0) + gen_strict_parameter_declaration = "strict-parameter-declaration"; + + else if (strcmp(name,"no-strict-parameter-declaration") == 0) + gen_strict_parameter_declaration = "no-strict-parameter-declaration"; + else { fprintf(stderr, "Unknown/Unsupported Language generation " "%s\n\n", name); @@ -837,7 +844,8 @@ static int process_generation(const char*name) " io-range-error | no-io-range-error\n" " strict-ca-eval | no-strict-ca-eval\n" " strict-expr-width | no-strict-expr-width\n" - " shared-loop-index | no-shared-loop-index\n"); + " shared-loop-index | no-shared-loop-index\n" + " strict-parameter-declaration | no-strict-parameter-declaration\n"); return 1; } @@ -1385,6 +1393,7 @@ int main(int argc, char **argv) fprintf(iconfig_file, "generation:%s\n", gen_strict_expr_width); fprintf(iconfig_file, "generation:%s\n", gen_shared_loop_index); fprintf(iconfig_file, "generation:%s\n", gen_verilog_ams); + fprintf(iconfig_file, "generation:%s\n", gen_strict_parameter_declaration); fprintf(iconfig_file, "generation:%s\n", gen_icarus); fprintf(iconfig_file, "warnings:%s\n", warning_flags); fprintf(iconfig_file, "ignore_missing_modules:%s\n", ignore_missing_modules ? "true" : "false"); diff --git a/main.cc b/main.cc index 99c080e0a..7ed4c7c50 100644 --- a/main.cc +++ b/main.cc @@ -117,6 +117,7 @@ bool gn_strict_ca_eval_flag = false; bool gn_strict_expr_width_flag = false; bool gn_shared_loop_index_flag = true; bool gn_verilog_ams_flag = false; +bool gn_strict_parameter_declaration = true; /* * For some generations we allow a system function to be called @@ -386,6 +387,12 @@ static void process_generation_flag(const char*gen) } else if (strcmp(gen,"no-shared-loop-index") == 0) { gn_shared_loop_index_flag = false; + } else if (strcmp(gen,"strict-parameter-declaration") == 0) { + gn_strict_parameter_declaration = true; + + } else if (strcmp(gen,"no-strict-parameter-declaration") == 0) { + gn_strict_parameter_declaration = false; + } else { } } diff --git a/symbol_search.cc b/symbol_search.cc index be8580018..9c00920e7 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -189,7 +189,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) { - if (prefix_scope || (scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + if (!gn_strict_parameter_declaration || prefix_scope + || (scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { path.push_back(path_tail); res->scope = scope; res->par_val = par; From 1f8991e382e6a508958537090ac4ff5f5190b9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20I=2E=20B=C3=B6ttcher?= Date: Tue, 17 Mar 2026 20:32:06 +0100 Subject: [PATCH 02/11] Emit a warning with -gno-strict-parameter-declaration When a parameter is used before declaration, a warning is printed, unless `-Wno-anachronisms`. --- Documentation/usage/command_line_flags.rst | 5 ++--- compiler.h | 5 +++-- driver/iverilog.man.in | 4 ++-- symbol_search.cc | 6 ++++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 751818d42..155d4ace9 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -135,9 +135,8 @@ These flags affect the general behavior of the compiler. The standards requires that parameters must be declared lexically before they are used. Using -gno-strict-parameter-declaration - will allow using a parameter before declaration, e.g., in a port - declaration, with the parameter declared in the body of the - module. + will allow using a parameter before declaration, with a + warning. The warning can be suppressed with -Wno-anachronisms. * shared-loop-index/no-shared-loop-index diff --git a/compiler.h b/compiler.h index 9548a85d0..eafc8aac9 100644 --- a/compiler.h +++ b/compiler.h @@ -211,8 +211,9 @@ extern bool gn_strict_expr_width_flag; extern bool gn_shared_loop_index_flag; /* If this flag is true (default), then parameters must be declared before - use. - use `-gno-strict-parameter-declaration` for pre version 13 behaviour. + use. `-gno-strict-parameter-declaration` allows to use parameters before + declaration, as prior to version 13. + A warning is emited with -Wanachronisms (default). */ extern bool gn_strict_parameter_declaration; diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 4f7bb40f2..1c0b9e44c 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -153,8 +153,8 @@ numbers are not truncated to integer width. .B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration The standards requires that parameters must be declared lexically before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP -will allow using a parameter before declaration, e.g., in a port -declaration, with the parameter declared in the body of the module. +will allow using a parameter before declaration, with a warning. +The warning can be suppressed with -Wno-anachronisms. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables diff --git a/symbol_search.cc b/symbol_search.cc index 9c00920e7..25f8483e3 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -195,6 +195,12 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->scope = scope; res->par_val = par; res->path_head = path; + if (warn_anachronisms && !prefix_scope + && !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + cerr << li->get_fileline() + << ": warning: parameter `" << path_tail.name + << "` used before declaration." << endl; + } return true; } else if (!res->decl_after_use) { res->decl_after_use = par; From 42f7d3a922ec9f60ec6d23e961a8f36ac4ab3196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20I=2E=20B=C3=B6ttcher?= Date: Wed, 18 Mar 2026 12:08:39 +0100 Subject: [PATCH 03/11] strict_param_decl: dedup use after decl test --- symbol_search.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/symbol_search.cc b/symbol_search.cc index 25f8483e3..cbe307ff9 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -189,14 +189,14 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (const NetExpr*par = scope->get_parameter(des, path_tail.name, res->type)) { - if (!gn_strict_parameter_declaration || prefix_scope - || (scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + bool decl_after_use = !prefix_scope + && !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos); + if (!gn_strict_parameter_declaration || !decl_after_use) { path.push_back(path_tail); res->scope = scope; res->par_val = par; res->path_head = path; - if (warn_anachronisms && !prefix_scope - && !(scope->get_parameter_lexical_pos(path_tail.name) <= lexical_pos)) { + if (warn_anachronisms && decl_after_use) { cerr << li->get_fileline() << ": warning: parameter `" << path_tail.name << "` used before declaration." << endl; From 54f17a2cb146294f235b87c53bb4746855b56ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20I=2E=20B=C3=B6ttcher?= Date: Wed, 18 Mar 2026 12:46:42 +0100 Subject: [PATCH 04/11] Add warning class -Wno-declaration-after-use With `-ggno-strict-parameter-declaration` a warning is issued for parameter use before declaration. This warning suppressed with the new class `-Wno-declaration-after-use`, instead of `-Wno-anachronisms`. --- Documentation/usage/command_line_flags.rst | 8 +++++++- compiler.h | 3 +++ driver/iverilog.man.in | 7 ++++++- driver/main.c | 12 +++++++++++- main.cc | 4 ++++ symbol_search.cc | 2 +- 6 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 155d4ace9..68c217a6d 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -136,7 +136,7 @@ These flags affect the general behavior of the compiler. The standards requires that parameters must be declared lexically before they are used. Using -gno-strict-parameter-declaration will allow using a parameter before declaration, with a - warning. The warning can be suppressed with -Wno-anachronisms. + warning. The warning can be suppressed with -Wno-declaration-after-use. * shared-loop-index/no-shared-loop-index @@ -267,6 +267,7 @@ These flags affect the general behavior of the compiler. -Wanachronisms -Wimplicit -Wimplicit-dimensions + -Wdeclaration-after-use -Wmacro-replacement -Wportbind -Wselect-range @@ -295,6 +296,11 @@ These flags affect the general behavior of the compiler. This flag is supported in release 10.1 or master branch snapshots after 2016-02-06. + * declaration-after-use + + With -gno-strict-parameter-declaration, issue a warning when a + parameter is declared after it is used. + * macro-redefinition This enables warnings when a macro is redefined, even if the macro text diff --git a/compiler.h b/compiler.h index eafc8aac9..0b5feca91 100644 --- a/compiler.h +++ b/compiler.h @@ -104,6 +104,9 @@ extern bool warn_sens_entire_arr; /* Warn about level-appropriate anachronisms. */ extern bool warn_anachronisms; +/* Warn about declaration after use (unless flaged as errors). */ +extern bool warn_decl_after_use; + /* Warn about nets that are references but not driven. */ extern bool warn_floating_nets; diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 1c0b9e44c..19ac06361 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -154,7 +154,7 @@ numbers are not truncated to integer width. The standards requires that parameters must be declared lexically before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP will allow using a parameter before declaration, with a warning. -The warning can be suppressed with -Wno-anachronisms. +The warning can be suppressed with -Wno-declaration-after-use. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables @@ -373,6 +373,11 @@ This enables warnings for creation of implicit declarations. For example, if a scalar wire X is used but not declared in the Verilog source, this will print a warning at its first use. +.TP 8 +.B declaration-after-use +This enables warnings for declarations after use, when +those are not flagged as errors (default). + .TP 8 .B macro-redefinition\fI | \fPmacro-replacement This enables preprocessor warnings when a macro is being redefined. diff --git a/driver/main.c b/driver/main.c index c1de20333..803e457c6 100644 --- a/driver/main.c +++ b/driver/main.c @@ -143,7 +143,7 @@ int gen_std_include = 1; of the include list. */ int gen_relative_include = 0; -char warning_flags[17] = "n"; +char warning_flags[18] = "nu"; int separate_compilation_flag = 0; @@ -528,6 +528,7 @@ static void process_warning_switch(const char*name) { if (strcmp(name,"all") == 0) { process_warning_switch("anachronisms"); + process_warning_switch("declaration-after-use"); process_warning_switch("implicit"); process_warning_switch("implicit-dimensions"); process_warning_switch("macro-replacement"); @@ -538,6 +539,9 @@ static void process_warning_switch(const char*name) } else if (strcmp(name,"anachronisms") == 0) { if (! strchr(warning_flags, 'n')) strcat(warning_flags, "n"); + } else if (strcmp(name,"declaration-after-use") == 0) { + if (! strchr(warning_flags, 'u')) + strcat(warning_flags, "u"); } else if (strcmp(name,"floating-nets") == 0) { if (! strchr(warning_flags, 'f')) strcat(warning_flags, "f"); @@ -579,6 +583,12 @@ static void process_warning_switch(const char*name) cp[0] = cp[1]; cp += 1; } + } else if (strcmp(name,"no-declaration-after-use") == 0) { + char*cp = strchr(warning_flags, 'u'); + if (cp) while (*cp) { + cp[0] = cp[1]; + cp += 1; + } } else if (strcmp(name,"no-floating-nets") == 0) { char*cp = strchr(warning_flags, 'f'); if (cp) while (*cp) { diff --git a/main.cc b/main.cc index 7ed4c7c50..8e71ef7b3 100644 --- a/main.cc +++ b/main.cc @@ -173,6 +173,7 @@ bool warn_ob_select = false; bool warn_sens_entire_vec = false; bool warn_sens_entire_arr = false; bool warn_anachronisms = false; +bool warn_decl_after_use = false; bool warn_floating_nets = false; /* @@ -767,6 +768,9 @@ static void read_iconfig_file(const char*ipath) case 'n': warn_anachronisms = true; break; + case 'u': + warn_decl_after_use = true; + break; default: break; } diff --git a/symbol_search.cc b/symbol_search.cc index cbe307ff9..11922e684 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -196,7 +196,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->scope = scope; res->par_val = par; res->path_head = path; - if (warn_anachronisms && decl_after_use) { + if (warn_decl_after_use && decl_after_use) { cerr << li->get_fileline() << ": warning: parameter `" << path_tail.name << "` used before declaration." << endl; From 7d438b66c8c8e1f45823831fb4ba1acb8e486fae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20I=2E=20B=C3=B6ttcher?= Date: Wed, 18 Mar 2026 17:59:33 +0100 Subject: [PATCH 05/11] add option -gno-strict-declaration The new option allows parameter, net and events to be used before declaration. With variants -gno-strict-net-declaration for nets and events, -gno-strict-parameter-declaration for parameters. --- Documentation/usage/command_line_flags.rst | 14 ++++++++++---- compiler.h | 11 +++++++++-- driver/iverilog.man.in | 11 ++++++++--- driver/main.c | 19 ++++++++++++++++++- main.cc | 7 +++++++ symbol_search.cc | 16 ++++++++++++++-- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 68c217a6d..73a2df9e1 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -131,12 +131,18 @@ These flags affect the general behavior of the compiler. containing an unsized constant number, and unsized constant numbers are not truncated to integer width. + * strict-declaration/no-strict-declaration + + * strict-net-declaration/no-net-strict-declaration + * strict-parameter-declaration/no-strict-parameter-declaration - The standards requires that parameters must be declared lexically - before they are used. Using -gno-strict-parameter-declaration - will allow using a parameter before declaration, with a - warning. The warning can be suppressed with -Wno-declaration-after-use. + The standards requires that nets and parameters must be declared + lexically before they are used. Using -gno-strict-declaration + will allow using a net or parameter before declaration, with a + warning. The warning can be suppressed with + -Wno-declaration-after-use. The option can be applied for nets + and parameters separately. * shared-loop-index/no-shared-loop-index diff --git a/compiler.h b/compiler.h index 0b5feca91..d72eb44c3 100644 --- a/compiler.h +++ b/compiler.h @@ -214,12 +214,19 @@ extern bool gn_strict_expr_width_flag; extern bool gn_shared_loop_index_flag; /* If this flag is true (default), then parameters must be declared before - use. `-gno-strict-parameter-declaration` allows to use parameters before + use. `-gno-strict[-parameter]-declaration` allows to use parameters before declaration, as prior to version 13. - A warning is emited with -Wanachronisms (default). + A warning is emited with -Wdeclaration-after-use (default). */ extern bool gn_strict_parameter_declaration; +/* If this flag is true (default), then nets must be declared before + use. `-gno-strict[-net]-declaration` allows to use nets before + declaration, as prior to version 13. + A warning is emited with -Wdeclaration-after-use (default). + */ +extern bool gn_strict_net_declaration; + static inline bool gn_system_verilog(void) { if (generation_flag >= GN_VER2005_SV) diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 19ac06361..040bca7b3 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -150,11 +150,16 @@ parameter assignment is evaluated as a lossless expression, as is any expression containing an unsized constant number, and unsized constant numbers are not truncated to integer width. .TP 8 +.B -gstrict-declaration\fI|\fP-gno-strict-declaration +.TP 8 +.B -gstrict-net-declaration\fI|\fP-gno-strict-net-declaration +.TP 8 .B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration -The standards requires that parameters must be declared lexically -before they are used. Using \fB\-gno\-strict\-parameter\-declaration\fP +The standards requires that nets and parameters must be declared lexically +before they are used. Using \fB\-gno\-strict\-declaration\fP will allow using a parameter before declaration, with a warning. -The warning can be suppressed with -Wno-declaration-after-use. +The warning can be suppressed with -Wno-declaration-after-use. The +option can be applied for nets and parameters separately. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables diff --git a/driver/main.c b/driver/main.c index 803e457c6..0e16bf672 100644 --- a/driver/main.c +++ b/driver/main.c @@ -134,6 +134,7 @@ const char*gen_strict_ca_eval = "no-strict-ca-eval"; const char*gen_strict_expr_width = "no-strict-expr-width"; const char*gen_shared_loop_index = "shared-loop-index"; const char*gen_verilog_ams = "no-verilog-ams"; +const char*gen_strict_net_declaration = "strict-net-declaration"; const char*gen_strict_parameter_declaration = "strict-parameter-declaration"; /* Boolean: true means use a default include dir, false means don't */ @@ -826,6 +827,20 @@ static int process_generation(const char*name) else if (strcmp(name,"no-verilog-ams") == 0) gen_verilog_ams = "no-verilog-ams"; + else if (strcmp(name,"strict-declaration") == 0) { + gen_strict_net_declaration = "strict-net-declaration"; + gen_strict_parameter_declaration = "strict-parameter-declaration"; + } + else if (strcmp(name,"no-strict-declaration") == 0) { + gen_strict_net_declaration = "no-strict-net-declaration"; + gen_strict_parameter_declaration = "no-strict-parameter-declaration"; + } + else if (strcmp(name,"strict-net-declaration") == 0) + gen_strict_net_declaration = "strict-net-declaration"; + + else if (strcmp(name,"no-strict-net-declaration") == 0) + gen_strict_net_declaration = "no-strict-net-declaration"; + else if (strcmp(name,"strict-parameter-declaration") == 0) gen_strict_parameter_declaration = "strict-parameter-declaration"; @@ -855,7 +870,8 @@ static int process_generation(const char*name) " strict-ca-eval | no-strict-ca-eval\n" " strict-expr-width | no-strict-expr-width\n" " shared-loop-index | no-shared-loop-index\n" - " strict-parameter-declaration | no-strict-parameter-declaration\n"); + " strict-declaration | no-strict-declaration\n" + " [no-]strict-[net|parameter]-declaration\n"); return 1; } @@ -1403,6 +1419,7 @@ int main(int argc, char **argv) fprintf(iconfig_file, "generation:%s\n", gen_strict_expr_width); fprintf(iconfig_file, "generation:%s\n", gen_shared_loop_index); fprintf(iconfig_file, "generation:%s\n", gen_verilog_ams); + fprintf(iconfig_file, "generation:%s\n", gen_strict_net_declaration); fprintf(iconfig_file, "generation:%s\n", gen_strict_parameter_declaration); fprintf(iconfig_file, "generation:%s\n", gen_icarus); fprintf(iconfig_file, "warnings:%s\n", warning_flags); diff --git a/main.cc b/main.cc index 8e71ef7b3..82f7bec33 100644 --- a/main.cc +++ b/main.cc @@ -118,6 +118,7 @@ bool gn_strict_expr_width_flag = false; bool gn_shared_loop_index_flag = true; bool gn_verilog_ams_flag = false; bool gn_strict_parameter_declaration = true; +bool gn_strict_net_declaration = true; /* * For some generations we allow a system function to be called @@ -394,6 +395,12 @@ static void process_generation_flag(const char*gen) } else if (strcmp(gen,"no-strict-parameter-declaration") == 0) { gn_strict_parameter_declaration = false; + } else if (strcmp(gen,"strict-net-declaration") == 0) { + gn_strict_net_declaration = true; + + } else if (strcmp(gen,"no-strict-net-declaration") == 0) { + gn_strict_net_declaration = false; + } else { } } diff --git a/symbol_search.cc b/symbol_search.cc index 11922e684..8e5d8b40a 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -164,12 +164,18 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (NetNet*net = scope->find_signal(path_tail.name)) { - if (prefix_scope || (net->lexical_pos() <= lexical_pos)) { + bool decl_after_use = !prefix_scope && !(net->lexical_pos() <= lexical_pos); + if (!gn_strict_net_declaration || !decl_after_use) { path.push_back(path_tail); res->scope = scope; res->net = net; res->type = net->net_type(); res->path_head = path; + if (warn_decl_after_use && decl_after_use) { + cerr << li->get_fileline() + << ": warning: net `" << path_tail.name + << "` used before declaration." << endl; + } return true; } else if (!res->decl_after_use) { res->decl_after_use = net; @@ -177,11 +183,17 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, } if (NetEvent*eve = scope->find_event(path_tail.name)) { - if (prefix_scope || (eve->lexical_pos() <= lexical_pos)) { + bool decl_after_use = !prefix_scope && !(eve->lexical_pos() <= lexical_pos); + if (!gn_strict_net_declaration || !decl_after_use) { path.push_back(path_tail); res->scope = scope; res->eve = eve; res->path_head = path; + if (warn_decl_after_use && decl_after_use) { + cerr << li->get_fileline() + << ": warning: event `" << path_tail.name + << "` used before declaration." << endl; + } return true; } else if (!res->decl_after_use) { res->decl_after_use = eve; From 475f098cab488fb7d9ba953344a6da51988f516a Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 17:20:27 +0000 Subject: [PATCH 06/11] Minor grammar and white space fixes in documentation. --- Documentation/usage/command_line_flags.rst | 2 +- driver/iverilog.man.in | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 73a2df9e1..76d009bb5 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -137,7 +137,7 @@ These flags affect the general behavior of the compiler. * strict-parameter-declaration/no-strict-parameter-declaration - The standards requires that nets and parameters must be declared + The standards require that nets and parameters must be declared lexically before they are used. Using -gno-strict-declaration will allow using a net or parameter before declaration, with a warning. The warning can be suppressed with diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 040bca7b3..77a71d653 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -124,7 +124,7 @@ to disable extended types if compiling code that clashes with the few new keywords used to implement the type system. .TP 8 .B -gio-range-error\fI|\fP-gno-io-range-error -The standards requires that a vectored port have matching ranges for its +The standards require that a vectored port have matching ranges for its port declaration as well as any net/register declaration. It was common practice in the past to only specify the range for the net/register declaration and some tools still allow this. By default any mismatch is @@ -159,7 +159,7 @@ The standards requires that nets and parameters must be declared lexically before they are used. Using \fB\-gno\-strict\-declaration\fP will allow using a parameter before declaration, with a warning. The warning can be suppressed with -Wno-declaration-after-use. The -option can be applied for nets and parameters separately. +option can be applied for nets and parameters separately. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables @@ -381,7 +381,7 @@ source, this will print a warning at its first use. .TP 8 .B declaration-after-use This enables warnings for declarations after use, when -those are not flagged as errors (default). +those are not flagged as errors (default). .TP 8 .B macro-redefinition\fI | \fPmacro-replacement From 29e128ed9434620b4f7d50979918667c705b0049 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 18:14:01 +0000 Subject: [PATCH 07/11] Only warn about declaration after use once for each data object. --- net_scope.cc | 10 +++++++++- netlist.h | 1 + symbol_search.cc | 14 ++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/net_scope.cc b/net_scope.cc index 1efc464e6..d90b49b82 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2026 Stephen Williams (steve@icarus.com) * Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch) * * This source code is free software; you can redistribute it @@ -462,6 +462,14 @@ unsigned NetScope::get_parameter_lexical_pos(perm_string key) const return 0; } +void NetScope::set_parameter_lexical_pos(perm_string key, unsigned lexical_pos) +{ + map::iterator idx; + + idx = parameters.find(key); + if (idx != parameters.end()) idx->second.lexical_pos = lexical_pos; +} + void NetScope::print_type(ostream&stream) const { switch (type_) { diff --git a/netlist.h b/netlist.h index 57b69959c..d1eb80764 100644 --- a/netlist.h +++ b/netlist.h @@ -1274,6 +1274,7 @@ class NetScope : public Definitions, public Attrib { LineInfo get_parameter_line_info(perm_string name) const; unsigned get_parameter_lexical_pos(perm_string name) const; + void set_parameter_lexical_pos(perm_string name, unsigned lexical_pos); /* Module instance arrays are collected here for access during the multiple elaboration passes. */ diff --git a/symbol_search.cc b/symbol_search.cc index 8e5d8b40a..91f34c22d 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2024 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2026 Stephen Williams (steve@icarus.com) * Copyright CERN 2012 / Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it @@ -175,6 +175,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: net `" << path_tail.name << "` used before declaration." << endl; + // suppress further warnings for this net + net->lexical_pos(lexical_pos); } return true; } else if (!res->decl_after_use) { @@ -193,6 +195,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: event `" << path_tail.name << "` used before declaration." << endl; + // suppress further warnings for this event + eve->lexical_pos(lexical_pos); } return true; } else if (!res->decl_after_use) { @@ -209,9 +213,11 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->par_val = par; res->path_head = path; if (warn_decl_after_use && decl_after_use) { - cerr << li->get_fileline() - << ": warning: parameter `" << path_tail.name - << "` used before declaration." << endl; + cerr << li->get_fileline() + << ": warning: parameter `" << path_tail.name + << "` used before declaration." << endl; + // suppress further warnings for this parameter + scope->set_parameter_lexical_pos(path_tail.name, lexical_pos); } return true; } else if (!res->decl_after_use) { From dc0d162fa9ad09d7942ef2f023f5fd8191178b07 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 18:26:53 +0000 Subject: [PATCH 08/11] Report declaration position when warning about declaration after use. --- symbol_search.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/symbol_search.cc b/symbol_search.cc index 91f34c22d..1c51cccb6 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -175,6 +175,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: net `" << path_tail.name << "` used before declaration." << endl; + cerr << net->get_fileline() + << ": : the net is declared here." << endl; // suppress further warnings for this net net->lexical_pos(lexical_pos); } @@ -195,6 +197,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: event `" << path_tail.name << "` used before declaration." << endl; + cerr << eve->get_fileline() + << ": : the event is declared here." << endl; // suppress further warnings for this event eve->lexical_pos(lexical_pos); } @@ -216,6 +220,8 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, cerr << li->get_fileline() << ": warning: parameter `" << path_tail.name << "` used before declaration." << endl; + cerr << par->get_fileline() + << ": : the parameter is declared here." << endl; // suppress further warnings for this parameter scope->set_parameter_lexical_pos(path_tail.name, lexical_pos); } From 4c315b32d47b48f5a6bd0f51ec51a4c495793681 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 20:03:02 +0000 Subject: [PATCH 09/11] Change strict-net-declaration to strict-net-var-declaration. Internally the compiler uses 'net' for both nets and variables, but we should make it clear to the user that this option applies to both. --- Documentation/usage/command_line_flags.rst | 13 ++++++------- compiler.h | 10 +++++----- driver/iverilog.man.in | 12 ++++++------ driver/main.c | 18 +++++++++--------- main.cc | 10 +++++----- symbol_search.cc | 8 ++++---- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 76d009bb5..38255bf34 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -133,16 +133,15 @@ These flags affect the general behavior of the compiler. * strict-declaration/no-strict-declaration - * strict-net-declaration/no-net-strict-declaration + * strict-net-var-declaration/no-strict-net-var-declaration * strict-parameter-declaration/no-strict-parameter-declaration - The standards require that nets and parameters must be declared - lexically before they are used. Using -gno-strict-declaration - will allow using a net or parameter before declaration, with a - warning. The warning can be suppressed with - -Wno-declaration-after-use. The option can be applied for nets - and parameters separately. + The standards require that nets, variables, and parameters must be + declared lexically before they are used. Using -gno-strict-declaration + will allow using a data object before declaration, with a warning. The + warning can be suppressed with -Wno-declaration-after-use. The option + can be applied for nets and variables and for parameters separately. * shared-loop-index/no-shared-loop-index diff --git a/compiler.h b/compiler.h index d72eb44c3..01893d18b 100644 --- a/compiler.h +++ b/compiler.h @@ -1,7 +1,7 @@ #ifndef IVL_compiler_H #define IVL_compiler_H /* - * Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2026 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -220,12 +220,12 @@ extern bool gn_shared_loop_index_flag; */ extern bool gn_strict_parameter_declaration; -/* If this flag is true (default), then nets must be declared before - use. `-gno-strict[-net]-declaration` allows to use nets before - declaration, as prior to version 13. +/* If this flag is true (default), then nets and variablesmust be declared + before use. `-gno-strict[-net-var]-declaration` allows to use nets and + variables before declaration, as prior to version 13. A warning is emited with -Wdeclaration-after-use (default). */ -extern bool gn_strict_net_declaration; +extern bool gn_strict_net_var_declaration; static inline bool gn_system_verilog(void) { diff --git a/driver/iverilog.man.in b/driver/iverilog.man.in index 77a71d653..21dbf72dc 100644 --- a/driver/iverilog.man.in +++ b/driver/iverilog.man.in @@ -152,14 +152,14 @@ numbers are not truncated to integer width. .TP 8 .B -gstrict-declaration\fI|\fP-gno-strict-declaration .TP 8 -.B -gstrict-net-declaration\fI|\fP-gno-strict-net-declaration +.B -gstrict-net-var-declaration\fI|\fP-gno-strict-net-var-declaration .TP 8 .B -gstrict-parameter-declaration\fI|\fP-gno-strict-parameter-declaration -The standards requires that nets and parameters must be declared lexically -before they are used. Using \fB\-gno\-strict\-declaration\fP -will allow using a parameter before declaration, with a warning. -The warning can be suppressed with -Wno-declaration-after-use. The -option can be applied for nets and parameters separately. +The standards require that nets, variables, and parameters are declared +lexically before they are used. Using \fB\-gno\-strict\-declaration\fP +will allow using a data object before declaration, with a warning. The +warning can be suppressed with -Wno-declaration-after-use. The option +can be applied for nets and variables and for parameters separately. .TP 8 .B -gshared-loop-index\fI|\fP-gno-shared-loop-index Enable (default) or disable the exclusion of for-loop control variables diff --git a/driver/main.c b/driver/main.c index 0e16bf672..a1d22b0ea 100644 --- a/driver/main.c +++ b/driver/main.c @@ -134,7 +134,7 @@ const char*gen_strict_ca_eval = "no-strict-ca-eval"; const char*gen_strict_expr_width = "no-strict-expr-width"; const char*gen_shared_loop_index = "shared-loop-index"; const char*gen_verilog_ams = "no-verilog-ams"; -const char*gen_strict_net_declaration = "strict-net-declaration"; +const char*gen_strict_net_var_declaration = "strict-net-var-declaration"; const char*gen_strict_parameter_declaration = "strict-parameter-declaration"; /* Boolean: true means use a default include dir, false means don't */ @@ -828,18 +828,18 @@ static int process_generation(const char*name) gen_verilog_ams = "no-verilog-ams"; else if (strcmp(name,"strict-declaration") == 0) { - gen_strict_net_declaration = "strict-net-declaration"; + gen_strict_net_var_declaration = "strict-net-var-declaration"; gen_strict_parameter_declaration = "strict-parameter-declaration"; } else if (strcmp(name,"no-strict-declaration") == 0) { - gen_strict_net_declaration = "no-strict-net-declaration"; + gen_strict_net_var_declaration = "no-strict-net-var-declaration"; gen_strict_parameter_declaration = "no-strict-parameter-declaration"; } - else if (strcmp(name,"strict-net-declaration") == 0) - gen_strict_net_declaration = "strict-net-declaration"; + else if (strcmp(name,"strict-net-var-declaration") == 0) + gen_strict_net_var_declaration = "strict-net-var-declaration"; - else if (strcmp(name,"no-strict-net-declaration") == 0) - gen_strict_net_declaration = "no-strict-net-declaration"; + else if (strcmp(name,"no-strict-net-var-declaration") == 0) + gen_strict_net_var_declaration = "no-strict-net-var-declaration"; else if (strcmp(name,"strict-parameter-declaration") == 0) gen_strict_parameter_declaration = "strict-parameter-declaration"; @@ -871,7 +871,7 @@ static int process_generation(const char*name) " strict-expr-width | no-strict-expr-width\n" " shared-loop-index | no-shared-loop-index\n" " strict-declaration | no-strict-declaration\n" - " [no-]strict-[net|parameter]-declaration\n"); + " [no-]strict-[net-var|parameter]-declaration\n"); return 1; } @@ -1419,7 +1419,7 @@ int main(int argc, char **argv) fprintf(iconfig_file, "generation:%s\n", gen_strict_expr_width); fprintf(iconfig_file, "generation:%s\n", gen_shared_loop_index); fprintf(iconfig_file, "generation:%s\n", gen_verilog_ams); - fprintf(iconfig_file, "generation:%s\n", gen_strict_net_declaration); + fprintf(iconfig_file, "generation:%s\n", gen_strict_net_var_declaration); fprintf(iconfig_file, "generation:%s\n", gen_strict_parameter_declaration); fprintf(iconfig_file, "generation:%s\n", gen_icarus); fprintf(iconfig_file, "warnings:%s\n", warning_flags); diff --git a/main.cc b/main.cc index 82f7bec33..a1f5ef1db 100644 --- a/main.cc +++ b/main.cc @@ -118,7 +118,7 @@ bool gn_strict_expr_width_flag = false; bool gn_shared_loop_index_flag = true; bool gn_verilog_ams_flag = false; bool gn_strict_parameter_declaration = true; -bool gn_strict_net_declaration = true; +bool gn_strict_net_var_declaration = true; /* * For some generations we allow a system function to be called @@ -395,11 +395,11 @@ static void process_generation_flag(const char*gen) } else if (strcmp(gen,"no-strict-parameter-declaration") == 0) { gn_strict_parameter_declaration = false; - } else if (strcmp(gen,"strict-net-declaration") == 0) { - gn_strict_net_declaration = true; + } else if (strcmp(gen,"strict-net-var-declaration") == 0) { + gn_strict_net_var_declaration = true; - } else if (strcmp(gen,"no-strict-net-declaration") == 0) { - gn_strict_net_declaration = false; + } else if (strcmp(gen,"no-strict-net-var-declaration") == 0) { + gn_strict_net_var_declaration = false; } else { } diff --git a/symbol_search.cc b/symbol_search.cc index 1c51cccb6..61a28d4ec 100644 --- a/symbol_search.cc +++ b/symbol_search.cc @@ -165,7 +165,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, if (NetNet*net = scope->find_signal(path_tail.name)) { bool decl_after_use = !prefix_scope && !(net->lexical_pos() <= lexical_pos); - if (!gn_strict_net_declaration || !decl_after_use) { + if (!gn_strict_net_var_declaration || !decl_after_use) { path.push_back(path_tail); res->scope = scope; res->net = net; @@ -173,10 +173,10 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, res->path_head = path; if (warn_decl_after_use && decl_after_use) { cerr << li->get_fileline() - << ": warning: net `" << path_tail.name + << ": warning: net/variable `" << path_tail.name << "` used before declaration." << endl; cerr << net->get_fileline() - << ": : the net is declared here." << endl; + << ": : the net/variable is declared here." << endl; // suppress further warnings for this net net->lexical_pos(lexical_pos); } @@ -188,7 +188,7 @@ bool symbol_search(const LineInfo*li, Design*des, NetScope*scope, if (NetEvent*eve = scope->find_event(path_tail.name)) { bool decl_after_use = !prefix_scope && !(eve->lexical_pos() <= lexical_pos); - if (!gn_strict_net_declaration || !decl_after_use) { + if (!gn_strict_net_var_declaration || !decl_after_use) { path.push_back(path_tail); res->scope = scope; res->eve = eve; From 5da8894590d1a1812058b2f198522d99e4119771 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 20:21:05 +0000 Subject: [PATCH 10/11] Fix documentation for -Wno-declaration-after-use. --- Documentation/usage/command_line_flags.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/usage/command_line_flags.rst b/Documentation/usage/command_line_flags.rst index 38255bf34..fb3f7c7bc 100644 --- a/Documentation/usage/command_line_flags.rst +++ b/Documentation/usage/command_line_flags.rst @@ -303,8 +303,12 @@ These flags affect the general behavior of the compiler. * declaration-after-use - With -gno-strict-parameter-declaration, issue a warning when a - parameter is declared after it is used. + This enables warnings for declarations after use, when those are not + flagged as errors (enabled by default). Use no-declaration-after-use + to disable this. + + This flag was added in version 14.0 or later (and is in the master branch + as of 2026-03-21). * macro-redefinition From 42d0c3fd4a5c13f3df28a50bf23e569a180c80ff Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Mar 2026 20:44:10 +0000 Subject: [PATCH 11/11] Update test suite to cover -gno-strict-declaration options. --- ivtest/gold/decl_before_use1_warn-iverilog-stderr.gold | 2 ++ ivtest/gold/decl_before_use1_warn-vvp-stdout.gold | 2 ++ ivtest/gold/decl_before_use2_warn-iverilog-stderr.gold | 2 ++ ivtest/gold/decl_before_use2_warn-vvp-stdout.gold | 2 ++ ivtest/gold/decl_before_use3_warn-iverilog-stderr.gold | 2 ++ ivtest/gold/decl_before_use3_warn-vvp-stdout.gold | 1 + ivtest/gold/decl_before_use4_warn-vvp-stdout.gold | 1 + ivtest/gold/decl_before_use5_warn-iverilog-stderr.gold | 2 ++ ivtest/gold/decl_before_use5_warn-vvp-stdout.gold | 2 ++ ivtest/gold/decl_before_use6_warn-vvp-stdout.gold | 2 ++ ivtest/gold/pr1909940.gold | 3 +++ ivtest/gold/pr1909940b.gold | 3 +++ ivtest/ivltests/decl_before_use1.v | 2 +- ivtest/ivltests/decl_before_use2.v | 2 +- ivtest/ivltests/decl_before_use3.v | 2 +- ivtest/ivltests/decl_before_use4.v | 2 +- ivtest/ivltests/decl_before_use5.v | 2 +- ivtest/regress-vlg.list | 4 ++-- ivtest/regress-vvp.list | 6 ++++++ ivtest/vvp_tests/decl_before_use1_warn.json | 7 +++++++ ivtest/vvp_tests/decl_before_use2_warn.json | 7 +++++++ ivtest/vvp_tests/decl_before_use3_warn.json | 7 +++++++ ivtest/vvp_tests/decl_before_use4_warn.json | 7 +++++++ ivtest/vvp_tests/decl_before_use5_warn.json | 7 +++++++ ivtest/vvp_tests/decl_before_use6_warn.json | 7 +++++++ 25 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 ivtest/gold/decl_before_use1_warn-iverilog-stderr.gold create mode 100644 ivtest/gold/decl_before_use1_warn-vvp-stdout.gold create mode 100644 ivtest/gold/decl_before_use2_warn-iverilog-stderr.gold create mode 100644 ivtest/gold/decl_before_use2_warn-vvp-stdout.gold create mode 100644 ivtest/gold/decl_before_use3_warn-iverilog-stderr.gold create mode 100644 ivtest/gold/decl_before_use3_warn-vvp-stdout.gold create mode 100644 ivtest/gold/decl_before_use4_warn-vvp-stdout.gold create mode 100644 ivtest/gold/decl_before_use5_warn-iverilog-stderr.gold create mode 100644 ivtest/gold/decl_before_use5_warn-vvp-stdout.gold create mode 100644 ivtest/gold/decl_before_use6_warn-vvp-stdout.gold create mode 100644 ivtest/gold/pr1909940.gold create mode 100644 ivtest/gold/pr1909940b.gold create mode 100644 ivtest/vvp_tests/decl_before_use1_warn.json create mode 100644 ivtest/vvp_tests/decl_before_use2_warn.json create mode 100644 ivtest/vvp_tests/decl_before_use3_warn.json create mode 100644 ivtest/vvp_tests/decl_before_use4_warn.json create mode 100644 ivtest/vvp_tests/decl_before_use5_warn.json create mode 100644 ivtest/vvp_tests/decl_before_use6_warn.json diff --git a/ivtest/gold/decl_before_use1_warn-iverilog-stderr.gold b/ivtest/gold/decl_before_use1_warn-iverilog-stderr.gold new file mode 100644 index 000000000..5cc4b93e4 --- /dev/null +++ b/ivtest/gold/decl_before_use1_warn-iverilog-stderr.gold @@ -0,0 +1,2 @@ +ivltests/decl_before_use1.v:4: warning: net/variable `v` used before declaration. +ivltests/decl_before_use1.v:9: : the net/variable is declared here. diff --git a/ivtest/gold/decl_before_use1_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use1_warn-vvp-stdout.gold new file mode 100644 index 000000000..1eccf69bf --- /dev/null +++ b/ivtest/gold/decl_before_use1_warn-vvp-stdout.gold @@ -0,0 +1,2 @@ +1 +used before declaration diff --git a/ivtest/gold/decl_before_use2_warn-iverilog-stderr.gold b/ivtest/gold/decl_before_use2_warn-iverilog-stderr.gold new file mode 100644 index 000000000..f1ef2cc14 --- /dev/null +++ b/ivtest/gold/decl_before_use2_warn-iverilog-stderr.gold @@ -0,0 +1,2 @@ +ivltests/decl_before_use2.v:3: warning: net/variable `w` used before declaration. +ivltests/decl_before_use2.v:10: : the net/variable is declared here. diff --git a/ivtest/gold/decl_before_use2_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use2_warn-vvp-stdout.gold new file mode 100644 index 000000000..6ad2d0448 --- /dev/null +++ b/ivtest/gold/decl_before_use2_warn-vvp-stdout.gold @@ -0,0 +1,2 @@ +00000001 +used before declaration diff --git a/ivtest/gold/decl_before_use3_warn-iverilog-stderr.gold b/ivtest/gold/decl_before_use3_warn-iverilog-stderr.gold new file mode 100644 index 000000000..113671293 --- /dev/null +++ b/ivtest/gold/decl_before_use3_warn-iverilog-stderr.gold @@ -0,0 +1,2 @@ +ivltests/decl_before_use3.v:4: warning: event `e` used before declaration. +ivltests/decl_before_use3.v:8: : the event is declared here. diff --git a/ivtest/gold/decl_before_use3_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use3_warn-vvp-stdout.gold new file mode 100644 index 000000000..983403b7d --- /dev/null +++ b/ivtest/gold/decl_before_use3_warn-vvp-stdout.gold @@ -0,0 +1 @@ +used before declaration diff --git a/ivtest/gold/decl_before_use4_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use4_warn-vvp-stdout.gold new file mode 100644 index 000000000..983403b7d --- /dev/null +++ b/ivtest/gold/decl_before_use4_warn-vvp-stdout.gold @@ -0,0 +1 @@ +used before declaration diff --git a/ivtest/gold/decl_before_use5_warn-iverilog-stderr.gold b/ivtest/gold/decl_before_use5_warn-iverilog-stderr.gold new file mode 100644 index 000000000..8bf2623ff --- /dev/null +++ b/ivtest/gold/decl_before_use5_warn-iverilog-stderr.gold @@ -0,0 +1,2 @@ +ivltests/decl_before_use5.v:4: warning: parameter `w` used before declaration. +ivltests/decl_before_use5.v:8: : the parameter is declared here. diff --git a/ivtest/gold/decl_before_use5_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use5_warn-vvp-stdout.gold new file mode 100644 index 000000000..6519eec97 --- /dev/null +++ b/ivtest/gold/decl_before_use5_warn-vvp-stdout.gold @@ -0,0 +1,2 @@ +10101010 +used before declaration diff --git a/ivtest/gold/decl_before_use6_warn-vvp-stdout.gold b/ivtest/gold/decl_before_use6_warn-vvp-stdout.gold new file mode 100644 index 000000000..0664d0861 --- /dev/null +++ b/ivtest/gold/decl_before_use6_warn-vvp-stdout.gold @@ -0,0 +1,2 @@ +10 +FAILED diff --git a/ivtest/gold/pr1909940.gold b/ivtest/gold/pr1909940.gold new file mode 100644 index 000000000..4da14bfe4 --- /dev/null +++ b/ivtest/gold/pr1909940.gold @@ -0,0 +1,3 @@ +./ivltests/pr1909940.v:4: warning: net/variable `in` used before declaration. +./ivltests/pr1909940.v:5: : the net/variable is declared here. +PASSED diff --git a/ivtest/gold/pr1909940b.gold b/ivtest/gold/pr1909940b.gold new file mode 100644 index 000000000..7d10aac17 --- /dev/null +++ b/ivtest/gold/pr1909940b.gold @@ -0,0 +1,3 @@ +./ivltests/pr1909940b.v:4: warning: net/variable `in` used before declaration. +./ivltests/pr1909940b.v:5: : the net/variable is declared here. +PASSED diff --git a/ivtest/ivltests/decl_before_use1.v b/ivtest/ivltests/decl_before_use1.v index 8f338b72a..8fae1af7f 100644 --- a/ivtest/ivltests/decl_before_use1.v +++ b/ivtest/ivltests/decl_before_use1.v @@ -3,7 +3,7 @@ module test(); initial begin v = 1; $display("%b", v); - $display("FAILED"); + $display("used before declaration"); end reg v; diff --git a/ivtest/ivltests/decl_before_use2.v b/ivtest/ivltests/decl_before_use2.v index 3eeb619c3..d40c97a1a 100644 --- a/ivtest/ivltests/decl_before_use2.v +++ b/ivtest/ivltests/decl_before_use2.v @@ -4,7 +4,7 @@ assign w = 1; initial begin $display("%b", w); - $display("FAILED"); + $display("used before declaration"); end wire [7:0] w; diff --git a/ivtest/ivltests/decl_before_use3.v b/ivtest/ivltests/decl_before_use3.v index 8fed35387..57f925957 100644 --- a/ivtest/ivltests/decl_before_use3.v +++ b/ivtest/ivltests/decl_before_use3.v @@ -2,7 +2,7 @@ module test(); initial begin ->e; - $display("FAILED"); + $display("used before declaration"); end event e; diff --git a/ivtest/ivltests/decl_before_use4.v b/ivtest/ivltests/decl_before_use4.v index 8daa94218..41e69deb9 100644 --- a/ivtest/ivltests/decl_before_use4.v +++ b/ivtest/ivltests/decl_before_use4.v @@ -2,7 +2,7 @@ module test(); initial begin @(e); - $display("FAILED"); + $display("used before declaration"); end event e; diff --git a/ivtest/ivltests/decl_before_use5.v b/ivtest/ivltests/decl_before_use5.v index cb92f23a0..d7931b0f7 100644 --- a/ivtest/ivltests/decl_before_use5.v +++ b/ivtest/ivltests/decl_before_use5.v @@ -2,7 +2,7 @@ module test(); initial begin $display("%b", w); - $display("FAILED"); + $display("used before declaration"); end localparam w = 8'hAA; diff --git a/ivtest/regress-vlg.list b/ivtest/regress-vlg.list index 6a0323cb8..9309d3afa 100644 --- a/ivtest/regress-vlg.list +++ b/ivtest/regress-vlg.list @@ -1126,8 +1126,8 @@ pr1903324 normal ivltests pr1903343 normal ivltests gold=pr1903343.gold pr1903520 normal ivltests pr1907192 normal ivltests -pr1909940 CE ivltests -pr1909940b CE ivltests +pr1909940 normal,-gno-strict-declaration ivltests gold=pr1909940.gold +pr1909940b normal,-gno-strict-declaration ivltests gold=pr1909940b.gold pr1912843 normal ivltests pr1913918a normal ivltests pr1913918b normal ivltests diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index 49a0917df..13a548189 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -97,6 +97,12 @@ decl_before_use3 vvp_tests/decl_before_use3.json decl_before_use4 vvp_tests/decl_before_use4.json decl_before_use5 vvp_tests/decl_before_use5.json decl_before_use6 vvp_tests/decl_before_use6.json +decl_before_use1_warn vvp_tests/decl_before_use1_warn.json +decl_before_use2_warn vvp_tests/decl_before_use2_warn.json +decl_before_use3_warn vvp_tests/decl_before_use3_warn.json +decl_before_use4_warn vvp_tests/decl_before_use4_warn.json +decl_before_use5_warn vvp_tests/decl_before_use5_warn.json +decl_before_use6_warn vvp_tests/decl_before_use6_warn.json delayed_sfunc vvp_tests/delayed_sfunc.json dffsynth vvp_tests/dffsynth.json dffsynth-S vvp_tests/dffsynth-S.json diff --git a/ivtest/vvp_tests/decl_before_use1_warn.json b/ivtest/vvp_tests/decl_before_use1_warn.json new file mode 100644 index 000000000..cf5df77cb --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use1_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use1.v", + "iverilog-args" : [ "-gno-strict-net-var-declaration" ], + "gold" : "decl_before_use1_warn" +} diff --git a/ivtest/vvp_tests/decl_before_use2_warn.json b/ivtest/vvp_tests/decl_before_use2_warn.json new file mode 100644 index 000000000..1fdf6c86d --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use2_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use2.v", + "iverilog-args" : [ "-gno-strict-declaration" ], + "gold" : "decl_before_use2_warn" +} diff --git a/ivtest/vvp_tests/decl_before_use3_warn.json b/ivtest/vvp_tests/decl_before_use3_warn.json new file mode 100644 index 000000000..f2507fe6b --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use3_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use3.v", + "iverilog-args" : [ "-gno-strict-net-var-declaration" ], + "gold" : "decl_before_use3_warn" +} diff --git a/ivtest/vvp_tests/decl_before_use4_warn.json b/ivtest/vvp_tests/decl_before_use4_warn.json new file mode 100644 index 000000000..26af6b94d --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use4_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use4.v", + "iverilog-args" : [ "-gno-strict-declaration", "-Wno-declaration-after-use" ], + "gold" : "decl_before_use4_warn" +} diff --git a/ivtest/vvp_tests/decl_before_use5_warn.json b/ivtest/vvp_tests/decl_before_use5_warn.json new file mode 100644 index 000000000..4568e78bd --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use5_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use5.v", + "iverilog-args" : [ "-gno-strict-parameter-declaration" ], + "gold" : "decl_before_use5_warn" +} diff --git a/ivtest/vvp_tests/decl_before_use6_warn.json b/ivtest/vvp_tests/decl_before_use6_warn.json new file mode 100644 index 000000000..5324bb9a3 --- /dev/null +++ b/ivtest/vvp_tests/decl_before_use6_warn.json @@ -0,0 +1,7 @@ + +{ + "type" : "normal", + "source" : "decl_before_use6.v", + "iverilog-args" : [ "-gno-strict-declaration", "-Wno-declaration-after-use" ], + "gold" : "decl_before_use6_warn" +}