summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-01 22:52:33 +0000
committerChris Lattner <sabre@nondot.org>2009-12-01 22:52:33 +0000
commited3b360290c4652c8e96bc6869354c73975afe05 (patch)
tree36f2fb40876c17613aee57705d28cc992ec13ced /clang/lib/Lex
parent0e3b78a6c21b27eb1d73351a6d856778b57de54b (diff)
downloadbcm5719-llvm-ed3b360290c4652c8e96bc6869354c73975afe05.tar.gz
bcm5719-llvm-ed3b360290c4652c8e96bc6869354c73975afe05.zip
pass the reason for failure up from MemoryBuffer and report it
in diagnostics when we fail to open a file. This allows us to report things like: $ clang test.c -I. test.c:2:10: fatal error: error opening file './foo.h': Permission denied #include "foo.h" ^ llvm-svn: 90276
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp5
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp6
2 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 9caca339be3..028593f39c7 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1112,9 +1112,10 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
}
// Finally, if all is good, enter the new file!
- if (EnterSourceFile(FID, CurDir))
+ std::string ErrorStr;
+ if (EnterSourceFile(FID, CurDir, &ErrorStr))
Diag(FilenameTok, diag::err_pp_error_opening_file)
- << std::string(SourceMgr.getFileEntryForID(FID)->getName());
+ << std::string(SourceMgr.getFileEntryForID(FID)->getName()) << ErrorStr;
}
/// HandleIncludeNextDirective - Implements #include_next.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 8a61d7b9c24..1580b87dac6 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -64,7 +64,8 @@ PreprocessorLexer *Preprocessor::getCurrentFileLexer() const {
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer.
-bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir) {
+bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
+ std::string *ErrorStr) {
assert(CurTokenLexer == 0 && "Cannot #include a file inside a macro!");
++NumEnteredSourceFiles;
@@ -79,7 +80,8 @@ bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir) {
}
// Get the MemoryBuffer for this FID, if it fails, we fail.
- const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID);
+ const llvm::MemoryBuffer *InputFile =
+ getSourceManager().getBuffer(FID, ErrorStr);
if (InputFile == 0)
return true;
OpenPOWER on IntegriCloud