Skip to content

Commit 81d1df2

Browse files
authored
[SpecialCaseList] Use glob by default (#74809)
https://reviews.llvm.org/D154014 addes glob support and enables it when `#!special-case-list-v2` is the first line. This patch makes the glob support the default (faster than regex after https://reviews.llvm.org/D156046) and switches to the deprecated regex support if `#!special-case-list-v1` is the first line. I have surveyed many ignore lists. All ignore lists I find only use basic `*` `.` and don't use regex metacharacters such as `(` and `)`. (As neither `src:` nor `fun:` benefits from using regex.) They are unaffected by the transition (with a caution that regex `src:x/a.pb.*` matches `x/axpbx` but glob `src:x/a.pb.*` doesn't). There is no deprecating warning. If a user finds `#!special-case-list-v1`, they shall read that the old syntax is deprecated. Link: https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
1 parent e1655a9 commit 81d1df2

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

clang/docs/SanitizerSpecialCaseList.rst

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ and lines starting with "#" are ignored.
5656

5757
.. note::
5858

59-
In `D154014 <https://reviews.llvm.org/D154014>`_ we transitioned to using globs instead
60-
of regexes to match patterns in special case lists. Since this was a
61-
breaking change, we will temporarily support the original behavior using
62-
regexes. If ``#!special-case-list-v2`` is the first line of the file, then
63-
we will use the new behavior using globs. For more details, see
64-
`this discourse post <https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666>`_.
59+
Prior to Clang 18, section names and entries described below use a variant of
60+
regex where ``*`` is translated to ``.*``. Clang 18 (`D154014
61+
<https://reviews.llvm.org/D154014>`) switches to glob and plans to remove
62+
regex support in Clang 19.
6563

64+
For Clang 18, regex is supported if ``#!special-case-list-v1`` is the first
65+
line of the file.
66+
67+
Many special case lists use ``.`` to indicate the literal character and do
68+
not use regex metacharacters such as ``(``, ``)``. They are unaffected by the
69+
regex to glob transition. For more details, see `this discourse post
70+
<https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666>`_.
6671

6772
Section names are globs written in square brackets that denote
6873
which sanitizer the following entries apply to. For example, ``[address]``
@@ -80,7 +85,6 @@ tool-specific docs.
8085

8186
.. code-block:: bash
8287
83-
#!special-case-list-v2
8488
# The line above is explained in the note above
8589
# Lines starting with # are ignored.
8690
# Turn off checks for the source file

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,12 @@ bool SpecialCaseList::parse(const MemoryBuffer *MB, std::string &Error) {
150150
return false;
151151
}
152152

153-
// In https://reviews.llvm.org/D154014 we transitioned to using globs instead
154-
// of regexes to match patterns in special case lists. Since this was a
155-
// breaking change, we will temporarily support the original behavior using
156-
// regexes. If "#!special-case-list-v2" is the first line of the file, then
157-
// we will use the new behavior using globs. For more details, see
153+
// In https://reviews.llvm.org/D154014 we added glob support and planned to
154+
// remove regex support in patterns. We temporarily support the original
155+
// behavior using regexes if "#!special-case-list-v1" is the first line of the
156+
// file. For more details, see
158157
// https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666
159-
bool UseGlobs = MB->getBuffer().starts_with("#!special-case-list-v2\n");
158+
bool UseGlobs = !MB->getBuffer().starts_with("#!special-case-list-v1\n");
160159

161160
for (line_iterator LineIt(*MB, /*SkipBlanks=*/true, /*CommentMarker=*/'#');
162161
!LineIt.is_at_eof(); LineIt++) {

llvm/unittests/Support/SpecialCaseListTest.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class SpecialCaseListTest : public ::testing::Test {
2525
std::string &Error,
2626
bool UseGlobs = true) {
2727
auto S = List.str();
28-
if (UseGlobs)
29-
S = (Twine("#!special-case-list-v2\n") + S).str();
28+
if (!UseGlobs)
29+
S = (Twine("#!special-case-list-v1\n") + S).str();
3030
std::unique_ptr<MemoryBuffer> MB = MemoryBuffer::getMemBuffer(S);
3131
return SpecialCaseList::create(MB.get(), Error);
3232
}
@@ -46,8 +46,8 @@ class SpecialCaseListTest : public ::testing::Test {
4646
SmallString<64> Path;
4747
sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path);
4848
raw_fd_ostream OF(FD, true, true);
49-
if (UseGlobs)
50-
OF << "#!special-case-list-v2\n";
49+
if (!UseGlobs)
50+
OF << "#!special-case-list-v1\n";
5151
OF << Contents;
5252
OF.close();
5353
return std::string(Path.str());
@@ -70,10 +70,10 @@ TEST_F(SpecialCaseListTest, Basic) {
7070
EXPECT_FALSE(SCL->inSection("", "fun", "hello"));
7171
EXPECT_FALSE(SCL->inSection("", "src", "hello", "category"));
7272

73-
EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "hello"));
74-
EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "bye"));
75-
EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "hi", "category"));
76-
EXPECT_EQ(7u, SCL->inSectionBlame("", "src", "zzzz", "category"));
73+
EXPECT_EQ(3u, SCL->inSectionBlame("", "src", "hello"));
74+
EXPECT_EQ(4u, SCL->inSectionBlame("", "src", "bye"));
75+
EXPECT_EQ(5u, SCL->inSectionBlame("", "src", "hi", "category"));
76+
EXPECT_EQ(6u, SCL->inSectionBlame("", "src", "zzzz", "category"));
7777
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hi"));
7878
EXPECT_EQ(0u, SCL->inSectionBlame("", "fun", "hello"));
7979
EXPECT_EQ(0u, SCL->inSectionBlame("", "src", "hello", "category"));
@@ -85,12 +85,12 @@ TEST_F(SpecialCaseListTest, CorrectErrorLineNumberWithBlankLine) {
8585
"\n"
8686
"[not valid\n",
8787
Error));
88-
EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
88+
EXPECT_THAT(Error, StartsWith("malformed section header on line 3:"));
8989

