Skip to content

Commit

Permalink
[Diagnostics] Don't drop a statically set NoWarningAsError flag durin…
Browse files Browse the repository at this point in the history
…g option processing

When a -W<diag> option is given on the command line, and the corresponding diagnostic has
the NoWarnOnError flag set, prevent the flag from being dropped when the severity is reevaluated.
This fixes PR51837.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D109981
  • Loading branch information
Wolfgang Pieb committed Jan 11, 2022
1 parent 1d3964d commit d789ea7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions clang/lib/Basic/Diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ void DiagnosticsEngine::setSeverity(diag::kind Diag, diag::Severity Map,
DiagnosticMapping Mapping = makeUserMapping(Map, L);
Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);

// Make sure we propagate the NoWarningAsError flag from an existing
// mapping (which may be the default mapping).
DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
Mapping.setNoWarningAsError(Info.hasNoWarningAsError() ||
Mapping.hasNoWarningAsError());

// Common case; setting all the diagnostics of a group in one place.
if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
DiagStatesByLoc.getCurDiagState()) {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Lexer/pragma-message.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* Test pragma message directive from
http://msdn.microsoft.com/en-us/library/x7dkzch2.aspx */

// message: Sends a string literal to the standard output without terminating
// the compilation.
// #pragma message(messagestring)
// OR
// #pragma message messagestring
//
// RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
#define STRING2(x) #x
#define STRING(x) STRING2(x)
#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}
Expand Down

0 comments on commit d789ea7

Please sign in to comment.