[PATCH] D109981: [Diagnostics] Don't drop a statically set NoWarningAsError flag during option processing
Wolfgang Pieb via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 17 10:14:06 PDT 2021
wolfgangp created this revision.
wolfgangp added a reviewer: dexonsmith.
wolfgangp requested review of this revision.
Fixes PR 51837.
When a -W<diag> option is given on the command line, and the corresponding diangostic has the NoWarnOnError flag set, the flag is dropped when the severity is reevaluated, possibly as a result of a pragma or of command line processing.
https://reviews.llvm.org/D109981
Files:
clang/lib/Basic/Diagnostic.cpp
clang/test/Lexer/pragma-message.c
Index: clang/test/Lexer/pragma-message.c
===================================================================
--- clang/test/Lexer/pragma-message.c
+++ clang/test/Lexer/pragma-message.c
@@ -8,24 +8,25 @@
// #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}}
-#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 14}}
+#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 14}}
+#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 15}}
#pragma message(invalid) // expected-error {{expected string literal in pragma message}}
// GCC supports a similar pragma, #pragma GCC warning (which generates a warning
// message) and #pragma GCC error (which generates an error message).
-#pragma GCC warning(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 21}}
-#pragma GCC warning ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 22}}
+#pragma GCC warning(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 22}}
+#pragma GCC warning ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 23}}
-#pragma GCC error(":O I'm a message! " STRING(__LINE__)) // expected-error {{:O I'm a message! 24}}
-#pragma GCC error ":O gcc accepts this! " STRING(__LINE__) // expected-error {{:O gcc accepts this! 25}}
+#pragma GCC error(":O I'm a message! " STRING(__LINE__)) // expected-error {{:O I'm a message! 25}}
+#pragma GCC error ":O gcc accepts this! " STRING(__LINE__) // expected-error {{:O gcc accepts this! 26}}
#define COMPILE_ERROR(x) _Pragma(STRING2(GCC error(x)))
-COMPILE_ERROR("Compile error at line " STRING(__LINE__) "!"); // expected-error {{Compile error at line 28!}}
+COMPILE_ERROR("Compile error at line " STRING(__LINE__) "!"); // expected-error {{Compile error at line 29!}}
#pragma message // expected-error {{pragma message requires parenthesized string}}
#pragma GCC warning("" // expected-error {{pragma warning requires parenthesized string}}
Index: clang/lib/Basic/Diagnostic.cpp
===================================================================
--- clang/lib/Basic/Diagnostic.cpp
+++ clang/lib/Basic/Diagnostic.cpp
@@ -374,6 +374,12 @@
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()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109981.373255.patch
Type: text/x-patch
Size: 3206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210917/a9af6fa2/attachment-0001.bin>
More information about the cfe-commits
mailing list