This is a re-send of http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131125/094231.html which went without any answer.
See PR15614 for a testcase. -- Lubos Lunak
From 710be67e5d01095a723a032676ea178193172b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <[email protected]> Date: Sun, 28 Jul 2013 11:32:55 +0200 Subject: [PATCH] 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. --- lib/Lex/PPDirectives.cpp | 5 +++++ test/Frontend/rewrite-includes-warnings.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 57dc495..f0e9b29 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -647,6 +647,9 @@ public: pp->DisableMacroExpansion = false; } ~ResetMacroExpansionHelper() { + restore(); + } + void restore() { PP->DisableMacroExpansion = save; } private: @@ -758,6 +761,7 @@ void Preprocessor::HandleDirective(Token &Result) { // C99 6.10.3 - Macro Replacement. case tok::pp_define: + helper.restore(); return HandleDefineDirective(Result, ImmediatelyAfterTopLevelIfndef); case tok::pp_undef: return HandleUndefDirective(Result); @@ -2105,6 +2109,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok, // 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()) && + !DisableMacroExpansion && Diags->getDiagnosticLevel(diag::pp_macro_not_used, MI->getDefinitionLoc()) != DiagnosticsEngine::Ignored) { MI->setIsWarnIfUnused(true); diff --git a/test/Frontend/rewrite-includes-warnings.c b/test/Frontend/rewrite-includes-warnings.c index 1fb98db..c4f38ed 100644 --- a/test/Frontend/rewrite-includes-warnings.c +++ b/test/Frontend/rewrite-includes-warnings.c @@ -1,4 +1,9 @@ -// 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 +// PR14831 #pragma GCC visibility push (default) + +// PR15614 +#define FOO 1 +int foo = FOO; -- 1.8.4.5
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
