From d789ea713372d44e50ff52a85a198ac6bbedaef9 Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Thu, 16 Sep 2021 17:22:31 -0700 Subject: [PATCH] [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing When a -W 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 --- clang/lib/Basic/Diagnostic.cpp | 6 ++++++ clang/test/Lexer/pragma-message.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp index 9b7ad96b949f1..ac4b9d2cd5a2b 100644 --- a/clang/lib/Basic/Diagnostic.cpp +++ b/clang/lib/Basic/Diagnostic.cpp @@ -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()) { diff --git a/clang/test/Lexer/pragma-message.c b/clang/test/Lexer/pragma-message.c index d0bbe9ea3a628..aca9f14fa2f6d 100644 --- a/clang/test/Lexer/pragma-message.c +++ b/clang/test/Lexer/pragma-message.c @@ -1,6 +1,5 @@ /* 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) @@ -8,6 +7,7 @@ // #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}}