9090
EXPECT_EQ(nullptr, makeSpecialCaseList("\n\n\n"
9191
"[not valid\n",
9292
Error));
93-
EXPECT_THAT(Error, StartsWith("malformed section header on line 5:"));
93+
EXPECT_THAT(Error, StartsWith("malformed section header on line 4:"));
9494
}
9595

9696
TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
@@ -101,7 +101,7 @@ TEST_F(SpecialCaseListTest, SectionGlobErrorHandling) {
101101
EXPECT_EQ(makeSpecialCaseList("[[]", Error), nullptr);
102102
EXPECT_EQ(
103103
Error,
104-
"malformed section at line 2: '[': invalid glob pattern, unmatched '['");
104+
"malformed section at line 1: '[': invalid glob pattern, unmatched '['");
105105

106106
EXPECT_EQ(makeSpecialCaseList("src:=", Error), nullptr);
107107
EXPECT_THAT(Error, HasSubstr("Supplied glob was blank"));
@@ -163,10 +163,10 @@ TEST_F(SpecialCaseListTest, Substring) {
163163
TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) {
164164
std::string Error;
165165
EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error));
166-
EXPECT_EQ("malformed line 2: 'badline'", Error);
166+
EXPECT_EQ("malformed line 1: 'badline'", Error);
167167
EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error));
168168
EXPECT_EQ(
169-
"malformed glob in line 2: 'bad[a-': invalid glob pattern, unmatched '['",
169+
"malformed glob in line 1: 'bad[a-': invalid glob pattern, unmatched '['",
170170
Error);
171171
std::vector<std::string> Files(1, "unexisting");
172172
EXPECT_EQ(nullptr,

0 commit comments

Comments
 (0)