Add IGNOREDRETURN warning.

This commit is contained in:
Wilson Snyder 2019-03-10 14:57:01 -04:00
parent b1831d7e33
commit 539a773ea7
12 changed files with 141 additions and 7 deletions

View File

@ -8,6 +8,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
*** Support $fread. [Leendert van Doorn]
*** Add IGNOREDRETURN warning.
**** Report PORTSHORT errors on concat constants, bug 1400. [Will Korteland]
**** Fix VERILATOR_GDB being ignored, msg2860. [Yu Sheng Lin]

View File

@ -3580,6 +3580,14 @@ code to a case statement, or a SystemVerilog 'unique if' or 'priority if'.
Disabled by default as this is a code style warning; it will simulate
correctly.
=item IGNOREDRETURN
Warns that a non-void function is being called as a task, and hence the
return value is being ignored. This warning is required by IEEE.
Ignoring this warning will only suppress the lint check, it will simulate
correctly.
=item IMPERFECTSCH
Warns that the scheduling of the model is not absolutely perfect, and some

View File

@ -78,7 +78,8 @@ public:
ENDLABEL, // End lable name mismatch
GENCLK, // Generated Clock
IFDEPTH, // If statements too deep
IMPERFECTSCH, // Imperfect schedule (disabled by default)
IGNOREDRETURN, // Ignoring return value (funcation as task)
IMPERFECTSCH, // Imperfect schedule (disabled by default)
IMPLICIT, // Implicit wire
IMPORTSTAR, // Import::* in $unit
IMPURE, // Impure function not being inlined
@ -139,7 +140,8 @@ public:
"CMPCONST", "COLONPLUS", "COMBDLY", "CONTASSREG",
"DEFPARAM", "DECLFILENAME",
"ENDLABEL", "GENCLK",
"IFDEPTH", "IMPERFECTSCH", "IMPLICIT", "IMPORTSTAR", "IMPURE",
"IFDEPTH", "IGNOREDRETURN",
"IMPERFECTSCH", "IMPLICIT", "IMPORTSTAR", "IMPURE",
"INCABSPATH", "INFINITELOOP", "INITIALDLY",
"LITENDIAN", "MODDUP",
"MULTIDRIVEN",

View File

@ -1170,11 +1170,15 @@ private:
nodep->replaceWith(outrefp);
// Insert new statements
visitp = insertBeforeStmt(nodep, beginp);
} else {
// outvscp maybe non-NULL if calling a function in a taskref,
// but if so we want to simply ignore the function result
nodep->replaceWith(beginp);
}
} else {
if (nodep->taskp()->isFunction()) {
nodep->v3warn(IGNOREDRETURN,
"Ignoring return value of non-void function (IEEE 2017 13.4.1)");
}
// outvscp maybe non-NULL if calling a function in a taskref,
// but if so we want to simply ignore the function result
nodep->replaceWith(beginp);
}
// Cleanup
nodep->deleteTree(); VL_DANGLING(nodep);
UINFO(4," FTask REF Done.\n");

View File

@ -46,7 +46,9 @@ module t (/*AUTOARG*/);
// Test loop
initial begin
// bug963
// verilator lint_off IGNOREDRETURN
dpii_clear();
// verilator lint_on IGNOREDRETURN
j = 0;
for (i=0; i<64; i++) begin
if (i[0])

View File

@ -50,12 +50,15 @@ module t;
if (n !== 10) $stop;
// Functions called as tasks
// verilator lint_off IGNOREDRETURN
rglobal = 32'h4;
if (inc_and_return(32'h2) != 32'h6) $stop;
if (rglobal !== 32'h6) $stop;
rglobal = 32'h6;
inc_and_return(32'h3);
if (rglobal !== 32'h9) $stop;
// verilator lint_on IGNOREDRETURN
$write("*-* All Finished *-*\n");
$finish;

View File

@ -6,6 +6,7 @@
module t (/*AUTOARG*/);
initial begin
// verilator lint_off IGNOREDRETURN
func(0, 1'b1);
end

20
test_regress/t/t_func_void.pl Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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.
scenarios(simulator => 1);
compile(
);
execute(
check_finished => 1,
);
ok(1);
1;

View File

@ -0,0 +1,36 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
module t (clk);
input clk;
int side_effect;
function int f1;
input int in;
f1 = in + 1;
side_effect += in + 1;
endfunction
initial begin
int got;
side_effect = 1;
//
got = f1(10);
if (got != 11) $stop;
if (side_effect != 12) $stop;
// verilator lint_off IGNOREDRETURN
f1(20);
// verilator lint_on IGNOREDRETURN
if (side_effect != 33) $stop;
//
// void'f1(30);
// if (side_effect != 64) $stop;
//
$write("*-* All Finished *-*\n");
$finish;
end
endmodule

View File

@ -0,0 +1,3 @@
%Warning-IGNOREDRETURN: t/t_func_void_bad.v:25: Ignoring return value of non-void function (IEEE 2017 13.4.1)
%Warning-IGNOREDRETURN: Use "/* verilator lint_off IGNOREDRETURN */" and lint_on around source to disable this message.
%Error: Exiting due to

View File

@ -0,0 +1,18 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 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.
scenarios(simulator => 1);
compile(
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,35 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
module t (clk);
input clk;
int side_effect;
function int f1;
input int in;
f1 = in + 1;
side_effect += in + 1;
endfunction
initial begin
int got;
side_effect = 1;
//
got = f1(10);
if (got != 11) $stop;
if (side_effect != 12) $stop;
//
f1(20);
if (side_effect != 33) $stop;
//
// void'f1(30);
// if (side_effect != 64) $stop;
//
$write("*-* All Finished *-*\n");
$finish;
end
endmodule