Change zero replication width error to ZEROREPL warning (#4753) (#4762)

This commit is contained in:
Pengcheng Xu 2024-01-03 13:11:50 +01:00 committed by GitHub
parent 8ea814e4b4
commit ec01008fe3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 6 deletions

View File

@ -134,6 +134,7 @@ Oleh Maksymenko
Patrick Stewart
Paul Wright
Pawel Sagan
Pengcheng Xu
Peter Debacker
Peter Horvath
Peter Monsson

View File

@ -2131,3 +2131,46 @@ List Of Warnings
Inactive region. Such processes do get resumed in the same time slot
somewhere in the Active region. Issued only if Verilator is run with the
:vlopt:`--timing` option.
.. option:: ZEROREPL
Warns that zero is used as the replication value in the replication
operator. This is specified as an error by IEEE 1800-2017 11.4.12.1.
Faulty example:
.. code-block:: sv
:linenos:
:emphasize-lines: 5
module dut
#(parameter int MY_PARAM = 0);
reg [7:0] data;
always @* begin
data = {MY_PARAM{1'b1}}; //<--- WARNING
end
endmodule
Results in the following error:
.. code-block::
%Error-ZEROREPL: test.v:5:22: Replication value of 0 is only legal under a concatenation (IEEE 1800-2017 11.4.12.1)
Note that in some cases, this warning may be false, when a condition
upstream or downstream of the access means the zero replication will
never execute or be used.
Repaired example:
.. code-block:: sv
:linenos:
:emphasize-lines: 2
module dut
#(parameter int MY_PARAM = 1); //<--- REPAIRED
reg [7:0] data;
always @* begin
data = {MY_PARAM{1'b1}};
end
endmodule

View File

@ -165,6 +165,7 @@ public:
WIDTHTRUNC, // Width mismatch- lhs < rhs
WIDTHXZEXPAND, // Width mismatch- lhs > rhs xz filled
ZERODLY, // #0 delay
ZEROREPL, // Replication width of zero
_ENUM_MAX
// ***Add new elements below also***
};
@ -210,7 +211,7 @@ public:
"UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNOPTTHREADS",
"UNPACKED", "UNSIGNED", "UNUSEDGENVAR", "UNUSEDPARAM", "UNUSEDSIGNAL",
"USERERROR", "USERFATAL", "USERINFO", "USERWARN",
"VARHIDDEN", "WAITCONST", "WIDTH", "WIDTHCONCAT", "WIDTHEXPAND", "WIDTHTRUNC", "WIDTHXZEXPAND", "ZERODLY",
"VARHIDDEN", "WAITCONST", "WIDTH", "WIDTHCONCAT", "WIDTHEXPAND", "WIDTHTRUNC", "WIDTHXZEXPAND", "ZERODLY", "ZEROREPL",
" MAX"
};
// clang-format on
@ -228,7 +229,7 @@ public:
return (m_e == ASSIGNIN || m_e == BADSTDPRAGMA || m_e == BLKANDNBLK || m_e == BLKLOOPINIT
|| m_e == CONTASSREG || m_e == ENCAPSULATED || m_e == ENDLABEL || m_e == ENUMVALUE
|| m_e == IMPURE || m_e == PINNOTFOUND || m_e == PKGNODECL
|| m_e == PROCASSWIRE // Says IEEE
|| m_e == PROCASSWIRE || m_e == ZEROREPL // Says IEEE
);
}
// Warnings to mention manual

View File

@ -781,7 +781,7 @@ class WidthVisitor final : public VNVisitor {
if (!constp) nodep->v3error("Replication value isn't a constant.");
if (times == 0
&& !VN_IS(nodep->backp(), Concat)) { // Concat Visitor will clean it up.
nodep->v3error("Replication value of 0 is only legal under a concatenation"
nodep->v3warn(ZEROREPL, "Replication value of 0 is only legal under a concatenation"
" (IEEE 1800-2017 11.4.12.1)");
times = 1; // Set to 1, so we can continue looking for errors
}

View File

@ -1,12 +1,12 @@
%Error: t/t_math_repl_bad.v:12:14: Replication value of 0 is only legal under a concatenation (IEEE 1800-2017 11.4.12.1)
: ... note: In instance 't'
%Error-ZEROREPL: t/t_math_repl_bad.v:12:14: Replication value of 0 is only legal under a concatenation (IEEE 1800-2017 11.4.12.1)
: ... note: In instance 't'
12 | o = {0 {1'b1}};
| ^
... For error description see https://verilator.org/warn/ZEROREPL?v=latest
%Warning-WIDTHEXPAND: t/t_math_repl_bad.v:12:9: Operator ASSIGN expects 32 bits on the Assign RHS, but Assign RHS's REPLICATE generates 1 bits.
: ... note: In instance 't'
12 | o = {0 {1'b1}};
| ^
... For warning description see https://verilator.org/warn/WIDTHEXPAND?v=latest
... Use "/* verilator lint_off WIDTHEXPAND */" and lint_on around source to disable this message.
%Error: t/t_math_repl_bad.v:13:43: Replication value isn't a constant.
: ... note: In instance 't'