Skip to content

Commit cadc8fa

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.7
2 parents 3bb903e + f0940a5 commit cadc8fa

File tree

7 files changed

+12
-33
lines changed

7 files changed

+12
-33
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Potentially Breaking Changes
6969
call the member ``operator delete`` instead of the expected global
7070
delete operator. The old behavior is retained under ``-fclang-abi-compat=21``
7171
flag.
72+
- Clang warning suppressions file, ``--warning-suppression-mappings=``, now will
73+
use the last matching entry instead of the longest one.
7274
- Trailing null statements in GNU statement expressions are no longer
7375
ignored by Clang; they now result in a void type. Clang previously
7476
matched GCC's behavior, which was recently clarified to be incorrect.

clang/docs/WarningSuppressionMappings.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Format
6363
Warning suppression mappings uses the same format as
6464
:doc:`SanitizerSpecialCaseList`.
6565

66-
Sections describe which diagnostic group's behaviour to change, e.g.
66+
Sections describe which diagnostic group's behavior to change, e.g.
6767
``[unused]``. When a diagnostic is matched by multiple sections, the latest
6868
section takes precedence.
6969

@@ -76,7 +76,7 @@ Source files are matched against these globs either:
7676
- as paths relative to the current working directory
7777
- as absolute paths.
7878

79-
When a source file matches multiple globs in a section, the longest one takes
79+
When a source file matches multiple globs in a section, the last one takes
8080
precedence.
8181

8282
.. code-block:: bash

clang/include/clang/Basic/Diagnostic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
971971
/// diagnostics in specific files.
972972
/// Mapping file is expected to be a special case list with sections denoting
973973
/// diagnostic groups and `src` entries for globs to suppress. `emit` category
974-
/// can be used to disable suppression. Longest glob that matches a filepath
974+
/// can be used to disable suppression. The last glob that matches a filepath
975975
/// takes precedence. For example:
976976
/// [unused]
977977
/// src:clang/*

clang/lib/Basic/Diagnostic.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,15 +588,12 @@ bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
588588

589589
StringRef F = llvm::sys::path::remove_leading_dotslash(PLoc.getFilename());
590590

591-
StringRef LongestSup = DiagSection->getLongestMatch("src", F, "");
592-
if (LongestSup.empty())
591+
unsigned LastSup = DiagSection->getLastMatch("src", F, "");
592+
if (LastSup == 0)
593593
return false;
594594

595-
StringRef LongestEmit = DiagSection->getLongestMatch("src", F, "emit");
596-
if (LongestEmit.empty())
597-
return true;
598-
599-
return LongestSup.size() > LongestEmit.size();
595+
unsigned LastEmit = DiagSection->getLastMatch("src", F, "emit");
596+
return LastSup > LastEmit;
600597
}
601598

602599
bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,

clang/unittests/Basic/DiagnosticTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ TEST_F(SuppressionMappingTest, EmitCategoryIsExcluded) {
294294
locForFile("foo.cpp")));
295295
}
296296

297-
TEST_F(SuppressionMappingTest, LongestMatchWins) {
297+
TEST_F(SuppressionMappingTest, LastMatchWins) {
298298
llvm::StringLiteral SuppressionMappingFile = R"(
299299
[unused]
300300
src:*clang/*
@@ -327,10 +327,8 @@ TEST_F(SuppressionMappingTest, LongShortMatch) {
327327

328328
EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
329329
locForFile("test/t1.cpp")));
330-
331-
// FIXME: This is confusing.
332-
EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
333-
locForFile("lld/test/t2.cpp")));
330+
EXPECT_FALSE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
331+
locForFile("lld/test/t2.cpp")));
334332
}
335333

336334
TEST_F(SuppressionMappingTest, ShortLongMatch) {

llvm/include/llvm/Support/SpecialCaseList.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ class SpecialCaseList {
218218
LLVM_ABI unsigned getLastMatch(StringRef Prefix, StringRef Query,
219219
StringRef Category) const;
220220

221-
// Helper method to search by Prefix, Query, and Category. Returns
222-
// matching rule, or empty string if there is no match.
223-
LLVM_ABI StringRef getLongestMatch(StringRef Prefix, StringRef Query,
224-
StringRef Category) const;
225-
226221
private:
227222
friend class SpecialCaseList;
228223
LLVM_ABI void preprocess(bool OrderBySize);

llvm/lib/Support/SpecialCaseList.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -380,17 +380,4 @@ unsigned SpecialCaseList::Section::getLastMatch(StringRef Prefix,
380380
return LastLine;
381381
}
382382

383-
StringRef SpecialCaseList::Section::getLongestMatch(StringRef Prefix,
384-
StringRef Query,
385-
StringRef Category) const {
386-
StringRef LongestRule;
387-
if (const Matcher *M = findMatcher(Prefix, Category)) {
388-
M->match(Query, [&](StringRef Rule, unsigned) {
389-
if (LongestRule.size() < Rule.size())
390-
LongestRule = Rule;
391-
});
392-
}
393-
return LongestRule;
394-
}
395-
396383
} // namespace llvm

0 commit comments

Comments
 (0)