[cfe-commits] r98727 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Frontend/CacheTokens.cpp lib/Frontend/FrontendActions.cpp lib/Frontend/PrintPreprocessedOutput.cpp lib/Frontend/RewriteMacros.cpp lib/Lex/Preprocessor.cpp lib/Sema/ParseAST.cpp test/Misc/changed-files.c
Douglas Gregor
dgregor at apple.com
Wed Mar 17 08:44:30 PDT 2010
Author: dgregor
Date: Wed Mar 17 10:44:30 2010
New Revision: 98727
URL: http://llvm.org/viewvc/llvm-project?rev=98727&view=rev
Log:
Entering the main source file in the preprocessor can fail if the
source file has been changed. Handle that failure more gracefully.
Added:
cfe/trunk/test/Misc/changed-files.c (with props)
Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
cfe/trunk/lib/Frontend/RewriteMacros.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Sema/ParseAST.cpp
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Mar 17 10:44:30 2010
@@ -350,7 +350,7 @@
/// 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
Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Wed Mar 17 10:44:30 2010
@@ -549,7 +549,8 @@
// 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.
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Wed Mar 17 10:44:30 2010
@@ -185,7 +185,8 @@
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);
@@ -213,7 +214,8 @@
llvm::OwningPtr<Action> PA(new MinimalAction(PP));
Parser P(PP, *PA);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
P.ParseTranslationUnit();
}
@@ -222,7 +224,8 @@
Token Tok;
// Start parsing the specified input file.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
do {
PP.Lex(Tok);
} while (Tok.isNot(tok::eof));
@@ -237,7 +240,8 @@
llvm::OwningPtr<Action> PA(CreatePrintParserActionsAction(PP, OS));
Parser P(PP, *PA);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
P.ParseTranslationUnit();
}
Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Mar 17 10:44:30 2010
@@ -448,7 +448,8 @@
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);
@@ -495,7 +496,8 @@
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
Modified: cfe/trunk/lib/Frontend/RewriteMacros.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteMacros.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteMacros.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteMacros.cpp Wed Mar 17 10:44:30 2010
@@ -101,7 +101,8 @@
// Get the first preprocessing token.
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
Token PPTok;
PP.Lex(PPTok);
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Mar 17 10:44:30 2010
@@ -488,7 +488,7 @@
/// 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.
@@ -497,8 +497,8 @@
// 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.
@@ -515,8 +515,7 @@
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);
}
Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=98727&r1=98726&r2=98727&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Wed Mar 17 10:44:30 2010
@@ -44,7 +44,8 @@
Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer);
Parser P(PP, S);
- PP.EnterMainSourceFile();
+ if (PP.EnterMainSourceFile())
+ return;
// Initialize the parser.
P.Initialize();
Added: cfe/trunk/test/Misc/changed-files.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/changed-files.c?rev=98727&view=auto
==============================================================================
--- cfe/trunk/test/Misc/changed-files.c (added)
+++ cfe/trunk/test/Misc/changed-files.c Wed Mar 17 10:44:30 2010
@@ -0,0 +1,3 @@
+// RUN: touch %t.c
+// RUN: not %clang -E %t.c -o %t.c 2> %t.stderr
+// RUN: grep "modified" %t.stderr
Propchange: cfe/trunk/test/Misc/changed-files.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Misc/changed-files.c
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Misc/changed-files.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list