r207758 - do not warn about unknown pragmas in modes that do not handle them (pr9537)
Lubos Lunak
l.lunak at centrum.cz
Thu May 1 05:54:03 PDT 2014
Author: llunak
Date: Thu May 1 07:54:03 2014
New Revision: 207758
URL: http://llvm.org/viewvc/llvm-project?rev=207758&view=rev
Log:
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.
Added:
cfe/trunk/test/Preprocessor/ignore-pragmas.c
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=207758&r1=207757&r2=207758&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu May 1 07:54:03 2014
@@ -667,6 +667,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);
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=207758&r1=207757&r2=207758&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu May 1 07:54:03 2014
@@ -592,7 +592,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.
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=207758&r1=207757&r2=207758&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Thu May 1 07:54:03 2014
@@ -671,7 +671,7 @@ static int MacroIDCompare(const id_macro
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.
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=207758&r1=207757&r2=207758&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Thu May 1 07:54:03 2014
@@ -1385,3 +1385,25 @@ void Preprocessor::RegisterBuiltinPragma
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());
+ // Also ignore all pragmas in all namespaces created
+ // in Preprocessor::RegisterBuiltinPragmas().
+ AddPragmaHandler("GCC", new EmptyPragmaHandler());
+ AddPragmaHandler("clang", new EmptyPragmaHandler());
+ if (PragmaHandler *NS = PragmaHandlers->FindHandler("STDC")) {
+ // Preprocessor::RegisterBuiltinPragmas() already registers
+ // PragmaSTDC_UnknownHandler as the empty handler, so remove it first,
+ // otherwise there will be an assert about a duplicate handler.
+ PragmaNamespace *STDCNamespace = NS->getIfNamespace();
+ assert(STDCNamespace &&
+ "Invalid namespace, registered as a regular pragma handler!");
+ if (PragmaHandler *Existing = STDCNamespace->FindHandler("", false)) {
+ RemovePragmaHandler("STDC", Existing);
+ }
+ }
+ AddPragmaHandler("STDC", new EmptyPragmaHandler());
+}
Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp?rev=207758&r1=207757&r2=207758&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Thu May 1 07:54:03 2014
@@ -515,13 +515,7 @@ void clang::RewriteIncludesInInput(Prepr
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.
Added: cfe/trunk/test/Preprocessor/ignore-pragmas.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/ignore-pragmas.c?rev=207758&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/ignore-pragmas.c (added)
+++ cfe/trunk/test/Preprocessor/ignore-pragmas.c Thu May 1 07:54:03 2014
@@ -0,0 +1,10 @@
+// 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
+#pragma this_pragma_does_not_exist
More information about the cfe-commits
mailing list