diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-01 22:52:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-01 22:52:33 +0000 |
commit | 39d9841ed4c0568d4b44dfbc12ac04491f60a374 (patch) | |
tree | 8e85395573cf9e3854b100995521f7195fe2d0f2 /lib | |
parent | 2b56b9cf7429919e1df011d8d6bee2e04f5bc22c (diff) |
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"
^
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90276 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 4 | ||||
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 5 | ||||
-rw-r--r-- | lib/Lex/PPLexerChange.cpp | 6 |
3 files changed, 9 insertions, 6 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index a85bef0f29..394f493fa9 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -47,12 +47,12 @@ unsigned ContentCache::getSize() const { return Buffer ? Buffer->getBufferSize() : Entry->getSize(); } -const llvm::MemoryBuffer *ContentCache::getBuffer() const { +const llvm::MemoryBuffer *ContentCache::getBuffer(std::string *ErrorStr) const { // Lazily create the Buffer for ContentCaches that wrap files. if (!Buffer && Entry) { // FIXME: Should we support a way to not have to do this check over // and over if we cannot open the file? - Buffer = MemoryBuffer::getFile(Entry->getName(), 0, Entry->getSize()); + Buffer = MemoryBuffer::getFile(Entry->getName(), ErrorStr,Entry->getSize()); if (isTruncated()) const_cast<ContentCache *>(this)->truncateAt(TruncateAtLine, TruncateAtColumn); diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 9caca339be..028593f39c 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/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/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 8a61d7b9c2..1580b87dac 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/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; |