Skip to content

Commit c613019

Browse files
committed
Make special case matcher slash-agnostic
1 parent 839b91c commit c613019

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

clang/docs/SanitizerSpecialCaseList.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ tool-specific docs.
174174
# Lines starting with # are ignored.
175175
# Turn off checks for the source file
176176
# Entries without sections are placed into [*] and apply to all sanitizers
177+
# "/" matches both windows and unix path separators ("/" and "\")
177178
src:path/to/source/file.c
178179
src:*/source/file.c
179180
# Turn off checks for this main file, including files included by it.

clang/unittests/Basic/DiagnosticTest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,27 @@ TEST_F(SuppressionMappingTest, ParsingRespectsOtherWarningOpts) {
360360
clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
361361
EXPECT_THAT(diags(), IsEmpty());
362362
}
363+
364+
TEST_F(SuppressionMappingTest, ForwardSlashMatchesBothDirections) {
365+
llvm::StringLiteral SuppressionMappingFile = R"(
366+
[unused]
367+
src:*clang/*
368+
src:*clang/lib/Sema/*=emit
369+
src:*clang/lib\\Sema/foo*)";
370+
Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
371+
FS->addFile("foo.txt", /*ModificationTime=*/{},
372+
llvm::MemoryBuffer::getMemBuffer(SuppressionMappingFile));
373+
clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
374+
EXPECT_THAT(diags(), IsEmpty());
375+
376+
EXPECT_TRUE(Diags.isSuppressedViaMapping(
377+
diag::warn_unused_function, locForFile(R"(clang/lib/Basic/foo.h)")));
378+
EXPECT_FALSE(Diags.isSuppressedViaMapping(
379+
diag::warn_unused_function, locForFile(R"(clang/lib/Sema\bar.h)")));
380+
EXPECT_TRUE(Diags.isSuppressedViaMapping(
381+
diag::warn_unused_function, locForFile(R"(clang\lib\Sema/foo.h)")));
382+
// The third pattern requires a literal backslash before Sema
383+
EXPECT_FALSE(Diags.isSuppressedViaMapping(
384+
diag::warn_unused_function, locForFile(R"(clang/lib/Sema/foo.h)")));
385+
}
363386
} // namespace

llvm/docs/ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ Changes to BOLT
174174
Changes to Sanitizers
175175
---------------------
176176

177+
* The [sanitizer special case list format](https://clang.llvm.org/docs/SanitizerSpecialCaseList.html#format)
178+
now treats forward slashes as either a forward or a backslash, to handle
179+
paths with mixed unix and window styles.
180+
177181
Other Changes
178182
-------------
179183

llvm/include/llvm/Support/GlobPattern.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace llvm {
3535
/// expansions are not supported. If \p MaxSubPatterns is empty then
3636
/// brace expansions are not supported and characters `{,}` are treated as
3737
/// literals.
38+
/// * `/` matches both unix and windows path separators: `/` and `\`.
3839
/// * `\` escapes the next character so it is treated as a literal.
3940
///
4041
/// Some known edge cases are:

llvm/lib/Support/GlobPattern.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ bool GlobPattern::SubGlobPattern::match(StringRef Str) const {
231231
++S;
232232
continue;
233233
}
234+
} else if (*P == '/' && (*S == '/' || *S == '\\')) {
235+
++P;
236+
++S;
237+
continue;
234238
} else if (*P == *S || *P == '?') {
235239
++P;
236240
++S;

0 commit comments

Comments
 (0)