]> granicus.if.org Git - clang/commitdiff
do not emit -Wunused-macros warnings in -frewrite-includes mode (PR15614)
authorLubos Lunak <l.lunak@centrum.cz>
Mon, 16 Sep 2019 19:18:37 +0000 (19:18 +0000)
committerLubos Lunak <l.lunak@centrum.cz>
Mon, 16 Sep 2019 19:18:37 +0000 (19:18 +0000)
-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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372026 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Frontend/rewrite-includes-warnings.c

index c4f660f88c73fba39098bd06ea2a911a2ae092cf..fe57f37f09ada33ac4fb9126b1ce16108e4fac87 100644 (file)
@@ -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());
   }
index 1fb98db30147ef5c7f9a3b0926245e104156fa96..d955f86f826a8a138cc9a6b75a50d5553c39e4a7 100644 (file)
@@ -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; }