Merge branch 'develop' into wip-isildur-g-cppcheck66

This commit is contained in:
g. economou
2024-05-02 18:37:46 +03:00
committed by GitHub
122 changed files with 1784 additions and 794 deletions

View File

@@ -192,7 +192,7 @@ int roseCountingMiracleOccurs(const struct RoseEngine *t,
u32 count = 0;
s64a m_loc = start;
s64a m_loc;
if (!cm->shufti) {
u8 c = cm->c;

View File

@@ -353,7 +353,7 @@ void createVertices(RoseBuildImpl *tbi,
edge_props.minBound, edge_props.maxBound);
}
for (auto &m : created) {
for (const auto &m : created) {
tbi->ghost[m.second] = g_v;
}
}
@@ -938,7 +938,7 @@ void shift_accepts_to_end(const RoseInGraph &ig,
}
static
void populateRoseGraph(RoseBuildImpl *tbi, RoseBuildData &bd) {
void populateRoseGraph(RoseBuildImpl *tbi, const RoseBuildData &bd) {
const RoseInGraph &ig = bd.ig;
/* add the pattern in to the main rose graph */

View File

@@ -131,7 +131,6 @@ void findMaskLiteral(const vector<CharReach> &mask, bool streaming,
if (better) {
best_begin = begin;
best_end = end;
best_len = len;
}
for (size_t i = best_begin; i < best_end; i++) {

View File

@@ -674,7 +674,7 @@ buildSuffix(const ReportManager &rm, const SomSlotManager &ssm,
}
assert(suff.graph());
NGHolder &holder = *suff.graph();
const NGHolder &holder = *suff.graph();
assert(holder.kind == NFA_SUFFIX);
const bool oneTop = onlyOneTop(holder);
bool compress_state = cc.streaming;
@@ -1378,7 +1378,7 @@ void updateExclusiveSuffixProperties(const RoseBuildImpl &build,
const vector<ExclusiveInfo> &exclusive_info,
set<u32> *no_retrigger_queues) {
const RoseGraph &g = build.g;
for (auto &info : exclusive_info) {
for (const auto &info : exclusive_info) {
const auto &qi = info.queue;
const auto &subengines = info.subengines;
bool no_retrigger = true;
@@ -1495,7 +1495,7 @@ void findExclusiveInfixes(RoseBuildImpl &build, build_context &bc,
}
static
bool buildLeftfixes(RoseBuildImpl &tbi, build_context &bc,
void buildLeftfixes(RoseBuildImpl &tbi, build_context &bc,
QueueIndexFactory &qif, set<u32> *no_retrigger_queues,
set<u32> *eager_queues, bool do_prefix) {
RoseGraph &g = tbi.g;
@@ -1581,7 +1581,7 @@ bool buildLeftfixes(RoseBuildImpl &tbi, build_context &bc,
leftfix);
}
return true;
return ;
}
static
@@ -1627,11 +1627,11 @@ public:
build.rm);
}
bytecode_ptr<NFA> operator()(unique_ptr<NGHolder> &holder) const {
bytecode_ptr<NFA> operator()(const unique_ptr<NGHolder> &holder) const {
const CompileContext &cc = build.cc;
const ReportManager &rm = build.rm;
NGHolder &h = *holder;
const NGHolder &h = *holder;
assert(h.kind == NFA_OUTFIX);
// Build NFA.
@@ -1657,7 +1657,7 @@ public:
return n;
}
bytecode_ptr<NFA> operator()(UNUSED MpvProto &mpv) const {
bytecode_ptr<NFA> operator()(UNUSED const MpvProto &mpv) const {
// MPV construction handled separately.
assert(mpv.puffettes.empty());
return nullptr;
@@ -2059,16 +2059,8 @@ bool buildNfas(RoseBuildImpl &tbi, build_context &bc, QueueIndexFactory &qif,
suffixTriggers.clear();
*leftfixBeginQueue = qif.allocated_count();
if (!buildLeftfixes(tbi, bc, qif, no_retrigger_queues, eager_queues,
true)) {
return false;
}
if (!buildLeftfixes(tbi, bc, qif, no_retrigger_queues, eager_queues,
false)) {
return false;
}
buildLeftfixes(tbi, bc, qif, no_retrigger_queues, eager_queues,true);
buildLeftfixes(tbi, bc, qif, no_retrigger_queues, eager_queues,false);
return true;
}
@@ -2251,10 +2243,9 @@ vector<u32> buildSuffixEkeyLists(const RoseBuildImpl &build, build_context &bc,
/* for each outfix also build elists */
for (const auto &outfix : build.outfixes) {
u32 qi = outfix.get_queue();
set<u32> ekeys = reportsToEkeys(all_reports(outfix), build.rm);
if (!ekeys.empty()) {
u32 qi = outfix.get_queue();
qi_to_ekeys[qi] = {ekeys.begin(), ekeys.end()};
}
}
@@ -2728,7 +2719,7 @@ void buildLeftInfoTable(const RoseBuildImpl &tbi, build_context &bc,
}
static
RoseProgram makeLiteralProgram(const RoseBuildImpl &build, build_context &bc,
RoseProgram makeLiteralProgram(const RoseBuildImpl &build, const build_context &bc,
ProgramBuild &prog_build, u32 lit_id,
const vector<vector<RoseEdge>> &lit_edge_map,
bool is_anchored_replay_program) {
@@ -2973,9 +2964,10 @@ void buildFragmentPrograms(const RoseBuildImpl &build,
pfrag.lit_ids, lit_edge_map);
if (pfrag.included_frag_id != INVALID_FRAG_ID &&
!lit_prog.empty()) {
auto &cfrag = fragments[pfrag.included_frag_id];
const auto &cfrag = fragments[pfrag.included_frag_id];
assert(pfrag.s.length() >= cfrag.s.length() &&
!pfrag.s.any_nocase() >= !cfrag.s.any_nocase());
!pfrag.s.any_nocase() == !cfrag.s.any_nocase());
/** !pfrag.s.any_nocase() >= !cfrag.s.any_nocase()); **/
u32 child_offset = cfrag.lit_program_offset;
DEBUG_PRINTF("child %u offset %u\n", cfrag.fragment_id,
child_offset);
@@ -2992,8 +2984,9 @@ void buildFragmentPrograms(const RoseBuildImpl &build,
pfrag.lit_ids);
if (pfrag.included_delay_frag_id != INVALID_FRAG_ID &&
!rebuild_prog.empty()) {
auto &cfrag = fragments[pfrag.included_delay_frag_id];
assert(pfrag.s.length() >= cfrag.s.length() &&
const auto &cfrag = fragments[pfrag.included_frag_id];
/** assert(pfrag.s.length() >= cfrag.s.length() && **/
assert(pfrag.s.length() == cfrag.s.length() &&
!pfrag.s.any_nocase() >= !cfrag.s.any_nocase());
u32 child_offset = cfrag.delay_program_offset;
DEBUG_PRINTF("child %u offset %u\n", cfrag.fragment_id,
@@ -3011,7 +3004,7 @@ void updateLitProtoProgramOffset(vector<LitFragment> &fragments,
auto &proto = *litProto.hwlmProto;
for (auto &lit : proto.lits) {
auto fragId = lit.id;
auto &frag = fragments[fragId];
const auto &frag = fragments[fragId];
if (delay) {
DEBUG_PRINTF("delay_program_offset:%u\n",
frag.delay_program_offset);

View File

@@ -170,7 +170,6 @@ void renovateCastle(RoseBuildImpl &tbi, CastleProto *castle,
return; /* bail - TODO: be less lazy */
}
vector<CharReach> rem_local_cr;
u32 ok_count = 0;
for (auto it = e.s.end() - g[v].left.lag; it != e.s.end(); ++it) {
if (!isSubsetOf(*it, cr)) {

View File

@@ -118,7 +118,7 @@ bool addPrefixLiterals(NGHolder &h, unordered_set<u32> &tailId,
for (auto v : adjacent_vertices_range(start, h)) {
if (v != h.startDs) {
for (auto &t : tails) {
for (const auto &t : tails) {
add_edge(t, v, h);
}
}
@@ -126,7 +126,7 @@ bool addPrefixLiterals(NGHolder &h, unordered_set<u32> &tailId,
clear_out_edges(start, h);
add_edge(h.start, h.start, h);
for (auto &t : heads) {
for (const auto &t : heads) {
add_edge(start, t, h);
}

View File

@@ -275,7 +275,7 @@ void assignGroupsToLiterals(RoseBuildImpl &build) {
// Second pass: the other literals.
for (u32 id = 0; id < literals.size(); id++) {
const rose_literal_id &lit = literals.at(id);
rose_literal_info &info = literal_info[id];
const rose_literal_info &info = literal_info[id];
if (!requires_group_assignment(lit, info)) {
continue;

View File

@@ -884,7 +884,7 @@ void buildAccel(const RoseBuildImpl &build,
}
bytecode_ptr<HWLM>
buildHWLMMatcher(const RoseBuildImpl &build, LitProto *litProto) {
buildHWLMMatcher(const RoseBuildImpl &build, const LitProto *litProto) {
if (!litProto) {
return nullptr;
}

View File

@@ -101,7 +101,7 @@ struct LitProto {
};
bytecode_ptr<HWLM>
buildHWLMMatcher(const RoseBuildImpl &build, LitProto *proto);
buildHWLMMatcher(const RoseBuildImpl &build, const LitProto *proto);
std::unique_ptr<LitProto>
buildFloatingMatcherProto(const RoseBuildImpl &build,

View File

@@ -1338,7 +1338,7 @@ void chunk(vector<T> in, vector<vector<T>> *out, size_t chunk_size) {
}
static
insertion_ordered_map<left_id, vector<RoseVertex>> get_eng_verts(RoseGraph &g) {
insertion_ordered_map<left_id, vector<RoseVertex>> get_eng_verts(const RoseGraph &g) {
insertion_ordered_map<left_id, vector<RoseVertex>> eng_verts;
for (auto v : vertices_range(g)) {
const auto &left = g[v].left;
@@ -1599,7 +1599,8 @@ void dedupeLeftfixesVariableLag(RoseBuildImpl &build) {
continue;
}
}
engine_groups[DedupeLeftKey(build, std::move(vpreds), left)].emplace_back(left);
auto preds_copy = std::move(vpreds);
engine_groups[DedupeLeftKey(build, preds_copy , left)].emplace_back(left);
}
/* We don't bother chunking as we expect deduping to be successful if the
@@ -1686,7 +1687,7 @@ void replaceTops(NGHolder &h, const map<u32, u32> &top_mapping) {
}
static
bool setDistinctTops(NGHolder &h1, const NGHolder &h2,
void setDistinctTops(NGHolder &h1, const NGHolder &h2,
map<u32, u32> &top_mapping) {
flat_set<u32> tops1 = getTops(h1), tops2 = getTops(h2);
@@ -1696,7 +1697,7 @@ bool setDistinctTops(NGHolder &h1, const NGHolder &h2,
// If our tops don't intersect, we're OK to merge with no changes.
if (!has_intersection(tops1, tops2)) {
DEBUG_PRINTF("tops don't intersect\n");
return true;
return ;
}
// Otherwise, we have to renumber the tops in h1 so that they don't overlap
@@ -1711,18 +1712,17 @@ bool setDistinctTops(NGHolder &h1, const NGHolder &h2,
}
replaceTops(h1, top_mapping);
return true;
return ;
}
bool setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
void setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
const deque<RoseVertex> &verts1) {
map<u32, u32> top_mapping;
if (!setDistinctTops(h1, h2, top_mapping)) {
return false;
}
setDistinctTops(h1, h2, top_mapping);
if (top_mapping.empty()) {
return true; // No remapping necessary.
return ; // No remapping necessary.
}
for (auto v : verts1) {
@@ -1740,19 +1740,17 @@ bool setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
}
}
return true;
return ;
}
static
bool setDistinctSuffixTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
void setDistinctSuffixTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
const deque<RoseVertex> &verts1) {
map<u32, u32> top_mapping;
if (!setDistinctTops(h1, h2, top_mapping)) {
return false;
}
setDistinctTops(h1, h2, top_mapping);
if (top_mapping.empty()) {
return true; // No remapping necessary.
return ; // No remapping necessary.
}
for (auto v : verts1) {
@@ -1762,7 +1760,7 @@ bool setDistinctSuffixTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
g[v].suffix.top = top_mapping[t];
}
return true;
return ;
}
/** \brief Estimate the number of accel states in the given graph when built as
@@ -1836,10 +1834,7 @@ void mergeNfaLeftfixes(RoseBuildImpl &tbi, LeftfixBouquet &roses) {
}
}
if (!setDistinctRoseTops(g, victim, *r1.graph(), verts2)) {
DEBUG_PRINTF("can't set distinct tops\n");
continue; // next h2
}
setDistinctRoseTops(g, victim, *r1.graph(), verts2);
assert(victim.kind == r1.graph()->kind);
assert(!generates_callbacks(*r1.graph()));
@@ -1924,7 +1919,7 @@ void mergeSmallLeftfixes(RoseBuildImpl &tbi) {
}
assert(left.graph());
NGHolder &h = *left.graph();
const NGHolder &h = *left.graph();
/* Ensure that kind on the graph is correct */
assert(h.kind == (tbi.isRootSuccessor(v) ? NFA_PREFIX : NFA_INFIX));
@@ -2024,7 +2019,7 @@ void mergeCastleLeftfixes(RoseBuildImpl &build) {
return;
}
RoseGraph &g = build.g;
const RoseGraph &g = build.g;
insertion_ordered_map<left_id, vector<RoseVertex>> eng_verts;
@@ -2119,10 +2114,7 @@ void mergeSuffixes(RoseBuildImpl &tbi, SuffixBouquet &suffixes,
old_tops[v] = g[v].suffix.top;
}
if (!setDistinctSuffixTops(g, victim, *s1.graph(), verts2)) {
DEBUG_PRINTF("can't set distinct tops\n");
continue; // next h2
}
setDistinctSuffixTops(g, victim, *s1.graph(), verts2);
if (!mergeNfaPair(victim, *s1.graph(), &tbi.rm, tbi.cc)) {
DEBUG_PRINTF("merge failed\n");
@@ -2306,7 +2298,7 @@ void mergeOutfixInfo(OutfixInfo &winner, const OutfixInfo &victim) {
}
static
map<NGHolder *, NGHolder *> chunkedNfaMerge(RoseBuildImpl &build,
map<NGHolder *, NGHolder *> chunkedNfaMerge(const RoseBuildImpl &build,
const vector<NGHolder *> &nfas) {
map<NGHolder *, NGHolder *> merged;

View File

@@ -62,7 +62,7 @@ bool mergeableRoseVertices(const RoseBuildImpl &tbi, RoseVertex u,
bool mergeableRoseVertices(const RoseBuildImpl &tbi,
const std::set<RoseVertex> &v1,
const std::set<RoseVertex> &v2);
bool setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
void setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2,
const std::deque<RoseVertex> &verts1);
} // namespace ue2

View File

@@ -1004,9 +1004,9 @@ bool hasOrphanedTops(const RoseBuildImpl &build) {
for (auto v : vertices_range(g)) {
if (g[v].left) {
set<u32> &tops = leftfixes[g[v].left];
if (!build.isRootSuccessor(v)) {
// Tops for infixes come from the in-edges.
set<u32> &tops = leftfixes[g[v].left];
for (const auto &e : in_edges_range(v, g)) {
tops.insert(g[e].rose_top);
}

View File

@@ -1294,12 +1294,7 @@ bool attemptRoseGraphMerge(RoseBuildImpl &build, bool preds_same, RoseVertex a,
DEBUG_PRINTF("victim %zu states\n", num_vertices(*a_h));
DEBUG_PRINTF("winner %zu states\n", num_vertices(*b_h));
if (!setDistinctRoseTops(g, victim, *b_h, deque<RoseVertex>(1, a))) {
assert(roseHasTops(build, a));
assert(roseHasTops(build, b));
return false;
}
setDistinctRoseTops(g, victim, *b_h, deque<RoseVertex>(1, a));
assert(victim.kind == b_h->kind);
assert(!generates_callbacks(*b_h));
@@ -1352,8 +1347,8 @@ bool attemptRoseMerge(RoseBuildImpl &build, bool preds_same, RoseVertex a,
assert(a != b);
RoseGraph &g = build.g;
LeftEngInfo &a_left = g[a].left;
LeftEngInfo &b_left = g[b].left;
const LeftEngInfo &a_left = g[a].left;
const LeftEngInfo &b_left = g[b].left;
// Trivial case.
if (a_left == b_left) {
@@ -1601,7 +1596,7 @@ void diamondMergePass(CandidateSet &candidates, RoseBuildImpl &build,
vector<RoseVertex> *dead, bool mergeRoses,
RoseAliasingInfo &rai) {
DEBUG_PRINTF("begin\n");
RoseGraph &g = build.g;
const RoseGraph &g = build.g;
if (candidates.empty()) {
return;
@@ -1972,7 +1967,7 @@ bool hasNoDiamondSiblings(const RoseGraph &g, RoseVertex v) {
* merge.
*/
static
void filterDiamondCandidates(RoseGraph &g, CandidateSet &candidates) {
void filterDiamondCandidates(const RoseGraph &g, CandidateSet &candidates) {
DEBUG_PRINTF("%zu candidates enter\n", candidates.size());
vector<RoseVertex> dead;

View File

@@ -104,7 +104,7 @@ void runAnchoredTableStream(const struct RoseEngine *t, const void *atable,
static really_inline
void saveStreamState(const struct NFA *nfa, struct mq *q, s64a loc) {
void saveStreamState(const struct NFA *nfa, const struct mq *q, s64a loc) {
DEBUG_PRINTF("offset=%llu, length=%zu, hlength=%zu, loc=%lld\n",
q->offset, q->length, q->hlength, loc);
nfaQueueCompressState(nfa, q, loc);