From ea420114a7d6ea4447638dfb60cf0f2fc7f76e71 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Wed, 1 May 2024 12:59:34 +0300 Subject: [PATCH 1/3] knownConditionTrueFalse --- src/hs_valid_platform.c | 1 + src/nfa/limex_compile.cpp | 1 + src/rose/rose_build_merge.cpp | 19 +++++-------------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/hs_valid_platform.c b/src/hs_valid_platform.c index 74a8fc1e..3fa1b08d 100644 --- a/src/hs_valid_platform.c +++ b/src/hs_valid_platform.c @@ -48,6 +48,7 @@ hs_error_t HS_CDECL hs_valid_platform(void) { return HS_ARCH_ERROR; } #elif !defined(VS_SIMDE_BACKEND) && (defined(ARCH_ARM32) || defined(ARCH_AARCH64)) + //check_neon returns true for now if (check_neon()) { return HS_SUCCESS; } else { diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index 2ec65552..5bc27301 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -1481,6 +1481,7 @@ u32 buildExceptionMap(const build_info &args, ReportListCache &reports_cache, continue; } u32 j = args.state_ids.at(w); + // j can be NO_STATE if args.state_ids.at(w) returns NO_STATE if (j == NO_STATE) { continue; } diff --git a/src/rose/rose_build_merge.cpp b/src/rose/rose_build_merge.cpp index 1e6c9222..c0df5765 100644 --- a/src/rose/rose_build_merge.cpp +++ b/src/rose/rose_build_merge.cpp @@ -1718,9 +1718,8 @@ bool setDistinctTops(NGHolder &h1, const NGHolder &h2, bool setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2, const deque &verts1) { map top_mapping; - if (!setDistinctTops(h1, h2, top_mapping)) { - return false; - } + + setDistinctTops(h1, h2, top_mapping); if (top_mapping.empty()) { return true; // No remapping necessary. @@ -1748,9 +1747,7 @@ static bool setDistinctSuffixTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2, const deque &verts1) { map top_mapping; - if (!setDistinctTops(h1, h2, top_mapping)) { - return false; - } + setDistinctTops(h1, h2, top_mapping); if (top_mapping.empty()) { return true; // No remapping necessary. @@ -1837,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())); @@ -2120,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"); From 389b55c647da265a9ed68cffe7cbb6f93b6b7e99 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Wed, 1 May 2024 15:21:36 +0300 Subject: [PATCH 2/3] refactor bool to void setDistinctTops setDistinctRoseTops setDistinctSuffixTops --- src/rose/rose_build_merge.cpp | 18 +++++++++--------- src/rose/rose_build_merge.h | 2 +- src/rose/rose_build_role_aliasing.cpp | 7 +------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/rose/rose_build_merge.cpp b/src/rose/rose_build_merge.cpp index c0df5765..21093a81 100644 --- a/src/rose/rose_build_merge.cpp +++ b/src/rose/rose_build_merge.cpp @@ -1687,7 +1687,7 @@ void replaceTops(NGHolder &h, const map &top_mapping) { } static -bool setDistinctTops(NGHolder &h1, const NGHolder &h2, +void setDistinctTops(NGHolder &h1, const NGHolder &h2, map &top_mapping) { flat_set tops1 = getTops(h1), tops2 = getTops(h2); @@ -1697,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 @@ -1712,17 +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 &verts1) { map top_mapping; setDistinctTops(h1, h2, top_mapping); if (top_mapping.empty()) { - return true; // No remapping necessary. + return ; // No remapping necessary. } for (auto v : verts1) { @@ -1740,17 +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 &verts1) { map top_mapping; setDistinctTops(h1, h2, top_mapping); if (top_mapping.empty()) { - return true; // No remapping necessary. + return ; // No remapping necessary. } for (auto v : verts1) { @@ -1760,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 diff --git a/src/rose/rose_build_merge.h b/src/rose/rose_build_merge.h index 6de6c778..e93a977f 100644 --- a/src/rose/rose_build_merge.h +++ b/src/rose/rose_build_merge.h @@ -62,7 +62,7 @@ bool mergeableRoseVertices(const RoseBuildImpl &tbi, RoseVertex u, bool mergeableRoseVertices(const RoseBuildImpl &tbi, const std::set &v1, const std::set &v2); -bool setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2, +void setDistinctRoseTops(RoseGraph &g, NGHolder &h1, const NGHolder &h2, const std::deque &verts1); } // namespace ue2 diff --git a/src/rose/rose_build_role_aliasing.cpp b/src/rose/rose_build_role_aliasing.cpp index 2888b9a0..39721d6f 100644 --- a/src/rose/rose_build_role_aliasing.cpp +++ b/src/rose/rose_build_role_aliasing.cpp @@ -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(1, a))) { - assert(roseHasTops(build, a)); - assert(roseHasTops(build, b)); - return false; - } + setDistinctRoseTops(g, victim, *b_h, deque(1, a)); assert(victim.kind == b_h->kind); assert(!generates_callbacks(*b_h)); From a634d57b2d5844b15f3168453f0bbd76d93d67e3 Mon Sep 17 00:00:00 2001 From: gtsoul-tech Date: Thu, 2 May 2024 10:13:55 +0300 Subject: [PATCH 3/3] knownConditionTrueFalse fixes previously fp --- src/nfa/repeat.c | 4 ++-- src/rose/rose_build_bytecode.cpp | 16 ++++------------ unit/internal/fdr_flood.cpp | 18 ++++++------------ unit/internal/flat_set.cpp | 4 +--- unit/internal/insertion_ordered.cpp | 4 +--- 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/nfa/repeat.c b/src/nfa/repeat.c index 5b2e4df4..07d02082 100644 --- a/src/nfa/repeat.c +++ b/src/nfa/repeat.c @@ -785,7 +785,7 @@ enum RepeatMatch repeatHasMatchRange(const struct RepeatInfo *info, if (diff > info->repeatMax) { DEBUG_PRINTF("range list is stale\n"); return REPEAT_STALE; - } else if (diff >= info->repeatMin && diff <= info->repeatMax) { + } else if (diff >= info->repeatMin) { return REPEAT_MATCH; } @@ -836,7 +836,7 @@ enum RepeatMatch repeatHasMatchBitmap(const struct RepeatInfo *info, if (diff > info->repeatMax) { DEBUG_PRINTF("stale\n"); return REPEAT_STALE; - } else if (diff >= info->repeatMin && diff <= info->repeatMax) { + } else if (diff >= info->repeatMin) { return REPEAT_MATCH; } diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index 639edddc..181d77e5 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -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 *no_retrigger_queues, set *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 @@ -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; } diff --git a/unit/internal/fdr_flood.cpp b/unit/internal/fdr_flood.cpp index 77d3ff47..fd8a9734 100644 --- a/unit/internal/fdr_flood.cpp +++ b/unit/internal/fdr_flood.cpp @@ -154,7 +154,7 @@ TEST_P(FDRFloodp, NoMask) { struct hs_scratch scratch; scratch.fdr_conf = NULL; - while (1) { + while (c != 255) { SCOPED_TRACE((unsigned int)c); u8 bit = 1 << (c & 0x7); u8 cAlt = c ^ bit; @@ -233,9 +233,7 @@ TEST_P(FDRFloodp, NoMask) { } matchesCounts.clear(); - if (++c == 0) { - break; - } + ++c; } } @@ -248,7 +246,7 @@ TEST_P(FDRFloodp, WithMask) { struct hs_scratch scratch; scratch.fdr_conf = NULL; - while (1) { + while (c != 255) { u8 bit = 1 << (c & 0x7); u8 cAlt = c ^ bit; SCOPED_TRACE((unsigned int)c); @@ -396,9 +394,7 @@ TEST_P(FDRFloodp, WithMask) { } matchesCounts.clear(); - if (++c == '\0') { - break; - } + ++c; } } @@ -414,7 +410,7 @@ TEST_P(FDRFloodp, StreamingMask) { struct hs_scratch scratch; scratch.fdr_conf = NULL; - while (1) { + while (c != 255) { u8 bit = 1 << (c & 0x7); u8 cAlt = c ^ bit; SCOPED_TRACE((unsigned int)c); @@ -548,9 +544,7 @@ TEST_P(FDRFloodp, StreamingMask) { } } - if (++c == '\0') { - break; - } + ++c; } matchesCounts.clear(); } diff --git a/unit/internal/flat_set.cpp b/unit/internal/flat_set.cpp index 10607a6f..174a4771 100644 --- a/unit/internal/flat_set.cpp +++ b/unit/internal/flat_set.cpp @@ -48,9 +48,7 @@ std::ostream &operator<<(std::ostream &os, const flat_set &f) { os << "{"; for (auto it = begin(f); it != end(f); ++it) { os << *it; - if (it != end(f)) { - os << ", "; - } + os << ", "; } os << "}"; return os; diff --git a/unit/internal/insertion_ordered.cpp b/unit/internal/insertion_ordered.cpp index 6026ce1d..2d799aa9 100644 --- a/unit/internal/insertion_ordered.cpp +++ b/unit/internal/insertion_ordered.cpp @@ -149,9 +149,7 @@ std::ostream &operator<<(std::ostream &os, const insertion_ordered_set &s) { os << "{"; for (auto it = begin(s); it != end(s); ++it) { os << *it; - if (it != end(s)) { - os << ", "; - } + os << ", "; } os << "}"; return os;