From 1f2b40cff181da2e8cd040c46138ddec08aa8f64 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 25 Oct 2011 18:41:04 -0400 Subject: [PATCH] Fix 3.823 constructor core dump on Debian, bug401. --- Changes | 2 ++ src/V3Error.cpp | 37 +++++++++++++++++-------------------- src/V3Error.h | 45 ++++++++++++++++++++++++++++----------------- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Changes b/Changes index 04dfe924f..c72526136 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Fix "always @ (* )", bug403, bug404. [Walter Lavino] +**** Fix 3.823 constructor core dump on Debian, bug401. [Ahmed El-Mahmoudy] + * Verilator 3.823 2011/10/20 diff --git a/src/V3Error.cpp b/src/V3Error.cpp index fd43b21a1..1b5fa2f30 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -34,11 +34,6 @@ //====================================================================== // Statics -map FileLine::s_namemap; -deque FileLine::s_names; -// s_defaultFileLine must be after s_name* initializer and in same .cpp file -FileLine FileLine::s_defaultFileLine = FileLine(EmptySecret()); - int V3Error::s_errCount = 0; int V3Error::s_warnCount = 0; int V3Error::s_debugDefault = 0; @@ -69,13 +64,28 @@ V3ErrorCode::V3ErrorCode(const char* msgp) { m_e = V3ErrorCode::EC_ERROR; } +//###################################################################### +// FileLineSingleton class functions + +int FileLineSingleton::nameToNumber(const string& filename) { + // Convert filenames to a filenameno + // This lets us assign a nice small identifier for debug messages, but more + // importantly lets us use a 4 byte int instead of 8 byte pointer in every FileLine. + map::const_iterator iter = m_namemap.find(filename); + if (VL_LIKELY(iter != m_namemap.end())) return iter->second; + int num = m_names.size(); + m_names.push_back(filename); + m_namemap.insert(make_pair(filename,num)); + return num; +} + //###################################################################### // FileLine class functions FileLine::FileLine(FileLine::EmptySecret) { // Sort of a singleton m_lineno=0; - m_filenameno=nameToNumber("AstRoot"); + m_filenameno=singleton().nameToNumber("AstRoot"); m_warnOn=0; for (int codei=V3ErrorCode::EC_MIN; codei::const_iterator iter = s_namemap.find(filename); - if (VL_LIKELY(iter != s_namemap.end())) return iter->second; - int num = s_names.size(); - s_names.push_back(filename); - s_namemap.insert(make_pair(filename,num)); - return num; -} - const string FileLine::filenameLetters() const { const int size = 1 + (64 / 4); // Each letter retires more than 4 bits of a > 64 bit number char out[size]; @@ -291,8 +289,7 @@ void FileLine::deleteAllRemaining() { // Eventually the list will be empty and terminate the loop. } fileLineLeakChecks.clear(); - s_names.clear(); - s_namemap.clear(); + FileLineSingleton::clear(); #endif } diff --git a/src/V3Error.h b/src/V3Error.h index f9e2afae8..f1164df81 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -252,8 +252,17 @@ inline uint32_t cvtToHash(void* vp) { class FileLine; class FileLineSingleton { + map m_namemap; // filenameno for each filename + deque m_names; // filename text for each filenameno + // COSNTRUCTORS + FileLineSingleton() { } + ~FileLineSingleton() { } protected: friend class FileLine; + // METHODS + int nameToNumber(const string& filename); + string numberToName(int filenameno) { return m_names[filenameno]; } + void clear() { m_namemap.clear(); m_names.clear(); } }; class FileLine { @@ -263,31 +272,33 @@ class FileLine { bitset m_warnOn; // Consider moving opt.language() into here, so can know language per-node - static map s_namemap; // filenameno for each filename - static deque s_names; // filename text for each filenameno - static FileLine s_defaultFileLine; - - static int nameToNumber(const string& filename); - static string numberToName(int filenameno) { return s_names[filenameno]; } - +private: struct EmptySecret {}; - + inline static FileLineSingleton& singleton() { + static FileLineSingleton s; + return s; + } + inline static FileLine& defaultFileLine() { + static FileLine* defFilelinep = new FileLine(FileLine::EmptySecret()); + return *defFilelinep; + } protected: // User routines should never need to change line numbers // We are storing pointers, so we CAN'T change them after initial reading. + friend class FileLineSingleton; friend class V3ParseImp; friend class V3PreLex; friend class V3PreProcImp; void lineno(int num) { m_lineno = num; } - void filename(const string& name) { m_filenameno = nameToNumber(name); } + void filename(const string& name) { m_filenameno = singleton().nameToNumber(name); } void lineDirective(const char* textp, int& enterExitRef); void linenoInc() { m_lineno++; } void linenoIncInPlace() { m_lineno++; } FileLine* copyOrSameFileLine(); public: FileLine (const string& filename, int lineno) { - m_lineno=lineno; m_filenameno = nameToNumber(filename); - m_warnOn=s_defaultFileLine.m_warnOn; } + m_lineno=lineno; m_filenameno = singleton().nameToNumber(filename); + m_warnOn=defaultFileLine().m_warnOn; } FileLine (FileLine* fromp) { m_lineno=fromp->m_lineno; m_filenameno = fromp->m_filenameno; m_warnOn=fromp->m_warnOn; } FileLine (EmptySecret); @@ -302,7 +313,7 @@ public: int lineno () const { return m_lineno; } string ascii() const; - const string filename () const { return numberToName(m_filenameno); } + const string filename () const { return singleton().numberToName(m_filenameno); } const string filenameLetters() const; const string filebasename () const; const string filebasenameNoExt () const; @@ -315,7 +326,7 @@ public: void warnLintOff(bool flag); void warnStyleOff(bool flag); void warnStateFrom(const FileLine& from) { m_warnOn=from.m_warnOn; } - void warnResetDefault() { warnStateFrom(s_defaultFileLine); } + void warnResetDefault() { warnStateFrom(defaultFileLine()); } // Specific flag ACCESSORS/METHODS bool coverageOn() const { return m_warnOn.test(V3ErrorCode::I_COVERAGE); } @@ -325,13 +336,13 @@ public: // METHODS - Global static void globalWarnLintOff(bool flag) { - s_defaultFileLine.warnLintOff(flag); } + defaultFileLine().warnLintOff(flag); } static void globalWarnStyleOff(bool flag) { - s_defaultFileLine.warnStyleOff(flag); } + defaultFileLine().warnStyleOff(flag); } static void globalWarnOff(V3ErrorCode code, bool flag) { - s_defaultFileLine.warnOff(code, flag); } + defaultFileLine().warnOff(code, flag); } static bool globalWarnOff(const string& code, bool flag) { - return s_defaultFileLine.warnOff(code, flag); } + return defaultFileLine().warnOff(code, flag); } // METHODS - Called from netlist // Merge warning disables from another fileline