r372026 - do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)
Lubos Lunak via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 16 12:18:37 PDT 2019
Author: llunak
Date: Mon Sep 16 12:18:37 2019
New Revision: 372026
URL: http://llvm.org/viewvc/llvm-project?rev=372026&view=rev
Log:
do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)
-frewrite-includes calls PP.SetMacroExpansionOnlyInDirectives() to avoid
macro expansions that are useless in that mode, but this can lead
to -Wunused-macros false positives. As -frewrite-includes does not emit
normal warnings, block -Wunused-macros too.
Differential Revision: https://reviews.llvm.org/D65371
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Frontend/rewrite-includes-warnings.c
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=372026&r1=372025&r2=372026&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Sep 16 12:18:37 2019
@@ -2782,7 +2782,8 @@ void Preprocessor::HandleDefineDirective
// If we need warning for not using the macro, add its location in the
// warn-because-unused-macro set. If it gets used it will be removed from set.
if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
- !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc())) {
+ !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
+ !MacroExpansionInDirectivesOverride) {
MI->setIsWarnIfUnused(true);
WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
}
Modified: cfe/trunk/test/Frontend/rewrite-includes-warnings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-warnings.c?rev=372026&r1=372025&r2=372026&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/rewrite-includes-warnings.c (original)
+++ cfe/trunk/test/Frontend/rewrite-includes-warnings.c Mon Sep 16 12:18:37 2019
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
+// RUN: %clang_cc1 -verify -Wall -Wextra -Wunused-macros -E -frewrite-includes %s
// expected-no-diagnostics
#pragma GCC visibility push (default)
+
+#define USED_MACRO 1
+int test() { return USED_MACRO; }
More information about the cfe-commits
mailing list