[cfe-commits] r105830 - in /cfe/trunk: include/clang/Lex/Pragma.h lib/Frontend/FrontendActions.cpp lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/Pragma.cpp test/Frontend/unknown-pragmas.c

Daniel Dunbar daniel at zuster.org
Fri Jun 11 13:10:13 PDT 2010


Author: ddunbar
Date: Fri Jun 11 15:10:12 2010
New Revision: 105830

URL: http://llvm.org/viewvc/llvm-project?rev=105830&view=rev
Log:
Preprocessor: Ignore unknown pragmas in -E -dM and -Eonly modes.

Added:
    cfe/trunk/test/Frontend/unknown-pragmas.c
Modified:
    cfe/trunk/include/clang/Lex/Pragma.h
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/lib/Lex/Pragma.cpp

Modified: cfe/trunk/include/clang/Lex/Pragma.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Pragma.h?rev=105830&r1=105829&r2=105830&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Pragma.h (original)
+++ cfe/trunk/include/clang/Lex/Pragma.h Fri Jun 11 15:10:12 2010
@@ -46,6 +46,15 @@
   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

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=105830&r1=105829&r2=105830&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Jun 11 15:10:12 2010
@@ -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 PreprocessOnlyAction::ExecuteAction() {
   Preprocessor &PP = getCompilerInstance().getPreprocessor();
 
+  // Ignore unknown pragmas.
+  PP.AddPragmaHandler(0, new EmptyPragmaHandler());
+
   Token Tok;
   // Start parsing the specified input file.
   PP.EnterMainSourceFile();

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=105830&r1=105829&r2=105830&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Fri Jun 11 15:10:12 2010
@@ -454,6 +454,9 @@
 }
 
 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();

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=105830&r1=105829&r2=105830&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Jun 11 15:10:12 2010
@@ -27,6 +27,14 @@
 }
 
 //===----------------------------------------------------------------------===//
+// EmptyPragmaHandler Implementation.
+//===----------------------------------------------------------------------===//
+
+EmptyPragmaHandler::EmptyPragmaHandler() : PragmaHandler(0) {}
+
+void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, Token &FirstToken) {}
+
+//===----------------------------------------------------------------------===//
 // PragmaNamespace Implementation.
 //===----------------------------------------------------------------------===//
 

Added: cfe/trunk/test/Frontend/unknown-pragmas.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/unknown-pragmas.c?rev=105830&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/unknown-pragmas.c (added)
+++ cfe/trunk/test/Frontend/unknown-pragmas.c Fri Jun 11 15:10:12 2010
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -Eonly -Wall -verify %s
+// RUN: %clang_cc1 -E -dM -Wall -verify %s
+
+#pragma adgohweopihweotnwet





More information about the cfe-commits mailing list