https://github.com/qinkunbao updated 
https://github.com/llvm/llvm-project/pull/140964

>From 534d49d489476ffd1aa8f23d21a02f29d3b823fc Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qin...@google.com>
Date: Wed, 21 May 2025 22:12:13 +0000
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6
---
 clang/lib/Basic/Diagnostic.cpp              |  5 ++++-
 llvm/include/llvm/Support/SpecialCaseList.h |  2 +-
 llvm/lib/Support/SpecialCaseList.cpp        | 21 ++++++++++-----------
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index b48eed8650672..8168c36d9ccce 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 fc6dc93651f38..14d83e64ec28c 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -125,7 +125,7 @@ class SpecialCaseList {
     // 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/SpecialCaseList.cpp 
b/llvm/lib/Support/SpecialCaseList.cpp
index dddf84cbb1ced..3e43f7bc93eff 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -53,17 +53,16 @@ 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;
+  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
+  if (auto Err = GlobPattern::create(Glob.first, /*MaxSubPatterns=*/1024)
+                     .moveInto(Pair.first))
+    return Err;
+  Pair.second = LineNumber;
   return Error::success();
 }
 

>From e26e2c03478107fb11fcdda3cee8b708cb322e5b Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qin...@google.com>
Date: Thu, 22 May 2025 20:46:07 +0000
Subject: [PATCH 2/3] Update local

Created using spr 1.3.6
---
 llvm/lib/Support/SpecialCaseList.cpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Support/SpecialCaseList.cpp 
b/llvm/lib/Support/SpecialCaseList.cpp
index 3e43f7bc93eff..0218bf5d7a5db 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -67,9 +67,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, 
unsigned LineNumber,
 }
 
 unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
-  for (const auto &[Pattern, Pair] : Globs)
-    if (Pair.first.match(Query))
-      return Pair.second;
+  for (const auto &glob : this->Globs) {
+    llvm::outs() << "Match: " << glob.first << " Line number: " << 
glob.second.second << "\n";
+    if (glob.second.first.match(Query))
+      return glob.second.second;
+  }
   for (const auto &[Regex, LineNumber] : RegExes)
     if (Regex->match(Query))
       return LineNumber;
@@ -227,13 +229,19 @@ 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;
   StringMap<Matcher>::const_iterator II = I->second.find(Category);
+
   if (II == I->second.end())
     return 0;
 
+  for (const auto& glob : II->getValue().Globs) {
+    llvm::outs() << "glob pattern: " << glob.first << " line number: " << 
glob.second.second << "\n";
+  }
   return II->getValue().match(Query);
 }
 

>From a975b6cab9cc5666e186e688410a61f2a613cba8 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qin...@google.com>
Date: Thu, 22 May 2025 21:21:35 +0000
Subject: [PATCH 3/3] Update the example.

Created using spr 1.3.6
---
 llvm/lib/Support/SpecialCaseList.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Support/SpecialCaseList.cpp 
b/llvm/lib/Support/SpecialCaseList.cpp
index 0218bf5d7a5db..674c9bd3aab38 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -68,7 +68,8 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, 
unsigned LineNumber,
 
 unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
   for (const auto &glob : this->Globs) {
-    llvm::outs() << "Match: " << glob.first << " Line number: " << 
glob.second.second << "\n";
+    llvm::outs() << "Inside match: " << glob.first
+                 << " Line number: " << glob.second.second << "\n";
     if (glob.second.first.match(Query))
       return glob.second.second;
   }
@@ -235,14 +236,15 @@ unsigned SpecialCaseList::inSectionBlame(const 
SectionEntries &Entries,
   if (I == Entries.end())
     return 0;
   StringMap<Matcher>::const_iterator II = I->second.find(Category);
-
   if (II == I->second.end())
     return 0;
 
-  for (const auto& glob : II->getValue().Globs) {
-    llvm::outs() << "glob pattern: " << glob.first << " line number: " << 
glob.second.second << "\n";
+  const llvm::SpecialCaseList::Matcher &matcher = II->getValue();
+  for (const auto &glob : matcher.Globs) {
+    llvm::outs() << "Outside match: " << glob.first
+                 << " line number: " << glob.second.second << "\n";
   }
-  return II->getValue().match(Query);
+  return matcher.match(Query);
 }
 
 } // namespace llvm

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to