]> granicus.if.org Git - clang/commitdiff
Preprocessor: Ignore unknown pragmas in -E -dM and -Eonly modes.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 11 Jun 2010 20:10:12 +0000 (20:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 11 Jun 2010 20:10:12 +0000 (20:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105830 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Pragma.h
lib/Frontend/FrontendActions.cpp
lib/Frontend/PrintPreprocessedOutput.cpp
lib/Lex/Pragma.cpp
test/Frontend/unknown-pragmas.c [new file with mode: 0644]

index ef367feb84db963da6aecb6fdd27f7c94d852aea..52f01a9a97619362b92f3bc363bfda42f868efeb 100644 (file)
@@ -46,6 +46,15 @@ public:
   virtual PragmaNamespace *getIfNamespace() { return 0; }
 };
 
+/// EmptyPragmaHandler - A pragma handler which takes no action, which can be
+/// used to ignore particular pragmas.
+class EmptyPragmaHandler : public PragmaHandler {
+public:
+  EmptyPragmaHandler();
+
+  virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
+};
+
 /// PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas,
 /// allowing hierarchical pragmas to be defined.  Common examples of namespaces
 /// are "#pragma GCC", "#pragma STDC", and "#pragma omp", but any namespaces may
index 6cd960be20d50f2f53ee1fda7ee9645c16337987..421d69d24308159469e36490a4edd959fd6fa4b9 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Lex/Pragma.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Parse/Parser.h"
 #include "clang/Basic/FileManager.h"
@@ -223,6 +224,9 @@ void ParseOnlyAction::ExecuteAction() {
 void PreprocessOnlyAction::ExecuteAction() {
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
 
+  // Ignore unknown pragmas.
+  PP.AddPragmaHandler(0, new EmptyPragmaHandler());
+
   Token Tok;
   // Start parsing the specified input file.
   PP.EnterMainSourceFile();
index b6c18b77316cc6b74be5186800816796b55bd0de..e89c425f4709303b4b652b902d2136a71bc50c6c 100644 (file)
@@ -454,6 +454,9 @@ static int MacroIDCompare(const void* a, const void* b) {
 }
 
 static void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
+  // Ignore unknown pragmas.
+  PP.AddPragmaHandler(0, new EmptyPragmaHandler());
+
   // -dM mode just scans and ignores all tokens in the files, then dumps out
   // the macro table at the end.
   PP.EnterMainSourceFile();
index 92332a006861b580515b206499872572db88f4cc..58a632618fd31d843dcd8fdb251b5d6c0536adee 100644 (file)
@@ -26,6 +26,14 @@ using namespace clang;
 PragmaHandler::~PragmaHandler() {
 }
 
+//===----------------------------------------------------------------------===//
+// EmptyPragmaHandler Implementation.
+//===----------------------------------------------------------------------===//
+
+EmptyPragmaHandler::EmptyPragmaHandler() : PragmaHandler(0) {}
+
+void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, Token &FirstToken) {}
+
 //===----------------------------------------------------------------------===//
 // PragmaNamespace Implementation.
 //===----------------------------------------------------------------------===//
diff --git a/test/Frontend/unknown-pragmas.c b/test/Frontend/unknown-pragmas.c
new file mode 100644 (file)
index 0000000..53a5a45
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -Eonly -Wall -verify %s
+// RUN: %clang_cc1 -E -dM -Wall -verify %s
+
+#pragma adgohweopihweotnwet