Cppcheck errors fixed and suppressed (#319)

* supress knownConditionTrueFalse

* cppcheck suppress redundantInitialization

* cppcheck solve stlcstrStream

* cppcheck suppress useStlAlgorithm

* cppcheck-suppress derefInvalidIteratorRedundantCheck

* cppcheck solvwe constParameterReference

* const parameter reference cppcheck

* removed wrong fix

* cppcheck-suppress memsetClassFloat

* cppcheck fix memsetClassFloat

* cppcheck fix unsignedLessThanZero

* supressing all errors on simde gitmodule

* fix typo (unsignedLessThanZero)

* fix cppcheck suppress simde gitmodule

* cppcheck-suppress unsignedLessThanZero

---------

Co-authored-by: gtsoul-tech <gtsoulkanakis@gmail.com>
This commit is contained in:
gtsoul-tech 2024-11-12 10:01:11 +02:00 committed by GitHub
parent 5145b6d2ab
commit 9a3268b047
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 33 additions and 24 deletions

View File

@ -3,6 +3,7 @@ knownConditionTrueFalse:*Parser.rl
knownConditionTrueFalse:*Parser.cpp knownConditionTrueFalse:*Parser.cpp
variableScope:*Parser.rl variableScope:*Parser.rl
unreadVariable:*control_verbs.cpp unreadVariable:*control_verbs.cpp
*:*simde/*
assertWithSideEffect assertWithSideEffect
syntaxError syntaxError
internalError internalError

View File

@ -431,6 +431,7 @@ accel_dfa_build_strat::buildAccel(UNUSED dstate_id_t this_idx,
DEBUG_PRINTF("accelerations scheme has offset s%u/d%u\n", info.offset, DEBUG_PRINTF("accelerations scheme has offset s%u/d%u\n", info.offset,
info.double_offset); info.double_offset);
// cppcheck-suppress redundantInitialization
accel->generic.offset = verify_u8(info.offset); accel->generic.offset = verify_u8(info.offset);
if (double_byte_ok(info) && info.double_cr.none() && if (double_byte_ok(info) && info.double_cr.none() &&

View File

@ -331,6 +331,7 @@ void buildReachMapping(const build_info &args, vector<NFAStateSet> &reach,
vector<NFAVertex> verts; vector<NFAVertex> verts;
verts.reserve(args.num_states); verts.reserve(args.num_states);
auto sidat = [&state_ids=state_ids](const NFAVertex &v) { auto sidat = [&state_ids=state_ids](const NFAVertex &v) {
// cppcheck-suppress knownConditionTrueFalse
return (state_ids.at(v) != NO_STATE); return (state_ids.at(v) != NO_STATE);
}; };
const auto &vr = vertices_range(h); const auto &vr = vertices_range(h);
@ -921,11 +922,13 @@ void buildAccel(const build_info &args, NFAStateSet &accelMask,
// Start with the NONE case. // Start with the NONE case.
auxvec.emplace_back(AccelAux()); auxvec.emplace_back(AccelAux());
// cppcheck-suppress memsetClassFloat
memset(&auxvec[0], 0, sizeof(AccelAux)); memset(&auxvec[0], 0, sizeof(AccelAux));
auxvec[0].accel_type = ACCEL_NONE; // no states on. auxvec[0].accel_type = ACCEL_NONE; // no states on.
AccelAux aux; AccelAux aux;
for (u32 i = 1; i < accelCount; i++) { for (u32 i = 1; i < accelCount; i++) {
// cppcheck-suppress memsetClassFloat
memset(&aux, 0, sizeof(aux)); memset(&aux, 0, sizeof(aux));
NFAStateSet effective_states(args.num_states); NFAStateSet effective_states(args.num_states);
@ -1218,10 +1221,11 @@ bool hasSquashableInitDs(const build_info &args) {
static static
bool hasInitDsStates(const NGHolder &h, bool hasInitDsStates(const NGHolder &h,
const unordered_map<NFAVertex, u32> &state_ids) { const unordered_map<NFAVertex, u32> &state_ids) {
// cppcheck-suppress knownConditionTrueFalse
if (state_ids.at(h.startDs) != NO_STATE) { if (state_ids.at(h.startDs) != NO_STATE) {
return true; return true;
} }
// cppcheck-suppress knownConditionTrueFalse
if (is_triggered(h) && state_ids.at(h.start) != NO_STATE) { if (is_triggered(h) && state_ids.at(h.start) != NO_STATE) {
return true; return true;
} }
@ -1696,7 +1700,7 @@ static
bool cannotDie(const build_info &args) { bool cannotDie(const build_info &args) {
const auto &h = args.h; const auto &h = args.h;
const auto &state_ids = args.state_ids; const auto &state_ids = args.state_ids;
// cppcheck-suppress knownConditionTrueFalse
// If we have a startDs we're actually using, we can't die. // If we have a startDs we're actually using, we can't die.
if (state_ids.at(h.startDs) != NO_STATE) { if (state_ids.at(h.startDs) != NO_STATE) {
DEBUG_PRINTF("is using startDs\n"); DEBUG_PRINTF("is using startDs\n");

View File

@ -512,6 +512,7 @@ set<NFAVertex> findZombies(const NGHolder &h,
} }
for (const auto &v : inv_adjacent_vertices_range(h.accept, h)) { for (const auto &v : inv_adjacent_vertices_range(h.accept, h)) {
// cppcheck-suppress knownConditionTrueFalse
if (state_ids.at(v) != NO_STATE) { if (state_ids.at(v) != NO_STATE) {
zombies.insert(v); zombies.insert(v);
} }

View File

@ -262,6 +262,7 @@ static
bool hasSuffixLiterals(const set<ue2_literal> &s) { bool hasSuffixLiterals(const set<ue2_literal> &s) {
for (auto it = s.begin(), ite = s.end(); it != ite; ++it) { for (auto it = s.begin(), ite = s.end(); it != ite; ++it) {
for (auto jt = std::next(it); jt != ite; ++jt) { for (auto jt = std::next(it); jt != ite; ++jt) {
// cppcheck-suppress useStlAlgorithm
if (isSuffix(*it, *jt) || isSuffix(*jt, *it)) { if (isSuffix(*it, *jt) || isSuffix(*jt, *it)) {
DEBUG_PRINTF("'%s' and '%s' have suffix issues\n", DEBUG_PRINTF("'%s' and '%s' have suffix issues\n",
dumpString(*it).c_str(), dumpString(*it).c_str(),
@ -530,7 +531,7 @@ void findMinCut(LitGraph &lg, vector<LitEdge> &cutset) {
vector<s32> distances(num_verts); vector<s32> distances(num_verts);
vector<LitEdge> predecessors(num_verts); vector<LitEdge> predecessors(num_verts);
vector<u64a> residuals(num_edges(lg)); vector<u64a> residuals(num_edges(lg));
//cppcheck-suppress unreadVariable
UNUSED u64a flow = boykov_kolmogorov_max_flow(lg, UNUSED u64a flow = boykov_kolmogorov_max_flow(lg,
get(&LitGraphEdgeProps::score, lg), get(&LitGraphEdgeProps::score, lg),
make_iterator_property_map(residuals.begin(), e_index_map), make_iterator_property_map(residuals.begin(), e_index_map),

View File

@ -2018,8 +2018,7 @@ void buildCountingMiracles(build_context &bc) {
continue; continue;
} }
RoseCountingMiracle rcm; RoseCountingMiracle rcm = {}; // Initialize rcm to zero
memset(&rcm, 0, sizeof(rcm));
if (cr.count() == 1) { if (cr.count() == 1) {
rcm.c = cr.find_first(); rcm.c = cr.find_first();
@ -3299,7 +3298,7 @@ void addEodAnchorProgram(const RoseBuildImpl &build, const build_context &bc,
} }
static static
void addEodEventProgram(const RoseBuildImpl &build, build_context &bc, void addEodEventProgram(const RoseBuildImpl &build,const build_context &bc,
ProgramBuild &prog_build, RoseProgram &program) { ProgramBuild &prog_build, RoseProgram &program) {
if (build.eod_event_literal_id == MO_INVALID_IDX) { if (build.eod_event_literal_id == MO_INVALID_IDX) {
return; return;
@ -3336,7 +3335,7 @@ void addEodEventProgram(const RoseBuildImpl &build, build_context &bc,
} }
static static
RoseProgram makeEodProgram(const RoseBuildImpl &build, build_context &bc, RoseProgram makeEodProgram(const RoseBuildImpl &build,const build_context &bc,
ProgramBuild &prog_build, u32 eodNfaIterOffset) { ProgramBuild &prog_build, u32 eodNfaIterOffset) {
RoseProgram program; RoseProgram program;

View File

@ -2223,6 +2223,7 @@ void mergeCluster(RoseGraph &g, const ReportManager &rm,
for (it2 = it; for (it2 = it;
it2 != vcluster.end() && cluster.size() < MERGE_GROUP_SIZE_MAX; it2 != vcluster.end() && cluster.size() < MERGE_GROUP_SIZE_MAX;
++it2) { ++it2) {
// cppcheck-suppress derefInvalidIteratorRedundantCheck
RoseVertex v = *it2; RoseVertex v = *it2;
NGHolder *h = g[v].suffix.graph.get(); NGHolder *h = g[v].suffix.graph.get();
assert(!g[v].suffix.haig); /* should not be here if haig */ assert(!g[v].suffix.haig); /* should not be here if haig */

View File

@ -127,6 +127,7 @@ static really_really_inline
m128 lshift64_m128(m128 a, unsigned b) { m128 lshift64_m128(m128 a, unsigned b) {
#if defined(HAVE__BUILTIN_CONSTANT_P) #if defined(HAVE__BUILTIN_CONSTANT_P)
if (__builtin_constant_p(b)) { if (__builtin_constant_p(b)) {
// cppcheck-suppress unsignedLessThanZero
return _mm_slli_epi64(a, b); return _mm_slli_epi64(a, b);
} }
#endif #endif

View File

@ -339,7 +339,7 @@ really_inline SuperVector<16> SuperVector<16>::vshl_16 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_slli_epi16(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_slli_epi16(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -354,7 +354,7 @@ really_inline SuperVector<16> SuperVector<16>::vshl_32 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_slli_epi32(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_slli_epi32(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -369,7 +369,7 @@ really_inline SuperVector<16> SuperVector<16>::vshl_64 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_slli_epi64(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_slli_epi64(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -384,7 +384,7 @@ really_inline SuperVector<16> SuperVector<16>::vshl_128(uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_slli_si128(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_slli_si128(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -414,7 +414,7 @@ really_inline SuperVector<16> SuperVector<16>::vshr_16 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_srli_epi16(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_srli_epi16(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -429,7 +429,7 @@ really_inline SuperVector<16> SuperVector<16>::vshr_32 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_srli_epi32(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_srli_epi32(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -444,7 +444,7 @@ really_inline SuperVector<16> SuperVector<16>::vshr_64 (uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_srli_epi64(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_srli_epi64(v->u.v128[0], i.value))}; });
return result; return result;
} }
@ -459,7 +459,7 @@ really_inline SuperVector<16> SuperVector<16>::vshr_128(uint8_t const N) const
if (N == 0) return *this; if (N == 0) return *this;
if (N == 16) return Zeroes(); if (N == 16) return Zeroes();
SuperVector result; SuperVector result;
Unroller<1, 16>::iterator([&,v=this](auto const i) { constexpr uint8_t n = i.value; if (N == n) result = {SuperVector<16>(_mm_srli_si128(v->u.v128[0], n))}; }); Unroller<1, 16>::iterator([&,v=this](auto const i) { if (N == i.value) result = {SuperVector<16>(_mm_srli_si128(v->u.v128[0], i.value))}; });
return result; return result;
} }

View File

@ -312,7 +312,7 @@ static
string dbSettingsHash(const string &filename, u32 mode) { string dbSettingsHash(const string &filename, u32 mode) {
ostringstream info_oss; ostringstream info_oss;
info_oss << filename.c_str() << ' '; info_oss << filename << ' ';
info_oss << mode << ' '; info_oss << mode << ' ';
string info = info_oss.str(); string info = info_oss.str();

View File

@ -38,8 +38,8 @@ using namespace ue2;
TEST(Truffle, CompileDot) { TEST(Truffle, CompileDot) {
m128 mask1, mask2; m128 mask1, mask2;
memset(&mask1, 0, sizeof(mask1)); memset(&mask1, 0, sizeof(mask1)); // cppcheck-suppress memsetClassFloat
memset(&mask2, 0, sizeof(mask2)); memset(&mask2, 0, sizeof(mask2)); // cppcheck-suppress memsetClassFloat
CharReach chars; CharReach chars;
@ -93,8 +93,8 @@ TEST(Truffle, CompileChars) {
TEST(Truffle, ExecNoMatch1) { TEST(Truffle, ExecNoMatch1) {
m128 mask1, mask2; m128 mask1, mask2;
memset(&mask1, 0, sizeof(mask1)); memset(&mask1, 0, sizeof(mask1)); // cppcheck-suppress memsetClassFloat
memset(&mask2, 0, sizeof(mask2)); memset(&mask2, 0, sizeof(mask2)); // cppcheck-suppress memsetClassFloat
CharReach chars; CharReach chars;

View File

@ -105,7 +105,7 @@ TEST(Uniform, loadstore_m128) {
u32 words[128/32]; u32 words[128/32];
} in; } in;
for (int i = 0; i < 128; i++) { for (int i = 0; i < 128; i++) {
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in)); // cppcheck-suppress memsetClassFloat
in.words[i/32] = 1U << (i % 32); in.words[i/32] = 1U << (i % 32);
const char *cin = reinterpret_cast<const char *>(&in); const char *cin = reinterpret_cast<const char *>(&in);
m128 out = load_m128(cin); m128 out = load_m128(cin);
@ -123,7 +123,7 @@ TEST(Uniform, loadstore_m256) {
u32 words[256/32]; u32 words[256/32];
} in; } in;
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in)); // cppcheck-suppress memsetClassFloat
in.words[i/32] = 1U << (i % 32); in.words[i/32] = 1U << (i % 32);
const char *cin = reinterpret_cast<const char *>(&in); const char *cin = reinterpret_cast<const char *>(&in);
m256 out = load_m256(cin); m256 out = load_m256(cin);
@ -141,7 +141,7 @@ TEST(Uniform, loadstore_m512) {
u32 words[512/32]; u32 words[512/32];
} in; } in;
for (int i = 0; i < 512; i++) { for (int i = 0; i < 512; i++) {
memset(&in, 0, sizeof(in)); memset(&in, 0, sizeof(in)); // cppcheck-suppress memsetClassFloat
in.words[i/32] = 1U << (i % 32); in.words[i/32] = 1U << (i % 32);
const char *cin = reinterpret_cast<const char *>(&in); const char *cin = reinterpret_cast<const char *>(&in);
m512 out = load_m512(cin); m512 out = load_m512(cin);