Hello, the attached patch should fix PR9537. It is apparently necessary to install empty pragma handlers for all pragma namespaces that exist.
-- Lubos Lunak
From dd030f1f50e8005be6f7e01ee55ce12b1822ee1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <[email protected]> Date: Wed, 27 Nov 2013 23:42:16 +0100 Subject: [PATCH] do not warn about unknown pragmas in modes that do not handle them (pr9537) And refactor to have just one place in code that sets up the empty pragma handlers. --- include/clang/Lex/Preprocessor.h | 3 +++ lib/Frontend/FrontendActions.cpp | 2 +- lib/Frontend/PrintPreprocessedOutput.cpp | 2 +- lib/Lex/Pragma.cpp | 11 +++++++++++ lib/Rewrite/Frontend/InclusionRewriter.cpp | 8 +------- test/Preprocessor/ignore-pragmas.c | 9 +++++++++ 6 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 test/Preprocessor/ignore-pragmas.c diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 2491011..6822424 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -643,6 +643,9 @@ public: RemovePragmaHandler(StringRef(), Handler); } + /// Install empty handlers for all pragmas (making them ignored). + void IgnorePragmas(); + /// \brief Add the specified comment handler to the preprocessor. void addCommentHandler(CommentHandler *Handler); diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index a3ab1be..88044f2 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -485,7 +485,7 @@ void PreprocessOnlyAction::ExecuteAction() { Preprocessor &PP = getCompilerInstance().getPreprocessor(); // Ignore unknown pragmas. - PP.AddPragmaHandler(new EmptyPragmaHandler()); + PP.IgnorePragmas(); Token Tok; // Start parsing the specified input file. diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index f3393bf..87fbd04 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -704,7 +704,7 @@ static int MacroIDCompare(const id_macro_pair *LHS, const id_macro_pair *RHS) { static void DoPrintMacros(Preprocessor &PP, raw_ostream *OS) { // Ignore unknown pragmas. - PP.AddPragmaHandler(new EmptyPragmaHandler()); + PP.IgnorePragmas(); // -dM mode just scans and ignores all tokens in the files, then dumps out // the macro table at the end. diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index e4059ee..5073a6d 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -1401,3 +1401,14 @@ void Preprocessor::RegisterBuiltinPragmas() { AddPragmaHandler(new PragmaRegionHandler("endregion")); } } + +/// Ignore all pragmas, useful for modes such as -Eonly which would otherwise +/// warn about those pragmas being unknown. +void Preprocessor::IgnorePragmas() { + AddPragmaHandler(new EmptyPragmaHandler()); + // Ignore also all pragma in all namespaces created + // in Preprocessor::RegisterBuiltinPragmas(). + AddPragmaHandler("GCC", new EmptyPragmaHandler()); + AddPragmaHandler("clang", new EmptyPragmaHandler()); + AddPragmaHandler("STDC", new EmptyPragmaHandler()); +} diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp index bd4250a..509e76c 100644 --- a/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -517,13 +517,7 @@ void clang::RewriteIncludesInInput(Preprocessor &PP, raw_ostream *OS, InclusionRewriter *Rewrite = new InclusionRewriter(PP, *OS, Opts.ShowLineMarkers); PP.addPPCallbacks(Rewrite); - // Ignore all pragmas, otherwise there will be warnings about unknown pragmas - // (because there's nothing to handle them). - PP.AddPragmaHandler(new EmptyPragmaHandler()); - // Ignore also all pragma in all namespaces created - // in Preprocessor::RegisterBuiltinPragmas(). - PP.AddPragmaHandler("GCC", new EmptyPragmaHandler()); - PP.AddPragmaHandler("clang", new EmptyPragmaHandler()); + PP.IgnorePragmas(); // First let the preprocessor process the entire file and call callbacks. // Callbacks will record which #include's were actually performed. diff --git a/test/Preprocessor/ignore-pragmas.c b/test/Preprocessor/ignore-pragmas.c new file mode 100644 index 0000000..58d51b7 --- /dev/null +++ b/test/Preprocessor/ignore-pragmas.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -E %s -Wall -verify +// RUN: %clang_cc1 -Eonly %s -Wall -verify +// RUN: %clang -M -Wall %s -Xclang -verify +// RUN: %clang -E -frewrite-includes %s -Wall -Xclang -verify +// RUN: %clang -E -dD -dM %s -Wall -Xclang -verify +// expected-no-diagnostics + +#pragma GCC visibility push (default) +#pragma weak -- 1.8.1.4
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
