Fix lint_off on Errors (#5351) (#5363)

This commit is contained in:
Ethan Sifferman 2024-08-11 12:04:46 -07:00 committed by GitHub
parent eb3f10399a
commit 1b15509a9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 128 additions and 21 deletions

View File

@ -336,6 +336,7 @@ public:
}
}
bool waive(V3ErrorCode code, const string& match) {
if (code.hardError()) return false;
for (const auto& itr : m_waivers) {
if ((code.isUnder(itr.first) || (itr.first == V3ErrorCode::I_LINT))
&& VString::wildmatch(match, itr.second)) {

View File

@ -53,25 +53,11 @@ V3ErrorCode::V3ErrorCode(const char* msgp) {
//
bool V3ErrorGuarded::isError(V3ErrorCode code, bool supp) VL_REQUIRES(m_mutex) {
if (supp) {
return false;
} else if (code == V3ErrorCode::USERINFO) {
return false;
} else if (code == V3ErrorCode::EC_INFO) {
return false;
} else if (code == V3ErrorCode::EC_FATAL) {
return true;
} else if (code == V3ErrorCode::EC_FATALEXIT) {
return true;
} else if (code == V3ErrorCode::EC_FATALSRC) {
return true;
} else if (code == V3ErrorCode::EC_ERROR) {
return true;
} else if (code < V3ErrorCode::EC_FIRST_WARN || pretendError(code)) {
return true;
} else {
return false;
}
if (code.hardError()) return true;
if (supp) return false;
if (code == V3ErrorCode::USERINFO || code == V3ErrorCode::EC_INFO) return false;
if (pretendError(code)) return true;
return false;
}
string V3ErrorGuarded::msgPrefix() VL_REQUIRES(m_mutex) {
@ -180,7 +166,7 @@ void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra)
}
if (!m_describedEachWarn[m_errorCode] && !m_pretendError[m_errorCode]) {
m_describedEachWarn[m_errorCode] = true;
if (m_errorCode >= V3ErrorCode::EC_FIRST_WARN && !m_describedWarnings) {
if (!m_errorCode.hardError() && !m_describedWarnings) {
m_describedWarnings = true;
std::cerr << warnMore() << "... Use \"/* verilator lint_off "
<< m_errorCode.ascii()

View File

@ -226,6 +226,10 @@ public:
}
// Warnings that warn about nasty side effects
bool dangerous() const VL_MT_SAFE { return (m_e == COMBDLY); }
// Insuppressible error codes that should always stop elaboration
bool hardError() const VL_MT_SAFE {
return (m_e != EC_INFO && m_e < V3ErrorCode::EC_FIRST_WARN);
}
// Warnings we'll present to the user as errors
// Later -Werror- options may make more of these.
bool pretendError() const VL_MT_SAFE {

View File

@ -371,7 +371,7 @@ bool FileLine::warnOff(const string& msg, bool flag) {
return true;
}
const V3ErrorCode code{cmsg};
if (code < V3ErrorCode::EC_FIRST_WARN) {
if (code.hardError()) {
return false;
} else {
warnOff(code, flag);

View File

@ -0,0 +1,23 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Ethan Sifferman.
// SPDX-License-Identifier: CC0-1.0
module DECLFILENAME;
logic UNUSEDSIGNAL;
logic [0:1] ASCRANGE_UNDRIVEN;
always_comb begin
case (ASCRANGE_UNDRIVEN)
2'b0x: UNUSEDSIGNAL = 1;
endcase
end
`ifdef T_VLT_MATCH_ERROR_1
import hi::*;
`elsif T_VLT_MATCH_ERROR_2
initial $readmemh("", EC_ERROR);
`elsif T_VLT_MATCH_ERROR_3
initial #1;
`endif
endmodule

View File

@ -0,0 +1,9 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2024 by Ethan Sifferman.
// SPDX-License-Identifier: CC0-1.0
`verilator_config
lint_off -file "*/t_vlt_match_error.v" -match "*"

View File

@ -0,0 +1,8 @@
%Error-PKGNODECL: t/t_vlt_match_error.v:17:12: Package/class 'hi' not found, and needs to be predeclared (IEEE 1800-2023 26.3)
17 | import hi::*;
| ^~
... For error description see https://verilator.org/warn/PKGNODECL?v=latest
%Error: t/t_vlt_match_error.v:17:12: Importing from missing package 'hi'
17 | import hi::*;
| ^~
%Error: Exiting due to

View File

@ -0,0 +1,22 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 by Wilson Snyder and Ethan Sifferman. 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(vlt => 1);
top_filename("t/t_vlt_match_error.v");
lint(
verilator_flags2 => ["-DT_VLT_MATCH_ERROR_1 --lint-only -Wall t/t_vlt_match_error.v t/t_vlt_match_error.vlt"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,4 @@
%Error: t/t_vlt_match_error.v:19:27: Can't find definition of variable: 'EC_ERROR'
19 | initial $readmemh("", EC_ERROR);
| ^~~~~~~~
%Error: Exiting due to

View File

@ -0,0 +1,22 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 by Wilson Snyder and Ethan Sifferman. 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(vlt => 1);
top_filename("t/t_vlt_match_error.v");
lint(
verilator_flags2 => ["-DT_VLT_MATCH_ERROR_2 --lint-only -Wall t/t_vlt_match_error.v t/t_vlt_match_error.vlt"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,6 @@
%Error-NEEDTIMINGOPT: t/t_vlt_match_error.v:21:13: Use --timing or --no-timing to specify how delays should be handled
: ... note: In instance 'DECLFILENAME'
21 | initial #1;
| ^
... For error description see https://verilator.org/warn/NEEDTIMINGOPT?v=latest
%Error: Exiting due to

View File

@ -0,0 +1,22 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 by Wilson Snyder and Ethan Sifferman. 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(vlt => 1);
top_filename("t/t_vlt_match_error.v");
lint(
verilator_flags2 => ["-DT_VLT_MATCH_ERROR_3 --lint-only -Wall t/t_vlt_match_error.v t/t_vlt_match_error.vlt"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;