diff --git a/src/lib/netlist/analog/nld_bjt.cpp b/src/lib/netlist/analog/nld_bjt.cpp index 3d954504264..666165d81f6 100644 --- a/src/lib/netlist/analog/nld_bjt.cpp +++ b/src/lib/netlist/analog/nld_bjt.cpp @@ -134,7 +134,7 @@ namespace analog BJT_PNP }; - NETLIB_CONSTRUCTOR_EX(QBJT, pstring model = "NPN") + NETLIB_CONSTRUCTOR_EX(QBJT, const pstring &model = "NPN") , m_model(*this, "MODEL", model) , m_qtype(BJT_NPN) { diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 1dc639008c4..a6743968b6e 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -360,7 +360,7 @@ namespace analog NETLIB_OBJECT_DERIVED(D, twoterm) { public: - NETLIB_CONSTRUCTOR_DERIVED_EX(D, twoterm, pstring model = "D") + NETLIB_CONSTRUCTOR_DERIVED_EX(D, twoterm, const pstring &model = "D") , m_model(*this, "MODEL", model) , m_D(*this, "m_D") { diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index 4df755e5396..e97affcd398 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -28,6 +28,9 @@ TIDY_FLAGSX += -modernize-use-trailing-return-type space := space += TIDY_FLAGS = $(subst $(space),,$(TIDY_FLAGSX)) +TIDY_SOURCES = $(SOURCES) + +#TIDY_SOURCES = $(SRC)/plib/pparser.cpp #TIDY_FLAGS = -checks=llvm-include-order,llvm-namespace-comment,modernize-use-override,modernize-use-using -fix #TIDY_FLAGS = -checks=llvm-include-order -fix @@ -45,8 +48,8 @@ endif # LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr -CFLAGS = $(LTO) -g -O3 -std=c++11 -I$(CURDIR)/.. -I$(CURDIR)/../.. $(CEXTRAFLAGS) -LDFLAGS = $(LTO) -g -O3 -std=c++11 $(LDEXTRAFLAGS) +CFLAGS = $(LTO) -g -O3 -std=c++14 -I$(CURDIR)/.. -I$(CURDIR)/../.. $(CEXTRAFLAGS) +LDFLAGS = $(LTO) -g -O3 -std=c++14 $(LDEXTRAFLAGS) LIBS = -lpthread -ldl CC = g++ @@ -54,7 +57,7 @@ LD = @g++ MD = @mkdir RM = @rm DOXYGEN = @doxygen -CLANG_TIDY = clang-tidy-9 +CLANG_TIDY = clang-tidy-10 TARGETS = nltool nlwav @@ -295,7 +298,7 @@ endif #------------------------------------------------- tidy: tidy_db @echo running tidy - @for i in $(SOURCES); do \ + @for i in $(TIDY_SOURCES); do \ $(CLANG_TIDY) $$i $(TIDY_FLAGS) -header-filter=.*; \ done diff --git a/src/lib/netlist/nl_base.cpp b/src/lib/netlist/nl_base.cpp index 851c7b8059f..8f1de5d22c6 100644 --- a/src/lib/netlist/nl_base.cpp +++ b/src/lib/netlist/nl_base.cpp @@ -167,13 +167,11 @@ detail::terminal_type detail::core_terminal_t::type() const { if (dynamic_cast(this) != nullptr) return terminal_type::TERMINAL; - else if (dynamic_cast(this) != nullptr) + else if (dynamic_cast(this) != nullptr + || dynamic_cast(this) != nullptr) return terminal_type::INPUT; - else if (dynamic_cast(this) != nullptr) - return terminal_type::OUTPUT; - else if (dynamic_cast(this) != nullptr) - return terminal_type::INPUT; - else if (dynamic_cast(this) != nullptr) + else if (dynamic_cast(this) != nullptr + || dynamic_cast(this) != nullptr) return terminal_type::OUTPUT; else { @@ -472,7 +470,7 @@ void netlist_t::print_stats() const } log().verbose("Total calls : {1:12} {2:12} {3:12}", total_count, - total_time, total_time / static_cast(total_count)); + total_time, total_time / static_cast(total_count ? total_count : 1)); log().verbose("Total loop {1:15}", m_stat_mainloop()); log().verbose("Total time {1:15}", total_time); diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index eb796bf7834..65d68a568e9 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -1474,7 +1474,7 @@ namespace netlist // netlist_t // ----------------------------------------------------------------------------- - class netlist_t + class netlist_t // NOLINT(clang-analyzer-optin.performance.Padding) { public: @@ -1496,9 +1496,9 @@ namespace netlist void qpush(detail::queue_t::entry_t && e) noexcept { if (!USE_QUEUE_STATS || !m_stats) - m_queue.push_nostats(std::move(e)); + m_queue.push_nostats(std::move(e)); // NOLINT(performance-move-const-arg) else - m_queue.push(std::move(e)); + m_queue.push(std::move(e)); // NOLINT(performance-move-const-arg) } template diff --git a/src/lib/netlist/nl_parser.cpp b/src/lib/netlist/nl_parser.cpp index dfae907fe96..a2cc7b31b93 100644 --- a/src/lib/netlist/nl_parser.cpp +++ b/src/lib/netlist/nl_parser.cpp @@ -144,6 +144,8 @@ void parser_t::parse_netlist(const pstring &nlname) void parser_t::net_truthtable_start(const pstring &nlname) { pstring name = get_identifier(); + bool head_found(false); + require_token(m_tok_comma); long ni = get_number_long(); require_token(m_tok_comma); @@ -169,9 +171,12 @@ void parser_t::net_truthtable_start(const pstring &nlname) require_token(m_tok_param_left); desc.desc.push_back(get_string()); require_token(m_tok_param_right); + head_found = true; } else if (token.is(m_tok_TT_LINE)) { + if (!head_found) + m_setup.log().error("TT_LINE found without TT_HEAD"); require_token(m_tok_param_left); desc.desc.push_back(get_string()); require_token(m_tok_param_right); diff --git a/src/lib/netlist/nl_setup.cpp b/src/lib/netlist/nl_setup.cpp index 3ffafe994e0..f04eeaa13a0 100644 --- a/src/lib/netlist/nl_setup.cpp +++ b/src/lib/netlist/nl_setup.cpp @@ -943,7 +943,7 @@ nl_double models_t::value(const pstring &model, const pstring &entity) switch (*p) { case 'M': factor = 1e6; break; - case 'k': factor = 1e3; break; + case 'k': case 'K': factor = 1e3; break; case 'm': factor = 1e-3; break; case 'u': factor = 1e-6; break; diff --git a/src/lib/netlist/plib/mat_cr.h b/src/lib/netlist/plib/mat_cr.h index db791752cf1..71268e43765 100644 --- a/src/lib/netlist/plib/mat_cr.h +++ b/src/lib/netlist/plib/mat_cr.h @@ -191,7 +191,7 @@ namespace plib const std::size_t piie = row_idx[i+1]; const auto &nz = nzbd[i]; - while (auto j = nz[nzbdp++]) + while (auto j = nz[nzbdp++]) // NOLINT(bugprone-infinite-loop) { // proceed to column i diff --git a/src/lib/netlist/plib/pparser.cpp b/src/lib/netlist/plib/pparser.cpp index 2ab2925b57f..d257de3d3a8 100644 --- a/src/lib/netlist/plib/pparser.cpp +++ b/src/lib/netlist/plib/pparser.cpp @@ -159,10 +159,12 @@ ptokenizer::token_t ptokenizer::get_token() { skipeol(); } +#if 0 else if (ret.str() == "#") { skipeol(); } +#endif else { return ret; @@ -293,6 +295,8 @@ void ppreprocessor::error(const pstring &err) #define CHECKTOK2(p_op, p_prio) \ else if (tok == # p_op) \ { \ + if (!has_val) \ + { error("parsing error!"); return 1;} \ if (prio < (p_prio)) \ return val; \ start++; \ @@ -304,7 +308,9 @@ void ppreprocessor::error(const pstring &err) int ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, int prio) { - int val = 0; + int val(0); + bool has_val(false); + pstring tok=sexpr[start]; if (tok == "(") { @@ -312,6 +318,7 @@ int ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, i val = expr(sexpr, start, /*prio*/ 255); if (sexpr[start] != ")") error("parsing error!"); + has_val = true; start++; } while (start < sexpr.size()) @@ -319,18 +326,32 @@ int ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, i tok=sexpr[start]; if (tok == ")") { - // FIXME: catch error - return val; + if (!has_val) + { + error("parsing error!"); + return 1; // tease compiler + } + else + return val; } else if (tok == "!") { if (prio < 3) - return val; + { + if (!has_val) + { + error("parsing error!"); + return 1; // tease compiler + } + else + return val; + } start++; val = !expr(sexpr, start, 3); + has_val = true; } CHECKTOK2(*, 5) - CHECKTOK2(/, 5) + CHECKTOK2(/, 5) // NOLINT(clang-analyzer-core.DivideZero) CHECKTOK2(+, 6) CHECKTOK2(-, 6) CHECKTOK2(==, 10) @@ -338,12 +359,18 @@ int ppreprocessor::expr(const std::vector &sexpr, std::size_t &start, i CHECKTOK2(||, 15) else { - // FIXME: error handling val = plib::pstonum(tok); + has_val = true; start++; } } - return val; + if (!has_val) + { + error("parsing error!"); + return 1; // tease compiler + } + else + return val; } ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name) diff --git a/src/lib/netlist/plib/pparser.h b/src/lib/netlist/plib/pparser.h index 8a9c12d69df..0f0e57fca12 100644 --- a/src/lib/netlist/plib/pparser.h +++ b/src/lib/netlist/plib/pparser.h @@ -220,6 +220,7 @@ protected: readbuffer(readbuffer &&rhs) noexcept : m_strm(rhs.m_strm), m_buf() {} COPYASSIGN(readbuffer, delete) readbuffer &operator=(readbuffer &&src) = delete; + ~readbuffer() override = default; int_type underflow() override { diff --git a/src/lib/netlist/plib/ppmf.h b/src/lib/netlist/plib/ppmf.h index 4cc301f6d7f..6ce65d4e960 100644 --- a/src/lib/netlist/plib/ppmf.h +++ b/src/lib/netlist/plib/ppmf.h @@ -69,10 +69,11 @@ namespace plib { using generic_function = void (*)(); template - mfp(MemberFunctionType mftp) // XXNOLINT(cppcoreguidelines-pro-type-member-init) + mfp(MemberFunctionType mftp) : m_function(0), m_this_delta(0), m_dummy1(0), m_dummy2(0), m_size(sizeof(mfp)) { - *reinterpret_cast(this) = mftp; + *reinterpret_cast(this) = mftp; // NOLINT + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) } template diff --git a/src/lib/netlist/plib/pstream.h b/src/lib/netlist/plib/pstream.h index b403f441045..68592b70b7d 100644 --- a/src/lib/netlist/plib/pstream.h +++ b/src/lib/netlist/plib/pstream.h @@ -256,7 +256,7 @@ struct perrlogger template explicit perrlogger(Args&& ... args) { - h()(std::forward(args)...); + h()(std::forward(args)...); // NOLINT(cppcoreguidelines-pro-bounds-array-to-pointer-decay) } private: static putf8_fmt_writer &h() diff --git a/src/lib/netlist/plib/pstring.h b/src/lib/netlist/plib/pstring.h index 96ab0bd0fa5..1307bc13e3c 100644 --- a/src/lib/netlist/plib/pstring.h +++ b/src/lib/netlist/plib/pstring.h @@ -107,7 +107,7 @@ public: template::value>::type> - pstring_t(C (&string)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) + pstring_t(C (*string)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays, modernize-avoid-c-arrays) { static_assert(N > 0,"pstring from array of length 0"); if (string[N-1] != 0) @@ -248,9 +248,7 @@ struct putf8_traits static std::size_t codelen(const mem_t *p) { const auto p1 = reinterpret_cast(p); - if ((*p1 & 0x80) == 0x00) - return 1; - else if ((*p1 & 0xE0) == 0xC0) + if ((*p1 & 0xE0) == 0xC0) return 2; else if ((*p1 & 0xF0) == 0xE0) return 3; @@ -258,7 +256,9 @@ struct putf8_traits return 4; else { - return 1; // not correct + // valid utf8: ((*p1 & 0x80) == 0x00) + // However, we return 1 here. + return 1; } } static std::size_t codelen(const code_t c) @@ -284,7 +284,7 @@ struct putf8_traits else if ((*p1 & 0xF8) == 0xF0) return static_cast(((p1[0] & 0x0f) << 18) | ((p1[1] & 0x3f) << 12) | ((p1[2] & 0x3f) << 6) | ((p1[3] & 0x3f) << 0)); else - return *p1; // not correct + return 0xFFFD; // unicode-replacement character } static void encode(const code_t c, string_type &s) { diff --git a/src/lib/netlist/plib/putil.h b/src/lib/netlist/plib/putil.h index f8cc634df66..cea0bace671 100644 --- a/src/lib/netlist/plib/putil.h +++ b/src/lib/netlist/plib/putil.h @@ -188,7 +188,7 @@ namespace plib }; template - T pstonum(const S &arg, std::locale loc = std::locale::classic()) + T pstonum(const S &arg, const std::locale &loc = std::locale::classic()) { decltype(arg.c_str()) cstr = arg.c_str(); std::size_t idx(0); diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index e227802c1a2..eb3cfcca44e 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -147,7 +147,7 @@ namespace devices pstring ml = ""; for (std::size_t j = 0; j < iN; j++) { - ml += fill[k][j] == 0 ? "X" : fill[k][j] < decltype(mat)::FILL_INFINITY ? "+" : "."; + ml += fill[k][j] == 0 ? 'X' : fill[k][j] < decltype(mat)::FILL_INFINITY ? '+' : '.'; if (fill[k][j] < decltype(mat)::FILL_INFINITY) if (fill[k][j] > fm) fm = fill[k][j]; diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index 5b59effecf8..a850d28a6f3 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -90,14 +90,16 @@ namespace devices float_ext_type &lAinv(const T1 &r, const T2 &c) { return m_lAinv[r][c]; } private: + template + using array2D = std::array, N>; static constexpr std::size_t m_pitch = ((( storage_N) + 7) / 8) * 8; - float_ext_type m_A[storage_N][m_pitch]; - float_ext_type m_Ainv[storage_N][m_pitch]; - float_ext_type m_W[storage_N][m_pitch]; + array2D m_A; + array2D m_Ainv; + array2D m_W; std::array m_RHS; // right hand side - contains currents - float_ext_type m_lA[storage_N][m_pitch]; - float_ext_type m_lAinv[storage_N][m_pitch]; + array2D m_lA; + array2D m_lAinv; //float_ext_type m_RHSx[storage_N]; diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index a01fc239938..fea8f2c2a34 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -97,18 +97,20 @@ protected: private: + template + using array2D = std::array, N>; static constexpr std::size_t m_pitch = ((( storage_N) + 7) / 8) * 8; - float_ext_type m_A[storage_N][m_pitch]; - float_ext_type m_Ainv[storage_N][m_pitch]; - float_ext_type m_W[storage_N][m_pitch]; + array2D m_A; + array2D m_Ainv; + array2D m_W; std::array m_RHS; // right hand side - contains currents - float_ext_type m_lA[storage_N][m_pitch]; + array2D m_lA; /* temporary */ - float_type H[storage_N][m_pitch] ; + array2D H; std::array rows; - unsigned cols[storage_N][m_pitch]; + array2D cols; std::array colcount; unsigned m_cnt;