From 23adbebcee97ba002e2e23c35ec4c24550a5db73 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 27 May 2025 18:02:47 -0700 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 --- llvm/lib/Support/SpecialCaseList.cpp | 7 ++++--- llvm/unittests/Support/SpecialCaseListTest.cpp | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp index 47ff3e24706a4..f9b5aafe88e98 100644 --- a/llvm/lib/Support/SpecialCaseList.cpp +++ b/llvm/lib/Support/SpecialCaseList.cpp @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/SpecialCaseList.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/LineIterator.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/VirtualFileSystem.h" @@ -66,10 +67,10 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber, } unsigned SpecialCaseList::Matcher::match(StringRef Query) const { - for (const auto &Glob : Globs) + for (const auto &Glob : reverse(Globs)) if (Glob->Pattern.match(Query)) return Glob->LineNo; - for (const auto &[Regex, LineNumber] : RegExes) + for (const auto &[Regex, LineNumber] : reverse(RegExes)) if (Regex->match(Query)) return LineNumber; return 0; @@ -213,7 +214,7 @@ bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix, unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix, StringRef Query, StringRef Category) const { - for (const auto &S : Sections) { + for (const auto &S : reverse(Sections)) { if (S.SectionMatcher->match(Section)) { unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category); if (Blame) diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index eea185d142891..05e4e83090fd9 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -311,8 +311,7 @@ TEST_F(SpecialCaseListTest, LinesInSection) { std::unique_ptr SCL = makeSpecialCaseList("fun:foo\n" "fun:bar\n" "fun:foo\n"); - // FIXME: Get the last one for #139128. - EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); } @@ -322,8 +321,7 @@ TEST_F(SpecialCaseListTest, LinesCrossSection) { "fun:foo\n" "[sect1]\n" "fun:bar\n"); - // FIXME: Get the last one for #139128. - EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); - EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); + EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "fun", "bar")); } } From 0c29d3233b5f5e51b75ebecb9ac75f478fd4dd4e Mon Sep 17 00:00:00 2001 From: Qinkun Bao Date: Tue, 27 May 2025 18:24:00 -0700 Subject: [PATCH 2/3] rebase Created using spr 1.3.6 --- .../unittests/Support/SpecialCaseListTest.cpp | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index 05e4e83090fd9..c48dcdad4717d 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -311,7 +311,7 @@ TEST_F(SpecialCaseListTest, LinesInSection) { std::unique_ptr SCL = makeSpecialCaseList("fun:foo\n" "fun:bar\n" "fun:foo\n"); - EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); } @@ -321,7 +321,30 @@ TEST_F(SpecialCaseListTest, LinesCrossSection) { "fun:foo\n" "[sect1]\n" "fun:bar\n"); - EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); - EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "fun", "bar")); + EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); +} + +TEST_F(SpecialCaseListTest, Blame) { + std::unique_ptr SCL = makeSpecialCaseList("[sect1]\n" + "src:foo*\n" + "[sect1]\n" + "src:bar*\n" + "src:def\n" + "[sect2]\n" + "src:def\n" + "src:de*\n"); + EXPECT_TRUE(SCL->inSection("sect1", "src", "fooz")); + EXPECT_TRUE(SCL->inSection("sect1", "src", "barz")); + EXPECT_FALSE(SCL->inSection("sect2", "src", "fooz")); + + EXPECT_TRUE(SCL->inSection("sect2", "src", "def")); + EXPECT_TRUE(SCL->inSection("sect1", "src", "def")); + + EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "src", "fooz")); + EXPECT_EQ(4u, SCL->inSectionBlame("sect1", "src", "barz")); + EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "src", "def")); + EXPECT_EQ(8u, SCL->inSectionBlame("sect2", "src", "def")); + EXPECT_EQ(8u, SCL->inSectionBlame("sect2", "src", "dez")); } } From 7f355c6c95115cb41a10ab3b8ea622b29418362d Mon Sep 17 00:00:00 2001 From: Qinkun Bao Date: Tue, 27 May 2025 18:46:43 -0700 Subject: [PATCH 3/3] rebase Created using spr 1.3.6 --- llvm/unittests/Support/SpecialCaseListTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp index c48dcdad4717d..05bd0e63adc20 100644 --- a/llvm/unittests/Support/SpecialCaseListTest.cpp +++ b/llvm/unittests/Support/SpecialCaseListTest.cpp @@ -311,7 +311,7 @@ TEST_F(SpecialCaseListTest, LinesInSection) { std::unique_ptr SCL = makeSpecialCaseList("fun:foo\n" "fun:bar\n" "fun:foo\n"); - EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); } @@ -321,8 +321,8 @@ TEST_F(SpecialCaseListTest, LinesCrossSection) { "fun:foo\n" "[sect1]\n" "fun:bar\n"); - EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo")); - EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar")); + EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo")); + EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "fun", "bar")); } TEST_F(SpecialCaseListTest, Blame) {