Skip to content
Snippets Groups Projects
Commit d839e77b authored by Daniel Dunbar's avatar Daniel Dunbar
Browse files

Preprocessor: Ignore unknown pragmas in -E -dM and -Eonly modes.

llvm-svn: 105830
parent afe54f16
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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();
......
......@@ -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();
......
......@@ -26,6 +26,14 @@ using namespace clang;
PragmaHandler::~PragmaHandler() {
}
//===----------------------------------------------------------------------===//
// EmptyPragmaHandler Implementation.
//===----------------------------------------------------------------------===//
EmptyPragmaHandler::EmptyPragmaHandler() : PragmaHandler(0) {}
void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, Token &FirstToken) {}
//===----------------------------------------------------------------------===//
// PragmaNamespace Implementation.
//===----------------------------------------------------------------------===//
......
// RUN: %clang_cc1 -Eonly -Wall -verify %s
// RUN: %clang_cc1 -E -dM -Wall -verify %s
#pragma adgohweopihweotnwet
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment