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);
Preprocessor &PP = getCompilerInstance().getPreprocessor();
// Ignore unknown pragmas.
- PP.AddPragmaHandler(new EmptyPragmaHandler());
+ PP.IgnorePragmas();
Token Tok;
// Start parsing the specified input file.
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.
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());
+}
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.
--- /dev/null
+// 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