/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
- void EnterMainSourceFile();
+ bool EnterMainSourceFile();
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. Return true
// Lex through the entire file. This will populate SourceManager with
// all of the header information.
Token Tok;
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
do { PP.Lex(Tok); } while (Tok.isNot(tok::eof));
// Generate the PTH file.
Preprocessor &PP = getCompilerInstance().getPreprocessor();
// Start preprocessing the specified input file.
Token Tok;
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
do {
PP.Lex(Tok);
PP.DumpToken(Tok, true);
llvm::OwningPtr<Action> PA(new MinimalAction(PP));
Parser P(PP, *PA);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
P.ParseTranslationUnit();
}
Token Tok;
// Start parsing the specified input file.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
do {
PP.Lex(Tok);
} while (Tok.isNot(tok::eof));
llvm::OwningPtr<Action> PA(CreatePrintParserActionsAction(PP, OS));
Parser P(PP, *PA);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
P.ParseTranslationUnit();
}
static void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
// -dM mode just scans and ignores all tokens in the files, then dumps out
// the macro table at the end.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
Token Tok;
do PP.Lex(Tok);
PP.addPPCallbacks(Callbacks);
// After we have configured the preprocessor, enter the main file.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
// Consume all of the tokens that come from the predefines buffer. Those
// should not be emitted into the output and are guaranteed to be at the
// Get the first preprocessing token.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
Token PPTok;
PP.Lex(PPTok);
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
-void Preprocessor::EnterMainSourceFile() {
+bool Preprocessor::EnterMainSourceFile() {
// We do not allow the preprocessor to reenter the main file. Doing so will
// cause FileID's to accumulate information from both runs (e.g. #line
// information) and predefined macros aren't guaranteed to be set properly.
// Enter the main file source buffer.
std::string ErrorStr;
- bool Res = EnterSourceFile(MainFileID, 0, ErrorStr);
- assert(!Res && "Entering main file should not fail!");
+ if (EnterSourceFile(MainFileID, 0, ErrorStr))
+ return true;
// Tell the header info that the main file was entered. If the file is later
// #imported, it won't be re-entered.
assert(!FID.isInvalid() && "Could not create FileID for predefines?");
// Start parsing the predefines.
- Res = EnterSourceFile(FID, 0, ErrorStr);
- assert(!Res && "Entering predefines should not fail!");
+ return EnterSourceFile(FID, 0, ErrorStr);
}
Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer);
Parser P(PP, S);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
// Initialize the parser.
P.Initialize();
--- /dev/null
+// RUN: touch %t.c
+// RUN: not %clang -E %t.c -o %t.c 2> %t.stderr
+// RUN: grep "modified" %t.stderr