diff --git a/src/V3Undriven.cpp b/src/V3Undriven.cpp index bf0ab47b1..0efd0d7fe 100644 --- a/src/V3Undriven.cpp +++ b/src/V3Undriven.cpp @@ -75,15 +75,19 @@ public: private: // METHODS inline bool bitNumOk(int bit) const { return (bit*FLAGS_PER_BIT < (int)m_flags.size()); } - inline bool usedFlag(int bit) { return m_flags[bit*FLAGS_PER_BIT + FLAG_USED]; } - inline bool drivenFlag(int bit) { return m_flags[bit*FLAGS_PER_BIT + FLAG_DRIVEN]; } - string bitNames(int index) { + inline bool usedFlag(int bit) { return m_usedWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_USED]; } + inline bool drivenFlag(int bit) { return m_drivenWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_DRIVEN]; } + enum BitNamesWhich { BN_UNUSED, BN_UNDRIVEN, BN_BOTH }; + string bitNames(BitNamesWhich which) { string bits=""; bool prev = false; int msb = 0; // bit==-1 loops below; we do one extra iteration so end with prev=false for (int bit=(m_flags.size()/FLAGS_PER_BIT)-1; bit >= -1; --bit) { - if (bit>=0 && !m_flags[bit*FLAGS_PER_BIT + index]) { + if (bit>=0 + && ((which == BN_UNUSED && !usedFlag(bit) && drivenFlag(bit)) + || (which == BN_UNDRIVEN && usedFlag(bit) && !drivenFlag(bit)) + || (which == BN_BOTH && !usedFlag(bit) && !drivenFlag(bit)))) { if (!prev) { prev=true; msb = bit; } } else if (prev) { AstBasicDType* bdtypep = m_varp->basicp(); @@ -136,33 +140,46 @@ public: bool allD=true; bool anyU=m_usedWhole; bool anyD=m_drivenWhole; + bool anyUnotD=false; + bool anyDnotU=false; + bool anynotDU=false; for (unsigned bit=0; bitv3warn(UNDRIVEN, "Signal is not driven, nor used: "<prettyName()); - } - else { - if (!m_usedWhole && !anyU) { - nodep->v3warn(UNUSED, "Signal is not used: "<prettyName()); - } else if (!m_usedWhole) { - nodep->v3warn(UNUSED, "Bits of signal are not used: "<prettyName() - <v3warn(UNUSED, "Signal is not driven, nor used: "<prettyName()); + } else if (allD && !anyU) { + nodep->v3warn(UNUSED, "Signal is not used: "<prettyName()); + } else if (!anyD && allU) { + nodep->v3warn(UNDRIVEN, "Signal is not driven: "<prettyName()); + } else { + // Bits have different dispositions + if (anynotDU) { + nodep->v3warn(UNUSED, "Bits of signal are not driven, nor used: "<prettyName() + <v3warn(UNDRIVEN, "Signal is not driven: "<prettyName()); - } else if (!m_drivenWhole) { + if (anyDnotU) { + nodep->v3warn(UNUSED, "Bits of signal are not used: "<prettyName() + <v3warn(UNDRIVEN, "Bits of signal are not driven: "<prettyName() - <{v3}; diff --git a/test_regress/t/t_lint_unused_bad.v b/test_regress/t/t_lint_unused_bad.v index 4802adabf..d1021f8e3 100644 --- a/test_regress/t/t_lint_unused_bad.v +++ b/test_regress/t/t_lint_unused_bad.v @@ -34,10 +34,15 @@ module sub; wire unu3; // Totally unused + wire [3:0] mixed; // [3] unused & undr, [2] unused, [1] undr, [0] ok + assign mixed[2] = 0; + assign mixed[0] = 0; + localparam THREE = 3; initial begin if (0 && assunu1[0] != 0 && udrb2 != 0) begin end if (0 && assunub2[THREE] && assunub2[1:0]!=0) begin end + if (0 && mixed[1:0] != 0) begin end end endmodule