Skip to content

Commit 56faefd

Browse files
committed
[Clang] Silently ignore unknown warnings in --warning-suppression-mappings.
This allows the same file to be used on multiple Clang versions, without generating output spam. Also disable parsing of the suppressions file in the Driver, where it's not needed. This was previously causing the diagnostics to be emitted twice, as the file was being parsed twice. I'll also note that if we do ever wish to emit non-fatal diagnostics from parsing this file, it'll need more: the code deleted here emitted warnings which were not possible for a user to disable, since the suppression file is parsed _before_ the diagnostic state has been setup.
1 parent 517334b commit 56faefd

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,9 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
547547
StringRef DiagGroup = SectionEntry->getKey();
548548
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
549549
WarningFlavor, DiagGroup, GroupDiags)) {
550-
StringRef Suggestion =
551-
DiagnosticIDs::getNearestOption(WarningFlavor, DiagGroup);
552-
Diags.Report(diag::warn_unknown_diag_option)
553-
<< static_cast<unsigned>(WarningFlavor) << DiagGroup
554-
<< !Suggestion.empty() << Suggestion;
550+
// If a diagnostic group name is unknown, simply ignore the
551+
// suppressions. This allows use of a single suppression file on multiple
552+
// versions of clang.
555553
continue;
556554
}
557555
for (diag::kind Diag : GroupDiags)

clang/test/Misc/Inputs/suppression-mapping.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ src:*foo/*=emit
1111
[format=2]
1212
src:*
1313
src:*foo/*=emit
14+
15+
# A warning group that clang doesn't know about should be silently ignored.
16+
[barglegunk]
17+
src:*

clang/tools/driver/driver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
319319
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts =
320320
CreateAndPopulateDiagOpts(Args);
321321

322+
// The _driver_ (vs cc1) diagnostics engine shouldn't bother to load a suppression file.
323+
DiagOpts->DiagnosticSuppressionMappingsFile = "";
324+
322325
TextDiagnosticPrinter *DiagClient
323326
= new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
324327
FixupDiagPrefixExeName(DiagClient, ProgName);

clang/unittests/Basic/DiagnosticTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ TEST_F(SuppressionMappingTest, UnknownDiagName) {
253253
FS->addFile("foo.txt", /*ModificationTime=*/{},
254254
llvm::MemoryBuffer::getMemBuffer("[non-existing-warning]"));
255255
clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
256-
EXPECT_THAT(diags(), ElementsAre(WithMessage(
257-
"unknown warning option 'non-existing-warning'")));
256+
EXPECT_THAT(diags(), IsEmpty());
258257
}
259258

260259
TEST_F(SuppressionMappingTest, SuppressesGroup) {

0 commit comments

Comments
 (0)