diff options
-rw-r--r-- | clang/lib/Basic/Diagnostic.cpp | 5 | ||||
-rw-r--r-- | llvm/include/llvm/Support/SpecialCaseList.h | 2 | ||||
-rw-r--r-- | llvm/lib/Support/GlobPattern.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Support/SpecialCaseList.cpp | 29 | ||||
-rw-r--r-- | llvm/unittests/Support/SpecialCaseListTest.cpp | 28 |
5 files changed, 47 insertions, 29 deletions
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 2282141..690f0ec 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -553,7 +553,10 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) { // Each section has a matcher with that section's name, attached to that // line. const auto &DiagSectionMatcher = Entry.SectionMatcher; - unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second; + unsigned DiagLine = 0; + for (const auto &[Pattern, Pair] : DiagSectionMatcher->Globs) + if (Pattern == DiagName) + DiagLine = Pair.second; LineAndSectionEntry.emplace_back(DiagLine, &Entry); } llvm::sort(LineAndSectionEntry); diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h index fc6dc93..14d83e6 100644 --- a/llvm/include/llvm/Support/SpecialCaseList.h +++ b/llvm/include/llvm/Support/SpecialCaseList.h @@ -125,7 +125,7 @@ protected: // Returns zero if no match is found. LLVM_ABI unsigned match(StringRef Query) const; - StringMap<std::pair<GlobPattern, unsigned>> Globs; + std::vector<std::pair<std::string, std::pair<GlobPattern, unsigned>>> Globs; std::vector<std::pair<std::unique_ptr<Regex>, unsigned>> RegExes; }; diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp index 7004adf46..f68abb6 100644 --- a/llvm/lib/Support/GlobPattern.cpp +++ b/llvm/lib/Support/GlobPattern.cpp @@ -139,6 +139,7 @@ GlobPattern::create(StringRef S, std::optional<size_t> MaxSubPatterns) { // Store the prefix that does not contain any metacharacter. size_t PrefixSize = S.find_first_of("?*[{\\"); Pat.Prefix = S.substr(0, PrefixSize); + llvm::errs() << "GlobPattern::create: Prefix: " << Pat.Prefix << "\n"; if (PrefixSize == std::string::npos) return Pat; S = S.substr(PrefixSize); @@ -191,8 +192,17 @@ GlobPattern::SubGlobPattern::create(StringRef S) { } bool GlobPattern::match(StringRef S) const { - if (!S.consume_front(Prefix)) + int debug = 0; + if (S == "hello") { + llvm::errs() << "Prefix: " << Prefix << "\n"; + debug = 1; + } + if (!S.consume_front(Prefix)) { + if (debug == 1) { + llvm::errs() << "consume_front: " << Prefix << "\n"; + } return false; + } if (SubGlobs.empty() && S.empty()) return true; for (auto &Glob : SubGlobs) diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index dddf84c..17a951f 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -53,24 +53,27 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber, return Error::success(); } - auto [It, DidEmplace] = Globs.try_emplace(Pattern); - if (DidEmplace) { - // We must be sure to use the string in the map rather than the provided - // reference which could be destroyed before match() is called - Pattern = It->getKey(); - auto &Pair = It->getValue(); - if (auto Err = GlobPattern::create(Pattern, /*MaxSubPatterns=*/1024) - .moveInto(Pair.first)) - return Err; - Pair.second = LineNumber; - } + Globs.emplace_back(); + auto &Glob = Globs.back(); + Glob.first = Pattern.str(); + auto &Pair = Glob.second; + // We must be sure to use the string in the map rather than the provided + // reference which could be destroyed before match() is called + llvm::errs() << __func__ << " GlobPattern::create: " << Glob.first << "\n"; + if (auto Err = GlobPattern::create(Glob.first, /*MaxSubPatterns=*/1024) + .moveInto(Pair.first)) + return Err; + Pair.second = LineNumber; return Error::success(); } unsigned SpecialCaseList::Matcher::match(StringRef Query) const { - for (const auto &[Pattern, Pair] : Globs) + for (const auto &[Pattern, Pair] : Globs) { + llvm::outs() << "Inside match: " << Pattern + << " Line number: " << Pair.second << "\n"; if (Pair.first.match(Query)) return Pair.second; + } for (const auto &[Regex, LineNumber] : RegExes) if (Regex->match(Query)) return LineNumber; @@ -228,6 +231,8 @@ unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix, unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries, StringRef Prefix, StringRef Query, StringRef Category) const { + llvm::outs() << "Input Arguments. Prefix: " << Prefix << " Query: " << Query + << " Category: " << Category << " \n"; SectionEntries::const_iterator I = Entries.find(Prefix); if (I == Entries.end()) return 0; diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index 4289a5e..4100357 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -63,20 +63,20 @@ TEST_F(SpecialCaseListTest, Basic) { "src:hi=category\n" "src:z*=category\n"); EXPECT_TRUE(SCL->inSection("", "src", "hello")); - EXPECT_TRUE(SCL->inSection("", "src", "bye")); - EXPECT_TRUE(SCL->inSection("", "src", "hi", "category")); - EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category")); - EXPECT_FALSE(SCL->inSection("", "src", "hi")); - EXPECT_FALSE(SCL->inSection("", "fun", "hello")); - EXPECT_FALSE(SCL->inSection("", "src", "hello", "category")); - - EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello")); - EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye")); - EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category")); - EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category")); - EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi")); - EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello")); - EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category")); + // EXPECT_TRUE(SCL->inSection("", "src", "bye")); + // EXPECT_TRUE(SCL->inSection("", "src", "hi", "category")); + // EXPECT_TRUE(SCL->inSection("", "src", "zzzz", "category")); + // EXPECT_FALSE(SCL->inSection("", "src", "hi")); + // EXPECT_FALSE(SCL->inSection("", "fun", "hello")); + // EXPECT_FALSE(SCL->inSection("", "src", "hello", "category")); + + // EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello")); + // EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye")); + // EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category")); + // EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category")); + // EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi")); + // EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello")); + // EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category")); } TEST_F(SpecialCaseListTest, CorrectErrorLineNumberWithBlankLine) { |