[clang] [llvm] [NFCI][Sanitizer] Convert Matcher::Globs from StringMap to vector. (PR #140964)
Qinkun Bao via cfe-commits
cfe-commits at lists.llvm.org
Fri May 23 14:12:26 PDT 2025
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 <qinkun at google.com>
Date: Wed, 21 May 2025 22:12:13 +0000
Subject: [PATCH 1/9] =?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 <qinkun at google.com>
Date: Thu, 22 May 2025 20:46:07 +0000
Subject: [PATCH 2/9] 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 <qinkun at google.com>
Date: Thu, 22 May 2025 21:21:35 +0000
Subject: [PATCH 3/9] 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
>From 8415be4d4cee5ae7790620b76c8135ec8b172dba Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 17:49:04 +0000
Subject: [PATCH 4/9] Update the log.
Created using spr 1.3.6
---
llvm/lib/Support/GlobPattern.cpp | 11 +++++++-
llvm/lib/Support/SpecialCaseList.cpp | 17 +++++------
.../unittests/Support/SpecialCaseListTest.cpp | 28 +++++++++----------
3 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp
index 7004adf461a0c..25fc44ff5208e 100644
--- a/llvm/lib/Support/GlobPattern.cpp
+++ b/llvm/lib/Support/GlobPattern.cpp
@@ -191,8 +191,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 674c9bd3aab38..04bf0c80f3166 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -55,10 +55,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
Globs.emplace_back();
auto &Glob = Globs.back();
- Glob.first = Pattern;
+ 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;
@@ -67,11 +68,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
}
unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
- for (const auto &glob : this->Globs) {
- llvm::outs() << "Inside match: " << glob.first
- << " Line number: " << glob.second.second << "\n";
- if (glob.second.first.match(Query))
- return glob.second.second;
+ 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))
@@ -240,10 +241,6 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
return 0;
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 matcher.match(Query);
}
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 4289a5e702155..4100357d8aa8b 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) {
>From c50bd5d9967b77011f8c5f3738bb458ca941ee45 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 17:50:36 +0000
Subject: [PATCH 5/9] remove unrelated changes.
Created using spr 1.3.6
---
llvm/lib/Support/SpecialCaseList.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 04bf0c80f3166..17a951f4cc988 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -240,8 +240,7 @@ unsigned SpecialCaseList::inSectionBlame(const SectionEntries &Entries,
if (II == I->second.end())
return 0;
- const llvm::SpecialCaseList::Matcher &matcher = II->getValue();
- return matcher.match(Query);
+ return II->getValue().match(Query);
}
} // namespace llvm
>From 36ae4577814fbbc433fb3574d8c30f4a24e92642 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 20:55:40 +0000
Subject: [PATCH 6/9] Implement with new glob defintion.
Created using spr 1.3.6
---
clang/lib/Basic/Diagnostic.cpp | 16 ++++++-----
llvm/include/llvm/Support/SpecialCaseList.h | 9 +++++-
llvm/lib/Support/GlobPattern.cpp | 12 +-------
llvm/lib/Support/SpecialCaseList.cpp | 22 ++++++---------
.../unittests/Support/SpecialCaseListTest.cpp | 28 +++++++++----------
5 files changed, 41 insertions(+), 46 deletions(-)
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 690f0ec43a651..5dc5991a294e3 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -554,9 +554,11 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
// line.
const auto &DiagSectionMatcher = Entry.SectionMatcher;
unsigned DiagLine = 0;
- for (const auto &[Pattern, Pair] : DiagSectionMatcher->Globs)
- if (Pattern == DiagName)
- DiagLine = Pair.second;
+ for (const auto &Glob : DiagSectionMatcher->Globs)
+ if (Glob->Name == DiagName) {
+ DiagLine = Glob->LineNo;
+ break;
+ }
LineAndSectionEntry.emplace_back(DiagLine, &Entry);
}
llvm::sort(LineAndSectionEntry);
@@ -628,12 +630,12 @@ bool WarningsSpecialCaseList::globsMatches(
StringRef Category = Entry.getKey();
const llvm::SpecialCaseList::Matcher &Matcher = Entry.getValue();
bool IsPositive = Category != "emit";
- for (const auto &[Pattern, Glob] : Matcher.Globs) {
- if (Pattern.size() < LongestMatch.size())
+ for (const auto &Glob : Matcher.Globs) {
+ if (Glob->Name.size() < LongestMatch.size())
continue;
- if (!Glob.first.match(FilePath))
+ if (!Glob->Pattern.match(FilePath))
continue;
- LongestMatch = Pattern;
+ LongestMatch = Glob->Name;
LongestIsPositive = IsPositive;
}
}
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index 14d83e64ec28c..2c8c41cae78d2 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -125,7 +125,14 @@ class SpecialCaseList {
// Returns zero if no match is found.
LLVM_ABI unsigned match(StringRef Query) const;
- std::vector<std::pair<std::string, std::pair<GlobPattern, unsigned>>> Globs;
+ struct Glob {
+ std::string Name;
+ unsigned LineNo;
+ GlobPattern Pattern;
+ Glob(Glob &&) = delete;
+ };
+
+ std::vector<std::unique_ptr<Matcher::Glob>> 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 f68abb644fa92..7004adf461a0c 100644
--- a/llvm/lib/Support/GlobPattern.cpp
+++ b/llvm/lib/Support/GlobPattern.cpp
@@ -139,7 +139,6 @@ 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);
@@ -192,17 +191,8 @@ GlobPattern::SubGlobPattern::create(StringRef S) {
}
bool GlobPattern::match(StringRef S) const {
- 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";
- }
+ if (!S.consume_front(Prefix))
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 17a951f4cc988..3d7e652efed1a 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -53,26 +53,22 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
return Error::success();
}
- Globs.emplace_back();
- auto &Glob = Globs.back();
- Glob.first = Pattern.str();
- auto &Pair = Glob.second;
+ std::unique_ptr<Matcher::Glob> Glob = std::make_unique<Matcher::Glob>();
+ Glob->Name = Pattern.str();
+ Glob->LineNo = LineNumber;
// 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))
+ if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
+ .moveInto(Glob->Pattern))
return Err;
- Pair.second = LineNumber;
+ Globs.push_back(std::move(Glob));
return Error::success();
}
unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
- 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 &Glob : Globs) {
+ if (Glob->Pattern.match(Query))
+ return Glob->LineNo;
}
for (const auto &[Regex, LineNumber] : RegExes)
if (Regex->match(Query))
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp
index 4100357d8aa8b..4289a5e702155 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) {
>From e4e17aae8dfe5f03ee1f798e79536ab7dc3a7f30 Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 20:56:55 +0000
Subject: [PATCH 7/9] Remove debug logs.
Created using spr 1.3.6
---
llvm/lib/Support/SpecialCaseList.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 3d7e652efed1a..085f8005c9c75 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -227,8 +227,6 @@ 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;
>From 5154d7c085bf53f595308ac9b6a7b481c782a70d Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 21:02:54 +0000
Subject: [PATCH 8/9] add auto qualifier.
Created using spr 1.3.6
---
llvm/include/llvm/Support/SpecialCaseList.h | 1 -
llvm/lib/Support/SpecialCaseList.cpp | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index 2c8c41cae78d2..af4dda181117a 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -129,7 +129,6 @@ class SpecialCaseList {
std::string Name;
unsigned LineNo;
GlobPattern Pattern;
- Glob(Glob &&) = delete;
};
std::vector<std::unique_ptr<Matcher::Glob>> Globs;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 085f8005c9c75..f2e2ebe730bb0 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -53,7 +53,7 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
return Error::success();
}
- std::unique_ptr<Matcher::Glob> Glob = std::make_unique<Matcher::Glob>();
+ auto Glob = std::make_unique<Matcher::Glob>();
Glob->Name = Pattern.str();
Glob->LineNo = LineNumber;
// We must be sure to use the string in the map rather than the provided
>From 4e06e02503a6bc056db5ff71690241eecf64f6aa Mon Sep 17 00:00:00 2001
From: Qinkun Bao <qinkun at google.com>
Date: Fri, 23 May 2025 21:12:14 +0000
Subject: [PATCH 9/9] Add some comments.
Created using spr 1.3.6
---
llvm/include/llvm/Support/SpecialCaseList.h | 3 +++
llvm/lib/Support/SpecialCaseList.cpp | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/SpecialCaseList.h b/llvm/include/llvm/Support/SpecialCaseList.h
index af4dda181117a..bc2215b32bdbf 100644
--- a/llvm/include/llvm/Support/SpecialCaseList.h
+++ b/llvm/include/llvm/Support/SpecialCaseList.h
@@ -129,6 +129,9 @@ class SpecialCaseList {
std::string Name;
unsigned LineNo;
GlobPattern Pattern;
+ // neither copyable nor movable because GlobPattern contains StringRef.
+ Glob(Glob &&) = delete;
+ Glob() = default;
};
std::vector<std::unique_ptr<Matcher::Glob>> Globs;
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index f2e2ebe730bb0..3ccd689e736d6 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -56,7 +56,7 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
auto Glob = std::make_unique<Matcher::Glob>();
Glob->Name = Pattern.str();
Glob->LineNo = LineNumber;
- // We must be sure to use the string in the map rather than the provided
+ // We must be sure to use the string in `Glob` rather than the provided
// reference which could be destroyed before match() is called
if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
.moveInto(Glob->Pattern))
More information about the cfe-commits
mailing list