]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Fix unreadVariable warning
authorKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Wed, 15 May 2024 14:05:50 +0000 (17:05 +0300)
committerKonstantinos Margaritis <konstantinos@vectorcamp.gr>
Wed, 15 May 2024 14:05:50 +0000 (17:05 +0300)
14 files changed:
src/fdr/fdr_confirm_compile.cpp
src/nfa/dfa_min.cpp
src/nfa/goughcompile.cpp
src/nfa/mcsheng_compile.cpp
src/nfa/nfa_api_queue.h
src/nfa/shengcompile.cpp
src/nfagraph/ng_repeat.cpp
src/nfagraph/ng_som.cpp
src/rose/match.c
src/rose/rose_build_add.cpp
src/rose/rose_build_long_lit.cpp
src/rose/rose_build_misc.cpp
src/stream_compress_impl.h
unit/internal/state_compress.cpp

index 7f4ad7ec83cd75bd86f21ef46494df9cabf7490d..625d1b14a0432ed52ebee3c133bbc1c7b39b7ef6 100644 (file)
@@ -294,9 +294,6 @@ setupFullConfs(const vector<hwlmLiteral> &lits,
                const EngineDescription &eng,
                const map<BucketIndex, vector<LiteralIndex>> &bucketToLits,
                bool make_small) {
-    unique_ptr<TeddyEngineDescription> teddyDescr =
-        getTeddyDescription(eng.getID());
-
     BC2CONF bc2Conf;
     u32 totalConfirmSize = 0;
     for (BucketIndex b = 0; b < eng.getNumBuckets(); b++) {
index 757fffbe96fd8764055e0860e9f0e0170dfe56d7..c44f81eab5ef57577d2def3f80cc160de9843a15 100644 (file)
@@ -304,6 +304,7 @@ void minimize_hopcroft(raw_dfa &rdfa, const Grey &grey) {
         DEBUG_PRINTF("dfa is empty\n");
     }
 
+    // cppcheck-suppress unreadVariable
     UNUSED const size_t states_before = rdfa.states.size();
 
     HopcroftInfo info(rdfa);
index 17193d251e7d2aecae06cacd2100d7bf2b8d96a4..a8ae96cb8d0d5c359444b2fa815d9e8f00afc6dc 100644 (file)
@@ -802,7 +802,7 @@ private:
 
 static
 void prep_joins_for_generation(const GoughGraph &g, GoughVertex v,
-                               map<GoughEdge, edge_join_info> *edge_info) {
+                               map<GoughEdge, edge_join_info> &edge_info) {
     DEBUG_PRINTF("writing out joins for %u\n", g[v].state_id);
     for (const auto &var : g[v].vars) {
         u32 dest_slot = var->slot;
@@ -813,7 +813,7 @@ void prep_joins_for_generation(const GoughGraph &g, GoughVertex v,
             }
 
             for (const GoughEdge &incoming_edge : var_edges.second) {
-                (*edge_info)[incoming_edge].insert(input, dest_slot);
+                edge_info[incoming_edge].insert(input, dest_slot);
                 DEBUG_PRINTF("need %u<-%u\n", dest_slot, input);
             }
         }
@@ -911,7 +911,7 @@ void build_blocks(const GoughGraph &g,
         }
 
         map<GoughEdge, edge_join_info> eji;
-        prep_joins_for_generation(g, t, &eji);
+        prep_joins_for_generation(g, t, eji);
 
         for (auto &m : eji) {
             vector<gough_ins> &block = (*blocks)[gough_edge_id(g, m.first)];
index 9b5d8f590294705d7ce5cea71800980eacf8b4c5..0d3ed834a8b9c13c3652fc77cbfb2773284e73d7 100644 (file)
@@ -1018,12 +1018,16 @@ bytecode_ptr<NFA> mcshengCompile16(dfa_info &info, dstate_id_t sheng_end,
 
     // Sherman optimization
     if (info.impl_alpha_size > 16) {
+#ifdef DEBUG
         u16 total_daddy = 0;
+#endif // DEBUG
         for (u32 i = 0; i < info.size(); i++) {
             find_better_daddy(info, i,
                               is_cyclic_near(info.raw, info.raw.start_anchored),
                               grey);
+#ifdef DEBUG
             total_daddy += info.extra[i].daddytaken;
+#endif // DEBUG
         }
 
         DEBUG_PRINTF("daddy %hu/%zu states=%zu alpha=%hu\n", total_daddy,
@@ -1172,12 +1176,16 @@ bytecode_ptr<NFA> mcsheng64Compile16(dfa_info&info, dstate_id_t sheng_end,
 
     // Sherman optimization
     if (info.impl_alpha_size > 16) {
+#ifdef DEBUG
         u16 total_daddy = 0;
+#endif // DEBUG
         for (u32 i = 0; i < info.size(); i++) {
             find_better_daddy(info, i,
                               is_cyclic_near(info.raw, info.raw.start_anchored),
                               grey);
+#ifdef DEBUG
             total_daddy += info.extra[i].daddytaken;
+#endif // DEBUG
         }
 
         DEBUG_PRINTF("daddy %hu/%zu states=%zu alpha=%hu\n", total_daddy,
@@ -1430,11 +1438,9 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
 
     map<dstate_id_t, AccelScheme> accel_escape_info
         = info.strat.getAccelInfo(cc.grey);
-    auto old_states = info.states;
     dstate_id_t sheng_end = find_sheng_states(info, accel_escape_info, MAX_SHENG_STATES);
 
     if (sheng_end <= DEAD_STATE + 1) {
-        info.states = old_states;
         return bytecode_ptr<NFA>(nullptr);
     }
 
@@ -1447,7 +1453,6 @@ bytecode_ptr<NFA> mcshengCompile(raw_dfa &raw, const CompileContext &cc,
     }
 
     if (!nfa) {
-        info.states = old_states;
         return nfa;
     }
 
index 16a4c011d94a47c0e3a6024114577f15e634c6e4..3f8bca2c1b12923cbef399656614ec270817ac80 100644 (file)
@@ -251,6 +251,10 @@ void q_skip_forward_to(struct mq *q, s64a min_loc) {
 // Dump the contents of the given queue.
 static never_inline UNUSED
 void debugQueue(const struct mq *q) {
+    if (q == nullptr) {
+       DEBUG_PRINTF("q=NULL!\n");
+       return;
+    }
     DEBUG_PRINTF("q=%p, nfa=%p\n", q, q->nfa);
     DEBUG_PRINTF("q offset=%llu, buf={%p, len=%zu}, history={%p, len=%zu}\n",
                  q->offset, q->buffer, q->length, q->history, q->hlength);
index c8a6dacaa8925726ea213bb377b3d3b4801219f6..9d83a587d2d89fc1a284112608179dccc575fffa 100644 (file)
@@ -800,7 +800,7 @@ bytecode_ptr<NFA> sheng64Compile(raw_dfa &raw, const CompileContext &cc,
     old_states = info.states;
     auto nfa = shengCompile_int<sheng64>(raw, cc, accel_states, strat, info);
     if (!nfa) {
-        info.states = old_states;
+        info.states = old_states;  // cppcheck-suppress unreadVariable
     }
     return nfa;
 }
index 8f62ffbb48ab726ec1bbed602879dd6e92eea439..921cf77c5d8c3197da4df424a216b1c8f59eb3c7 100644 (file)
@@ -854,9 +854,7 @@ void replaceSubgraphWithLazySpecial(NGHolder &g, ReachSubgraph &rsi,
     assert(rsi.repeatMax >= rsi.repeatMin);
 
     DEBUG_PRINTF("entry\n");
-
-    const unordered_set<NFAVertex> involved(rsi.vertices.begin(),
-                                            rsi.vertices.end());
     vector<NFAVertex> g_succs;
     getSuccessors(g, rsi, &g_succs);
 
index 518b6ebc51de6cbdafb72d1e29ef91a60e49709c..9197ce44da222878480a2caab7441907d7103553 100644 (file)
@@ -3125,7 +3125,7 @@ sombe_rv doSomWithHaig(NG &ng, NGHolder &g, const ExpressionInfo &expr,
 
     // try a redundancy pass.
     if (addSomRedundancy(g, depths)) {
-        depths = getDistancesFromSOM(g);
+        depths = getDistancesFromSOM(g); // cppcheck-suppress unreadVariable
     }
 
     auto regions = assignRegions(g);
index 643b1d9fcbed46ee78d79aac1cd87107f0d4880c..fa57f9489ea8d573ed007a934d7f14fe16378e03 100644 (file)
@@ -267,7 +267,8 @@ hwlmcb_rv_t playDelaySlot(const struct RoseEngine *t,
     const u32 *programs = getByOffset(t, t->delayProgramOffset);
 
     for (u32 it = fatbit_iterate(vicSlot, delay_count, MMB_INVALID);
-         it != MMB_INVALID; it = fatbit_iterate(vicSlot, delay_count, it)) {
+        it != MMB_INVALID; it = fatbit_iterate(vicSlot, delay_count, it)) {
+        // cppcheck-suppress unreadVariable
         UNUSED rose_group old_groups = tctxt->groups;
 
         DEBUG_PRINTF("DELAYED MATCH id=%u offset=%llu\n", it, offset);
index 2f4e08a44d01d9f773cab47b7e6958f204f6f455..56a9faf5f0f13826e33c7b1634ca7cb0ce9e7c90 100644 (file)
@@ -1039,9 +1039,9 @@ bool canImplementGraph(NGHolder &h, bool prefilter, const ReportManager &rm,
 
     if (prefilter && cc.grey.prefilterReductions) {
         // If we're prefiltering, we can have another go with a reduced graph.
-        UNUSED size_t numBefore = num_vertices(h);
+        UNUSED size_t numBefore = num_vertices(h); // cppcheck-suppress unreadVariable
         prefilterReductions(h, cc);
-        UNUSED size_t numAfter = num_vertices(h);
+        UNUSED size_t numAfter = num_vertices(h);  // cppcheck-suppress unreadVariable
         DEBUG_PRINTF("reduced from %zu to %zu vertices\n", numBefore, numAfter);
 
         if (isImplementableNFA(h, &rm, cc)) {
index 45a2eb270d5ebb91be96f9e8f260a7a476349960..943c5b29fc82b80c38bdad43810b11b9c7b56b43 100644 (file)
@@ -98,8 +98,7 @@ void addToBloomFilter(vector<u8> &bloom, const u8 *substr, bool nocase) {
 
     const auto hash_functions = { bloomHash_1, bloomHash_2, bloomHash_3 };
     for (const auto &hash_func : hash_functions) {
-        u32 hash = hash_func(substr, nocase);
-        u32 key = hash & key_mask;
+        u32 key = hash_func(substr, nocase) & key_mask;
         DEBUG_PRINTF("set key %u (of %zu)\n", key, bloom.size() * 8);
         bloom[key / 8] |= 1U << (key % 8);
     }
@@ -193,11 +192,9 @@ vector<RoseLongLitHashEntry> buildHashTable(
     }
 
     for (const auto &m : hashToLitOffPairs) {
-        u32 hash = m.first;
+        u32 bucket = m.first % numEntries;
         const LitOffsetVector &d = m.second;
 
-        u32 bucket = hash % numEntries;
-
         // Placement via linear probing.
         for (const auto &lit_offset : d) {
             while (tab[bucket].str_offset != 0) {
index d0c630270368de4bd2c1dad3a27d18ee5748f14c..887d8a8d39c64f26e84b5c0d2a15da0e9834b788 100644 (file)
@@ -861,7 +861,6 @@ u32 roseQuality(const RoseResources &res, const RoseEngine *t) {
     }
 
     if (eod_prefix) {
-        always_run++;
         DEBUG_PRINTF("eod prefixes are slow");
         return 0;
     }
index f02543efa59167a09e33b3f162f59022433db554..a4c3e466e070b20a90949c760ce55bece3c3c172 100644 (file)
@@ -142,6 +142,7 @@ size_t JOIN(sc_, FN_SUFFIX)(const struct RoseEngine *rose,
     COPY(stream_body + so->groups, so->groups_size);
 
     /* copy the real bits of history */
+    // cppcheck-suppress unreadVariable
     UNUSED u32 hend = so->history + rose->historyRequired;
     COPY(stream_body + hend - history, history);
 
index d1442b4fa1e06ae6907c1bc69f4afb4d3314edec..58e540a8e5b1c44b4cf506d5aae12645f7c83c5d 100644 (file)
@@ -180,7 +180,7 @@ TEST(state_compress, m128_2) {
             loadcompressed128(&val_out, &buf, &mask, 0);
             EXPECT_TRUE(!diff128(and128(val, mask), val_out));
 
-            mask_raw[j] = 0x7f;
+            mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
         }
     }
 }
@@ -258,7 +258,7 @@ TEST(state_compress, m256_2) {
             loadcompressed256(&val_out, &buf, &mask, 0);
             EXPECT_TRUE(!diff256(and256(val, mask), val_out));
 
-            mask_raw[j] = 0x7f;
+            mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
         }
     }
 }
@@ -338,7 +338,7 @@ TEST(state_compress, m384_2) {
             loadcompressed384(&val_out, &buf, &mask, 0);
             EXPECT_TRUE(!diff384(and384(val, mask), val_out));
 
-            mask_raw[j] = 0x7f;
+            mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
         }
     }
 }
@@ -419,7 +419,7 @@ TEST(state_compress, m512_2) {
             loadcompressed512(&val_out, &buf, &mask, 0);
             EXPECT_TRUE(!diff512(and512(val, mask), val_out));
 
-            mask_raw[j] = 0x7f;
+            mask_raw[j] = 0x7f; // cppcheck-suppress unreadVariable
         }
     }
 }