From ac2313ecb780213aaa23ceae048909bf25551126 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 11 May 2025 22:36:40 -0400 Subject: [PATCH] Fix some errors exceeding the --error-limit --- src/V3Error.cpp | 19 ++++++++++++++++++- src/V3Error.h | 14 ++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/V3Error.cpp b/src/V3Error.cpp index 87f355915..1587c8b79 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -131,14 +131,31 @@ void V3ErrorGuarded::v3errorPrep(V3ErrorCode code) VL_REQUIRES(m_mutex) { m_errorSuppressed = false; } -// cppcheck-has-bug-suppress constParameter void V3ErrorGuarded::v3errorEnd(std::ostringstream& sstr, const string& extra) + VL_REQUIRES(m_mutex) { + static bool s_firedTooMany = false; + v3errorEndGuts(sstr, extra); + if (errorLimit() && errorCount() >= errorLimit() && !s_firedTooMany) { + s_firedTooMany = true; + // Recurses here + v3errorEnd((v3errorPrep(V3ErrorCode::EC_FATALMANY), + (v3errorStr() << "Exiting due to too many errors encountered; --error-limit=" + << errorCount() << std::endl), + v3errorStr())); + assert(0); // LCOV_EXCL_LINE + VL_UNREACHABLE; + } +} + +// cppcheck-has-bug-suppress constParameter +void V3ErrorGuarded::v3errorEndGuts(std::ostringstream& sstr, const string& extra) VL_REQUIRES(m_mutex) { // 'extra' is appended to the message, and is is excluded in check for // duplicate messages. Currently used for reporting instance name. #if defined(__COVERITY__) || defined(__cppcheck__) if (m_errorCode == V3ErrorCode::EC_FATAL) __coverity_panic__(x); #endif + // Skip suppressed messages if (m_errorSuppressed // On debug, show only non default-off warning to prevent pages of warnings diff --git a/src/V3Error.h b/src/V3Error.h index 5989b6ffc..445c302f5 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -344,6 +344,7 @@ private: void v3errorPrep(V3ErrorCode code) VL_REQUIRES(m_mutex); std::ostringstream& v3errorStr() VL_REQUIRES(m_mutex) { return m_errorStr; } void v3errorEnd(std::ostringstream& sstr, const string& extra = "") VL_REQUIRES(m_mutex); + void v3errorEndGuts(std::ostringstream& sstr, const string& extra) VL_REQUIRES(m_mutex); public: V3RecursiveMutex m_mutex; // Make sure only single thread is in class @@ -359,18 +360,7 @@ public: void vlAbortOrExit() VL_REQUIRES(m_mutex); void errorContexted(bool flag) VL_REQUIRES(m_mutex) { m_errorContexted = flag; } void incWarnings() VL_REQUIRES(m_mutex) { ++m_warnCount; } - void incErrors() VL_REQUIRES(m_mutex) { - ++m_errCount; - if (errorCount() == errorLimit()) { // Not >= as would otherwise recurse - v3errorEnd( - (v3errorPrep(V3ErrorCode::EC_FATALMANY), - (v3errorStr() << "Exiting due to too many errors encountered; --error-limit=" - << errorCount() << std::endl), - v3errorStr())); - assert(0); // LCOV_EXCL_LINE - VL_UNREACHABLE; - } - } + void incErrors() VL_REQUIRES(m_mutex) { ++m_errCount; } int errorCount() VL_REQUIRES(m_mutex) { return m_errCount; } bool pretendError(int errorCode) VL_REQUIRES(m_mutex) { return m_pretendError[errorCode]; } void pretendError(V3ErrorCode code, bool flag) VL_REQUIRES(m_mutex) {