diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 522941a52..13bb845d0 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -134,6 +134,7 @@ Oleh Maksymenko Patrick Stewart Paul Wright Pawel Sagan +Pengcheng Xu Peter Debacker Peter Horvath Peter Monsson diff --git a/docs/guide/warnings.rst b/docs/guide/warnings.rst index 12e854f35..a09a6203e 100644 --- a/docs/guide/warnings.rst +++ b/docs/guide/warnings.rst @@ -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 diff --git a/src/V3Error.h b/src/V3Error.h index 51de65960..0643ff8bf 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -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 diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 93ce607c1..bbc9542f7 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -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 } diff --git a/test_regress/t/t_math_repl_bad.out b/test_regress/t/t_math_repl_bad.out index d39d2f109..380f0ff1b 100644 --- a/test_regress/t/t_math_repl_bad.out +++ b/test_regress/t/t_math_repl_bad.out @@ -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'