]> granicus.if.org Git - clang/commitdiff
avoid bogus warnings about "unknown" pragmas with -frewrite-includes (pr#14831)
authorLubos Lunak <l.lunak@suse.cz>
Sat, 20 Jul 2013 14:30:01 +0000 (14:30 +0000)
committerLubos Lunak <l.lunak@suse.cz>
Sat, 20 Jul 2013 14:30:01 +0000 (14:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186764 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/Frontend/InclusionRewriter.cpp
test/Frontend/rewrite-includes-warnings.c [new file with mode: 0644]

index 0c3269a0472495956184a9cae23a291bb6b61414..93ad9b88d609d6c9fb64c9325aed2575232fd1c0 100644 (file)
@@ -16,6 +16,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/PreprocessorOutputOptions.h"
 #include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/Pragma.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
@@ -503,6 +504,13 @@ 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());
 
   // First let the preprocessor process the entire file and call callbacks.
   // Callbacks will record which #include's were actually performed.
diff --git a/test/Frontend/rewrite-includes-warnings.c b/test/Frontend/rewrite-includes-warnings.c
new file mode 100644 (file)
index 0000000..1fb98db
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -verify -Wall -Wextra -E -frewrite-includes %s
+// expected-no-diagnostics
+
+#pragma GCC visibility push (default)