Skip to content

Commit c51ac31

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
1 parent c6ad464 commit c51ac31

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,24 @@ bool SpecialCaseList::createInternal(const MemoryBuffer *MB,
132132
Expected<SpecialCaseList::Section *>
133133
SpecialCaseList::addSection(StringRef SectionStr, unsigned LineNo,
134134
bool UseGlobs) {
135-
Sections.emplace_back();
136-
auto &Section = Sections.back();
137-
Section.SectionStr = SectionStr;
138-
139-
if (auto Err = Section.SectionMatcher->insert(SectionStr, LineNo, UseGlobs)) {
135+
auto it =
136+
std::find_if(Sections.begin(), Sections.end(), [&](const Section &s) {
137+
return s.SectionStr == SectionStr;
138+
});
139+
if (it == Sections.end()) {
140+
Sections.emplace_back();
141+
auto &sec = Sections.back();
142+
sec.SectionStr = SectionStr;
143+
}
144+
it = std::prev(Sections.end());
145+
if (auto Err = it->SectionMatcher->insert(SectionStr, LineNo, UseGlobs)) {
140146
return createStringError(errc::invalid_argument,
141147
"malformed section at line " + Twine(LineNo) +
142148
": '" + SectionStr +
143149
"': " + toString(std::move(Err)));
144150
}
145151

146-
return &Section;
152+
return &(*it);
147153
}
148154

149155
bool SpecialCaseList::parse(const MemoryBuffer *MB, std::string &Error) {

llvm/unittests/Support/SpecialCaseListTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,24 @@ TEST_F(SpecialCaseListTest, Version2) {
306306
EXPECT_TRUE(SCL->inSection("sect2", "fun", "bar"));
307307
EXPECT_FALSE(SCL->inSection("sect3", "fun", "bar"));
308308
}
309+
310+
TEST_F(SpecialCaseListTest, Version3) {
311+
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("[sect1]\n"
312+
"fun:foo*\n"
313+
"[sect1]\n"
314+
"fun:bar*\n"
315+
"[sect2]\n"
316+
"fun:def\n");
317+
EXPECT_TRUE(SCL->inSection("sect1", "fun", "fooz"));
318+
EXPECT_TRUE(SCL->inSection("sect1", "fun", "barz"));
319+
EXPECT_FALSE(SCL->inSection("sect2", "fun", "fooz"));
320+
321+
EXPECT_TRUE(SCL->inSection("sect2", "fun", "def"));
322+
EXPECT_FALSE(SCL->inSection("sect1", "fun", "def"));
323+
324+
EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "fooz"));
325+
EXPECT_EQ(4u, SCL->inSectionBlame("sect1", "fun", "barz"));
326+
EXPECT_EQ(6u, SCL->inSectionBlame("sect2", "fun", "def"));
327+
}
328+
309329
}

0 commit comments

Comments
 (0)