Skip to content

Commit d789ea7

Browse files
author
Wolfgang Pieb
committed
[Diagnostics] Don't drop a statically set NoWarningAsError flag during 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
1 parent 1d3964d commit d789ea7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@ void DiagnosticsEngine::setSeverity(diag::kind Diag, diag::Severity Map,
374374
DiagnosticMapping Mapping = makeUserMapping(Map, L);
375375
Mapping.setUpgradedFromWarning(WasUpgradedFromWarning);
376376

377+
// Make sure we propagate the NoWarningAsError flag from an existing
378+
// mapping (which may be the default mapping).
379+
DiagnosticMapping &Info = GetCurDiagState()->getOrAddMapping(Diag);
380+
Mapping.setNoWarningAsError(Info.hasNoWarningAsError() ||
381+
Mapping.hasNoWarningAsError());
382+
377383
// Common case; setting all the diagnostics of a group in one place.
378384
if ((L.isInvalid() || L == DiagStatesByLoc.getCurDiagStateLoc()) &&
379385
DiagStatesByLoc.getCurDiagState()) {

clang/test/Lexer/pragma-message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* Test pragma message directive from
22
http://msdn.microsoft.com/en-us/library/x7dkzch2.aspx */
3-
43
// message: Sends a string literal to the standard output without terminating
54
// the compilation.
65
// #pragma message(messagestring)
76
// OR
87
// #pragma message messagestring
98
//
109
// RUN: %clang_cc1 -fsyntax-only -verify -Werror %s
10+
// RUN: %clang_cc1 -fsyntax-only -verify -Werror -W#pragma-messages %s
1111
#define STRING2(x) #x
1212
#define STRING(x) STRING2(x)
1313
#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}

0 commit comments

Comments
 (0)