From 2ffb14f004affc363d86d6c7c63c356190db3679 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 6 Dec 2009 09:19:25 +0000 Subject: [PATCH] Unbreak and add test case for r90276, a situation in which getBuffer is expected to fail. Also, update SourceManager.h doxyments for getBuffer() to reflect reality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90701 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/SourceManager.h | 11 +++++------ lib/Lex/PPLexerChange.cpp | 2 +- test/Preprocessor/open-failure.c | 11 +++++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 test/Preprocessor/open-failure.c diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 3b170a6a74..b4cf959dc5 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -70,8 +70,8 @@ namespace SrcMgr { unsigned NumLines; /// getBuffer - Returns the memory buffer for the associated content. If - /// there is an error opening this buffer the first time, this returns null - /// and fills in the ErrorStr with a reason. + /// there is an error opening this buffer the first time, this manufactures + /// a temporary buffer and returns a non-empty error string. const llvm::MemoryBuffer *getBuffer(std::string *ErrorStr = 0) const; /// getSize - Returns the size of the content encapsulated by this @@ -426,10 +426,9 @@ public: // FileID manipulation methods. //===--------------------------------------------------------------------===// - /// getBuffer - Return the buffer for the specified FileID. If there is an - /// error opening this buffer the first time, this returns null and fills in - /// the ErrorStr with a reason. - /// + /// getBuffer - Return the buffer for the specified FileID. If there is an + /// error opening this buffer the first time, this manufactures a temporary + /// buffer and returns a non-empty error string. const llvm::MemoryBuffer *getBuffer(FileID FID, std::string *Error = 0) const{ return getSLocEntry(FID).getFile().getContentCache()->getBuffer(Error); } diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 5cdfeafa33..ce1b19ca7c 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -81,8 +81,8 @@ bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir, // Get the MemoryBuffer for this FID, if it fails, we fail. const llvm::MemoryBuffer *InputFile = - if (InputFile == 0) getSourceManager().getBuffer(FID, &ErrorStr); + if (!ErrorStr.empty()) return true; EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir); diff --git a/test/Preprocessor/open-failure.c b/test/Preprocessor/open-failure.c new file mode 100644 index 0000000000..667b822168 --- /dev/null +++ b/test/Preprocessor/open-failure.c @@ -0,0 +1,11 @@ +// RUN: rm -rf %t.dir +// RUN: mkdir %t.dir +// RUN: echo 'void f0();' > %t.dir/t.h +// RUN: chmod 000 %t.dir/t.h +// RUN: clang-cc -verify -I %t.dir %s + +// FIXME: Is there a way to test this on Windows? +// XFAIL: win32 + +#include "t.h" // expected-error {{Permission denied}} +int f0(void); -- 2.40.0