Change metacomment extra underscore error to warning (#6968)

Used to throw a hard v3error on stray underscores in metacomments.
Issue a BADVLTPRAGMA that can be turned off instead.
This commit is contained in:
Geza Lore 2026-01-31 15:16:20 +00:00 committed by GitHub
parent b9ef4a6c48
commit f472c2da6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 65 additions and 14 deletions

View File

@ -481,17 +481,21 @@ void V3PreProcImp::comment(const string& text) {
if ((cp[0] == 'v' || cp[0] == 'V') && VString::startsWith(cp + 1, "erilator")) {
cp += std::strlen("verilator");
if (*cp == '_') {
fileline()->v3error("Extra underscore in meta-comment;"
" use /*verilator {...}*/ not /*verilator_{...}*/");
V3Control::applyIgnores(fileline());
fileline()->v3warn(BADVLTPRAGMA, "Extra underscore in meta-comment, ignoring comment;"
" use /*verilator {...}*/ not /*verilator_{...}*/");
return;
}
vlcomment = true;
} else if (VString::startsWith(cp, "synopsys")) {
cp += std::strlen("synopsys");
synth = true;
if (*cp == '_') {
fileline()->v3error("Extra underscore in meta-comment;"
" use /*synopsys {...}*/ not /*synopsys_{...}*/");
V3Control::applyIgnores(fileline());
fileline()->v3warn(BADVLTPRAGMA, "Extra underscore in meta-comment, ignoring comment;"
" use /*synopsys {...}*/ not /*synopsys_{...}*/");
return;
}
synth = true;
} else if (VString::startsWith(cp, "cadence")) {
cp += std::strlen("cadence");
synth = true;
@ -505,8 +509,6 @@ void V3PreProcImp::comment(const string& text) {
return;
}
if (!vlcomment && !synth) return; // Short-circuit
while (std::isspace(*cp)) ++cp;
string cmd = commentCleanup(string{cp});
// cmd now is comment without extra spaces and "verilator" prefix

View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# 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-FileCopyrightText: 2026 Wilson Snyder
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('vlt')
test.top_filename = "t/t_pp_underline_bad.v"
test.lint(verilator_flags2=["-Wno-BADVLTPRAGMA"])
test.passes()

View File

@ -1,12 +1,8 @@
%Error: t/t_pp_underline_bad.v:8:4: Extra underscore in meta-comment; use /*verilator {...}*/ not /*verilator_{...}*/
%Error-BADVLTPRAGMA: t/t_pp_underline_bad.v:8:4: Extra underscore in meta-comment, ignoring comment; use /*verilator {...}*/ not /*verilator_{...}*/
8 | // verilator_no_inline_module
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... See the manual at https://verilator.org/verilator_doc.html?v=latest for more assistance.
%Error: t/t_pp_underline_bad.v:10:19: Extra underscore in meta-comment; use /*synopsys {...}*/ not /*synopsys_{...}*/
... For error description see https://verilator.org/warn/BADVLTPRAGMA?v=latest
%Error-BADVLTPRAGMA: t/t_pp_underline_bad.v:10:19: Extra underscore in meta-comment, ignoring comment; use /*synopsys {...}*/ not /*synopsys_{...}*/
10 | case (1'b1) // synopsys_full_case
| ^~~~~~~~~~~~~~~~~~~~~
%Error-BADVLTPRAGMA: t/t_pp_underline_bad.v:8:4: Unknown verilator comment: '/*verilator _no_inline_module*/'
8 | /*verilator _no_inline_module*/
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... For error description see https://verilator.org/warn/BADVLTPRAGMA?v=latest
%Error: Exiting due to

View File

@ -9,6 +9,7 @@ module t;
initial begin
case (1'b1) // synopsys_full_case
1'b0: $stop;
1'b1: $finish;
endcase
$stop; // Should have failed
end

View File

@ -0,0 +1,5 @@
%Error-BADVLTPRAGMA: t/t_pp_underline_bad.v:8:4: Extra underscore in meta-comment, ignoring comment; use /*verilator {...}*/ not /*verilator_{...}*/
8 | // verilator_no_inline_module
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... For error description see https://verilator.org/warn/BADVLTPRAGMA?v=latest
%Error: Exiting due to

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# 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-FileCopyrightText: 2026 Wilson Snyder
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
test.scenarios('vlt')
test.top_filename = "t/t_pp_underline_bad.v"
test.lint(verilator_flags2=["t/t_pp_underline_bad_vlt.vlt"],
fails=True,
expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,9 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain.
// SPDX-FileCopyrightText: 2026 Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
`verilator_config
lint_off -rule BADVLTPRAGMA -file "t/t_pp_underline_bad.v" -lines 10