[llvm-commits] [llvm] r44219 - in /llvm/trunk: include/llvm/Support/MemoryBuffer.h lib/Support/MemoryBuffer.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 18 10:52:28 PST 2007
Author: lattner
Date: Sun Nov 18 12:52:28 2007
New Revision: 44219
URL: http://llvm.org/viewvc/llvm-project?rev=44219&view=rev
Log:
Fix the Linker testcase regressions, by making MemoryBuffer::getFileOrSTDIN return
a valid but empty buffer if stdin is empty.
Modified:
llvm/trunk/include/llvm/Support/MemoryBuffer.h
llvm/trunk/lib/Support/MemoryBuffer.cpp
Modified: llvm/trunk/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemoryBuffer.h?rev=44219&r1=44218&r2=44219&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/MemoryBuffer.h Sun Nov 18 12:52:28 2007
@@ -88,14 +88,11 @@
/// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
/// if the Filename is "-". If an error occurs, this returns null and fills
- /// in *ErrStr with a reason.
+ /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
+ /// returns an empty buffer.
static MemoryBuffer *getFileOrSTDIN(const char *FilenameStart,unsigned FnSize,
std::string *ErrStr = 0,
- int64_t FileSize = -1) {
- if (FnSize == 1 && FilenameStart[0] == '-')
- return getSTDIN();
- return getFile(FilenameStart, FnSize, ErrStr, FileSize);
- }
+ int64_t FileSize = -1);
/// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
/// if the Filename is "-". If an error occurs, this returns null and fills
Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=44219&r1=44218&r2=44219&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Sun Nov 18 12:52:28 2007
@@ -117,6 +117,24 @@
}
+/// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
+/// if the Filename is "-". If an error occurs, this returns null and fills
+/// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
+/// returns an empty buffer.
+MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *FilenameStart,
+ unsigned FnSize,
+ std::string *ErrStr,
+ int64_t FileSize) {
+ if (FnSize != 1 || FilenameStart[0] != '-')
+ return getFile(FilenameStart, FnSize, ErrStr, FileSize);
+ MemoryBuffer *M = getSTDIN();
+ if (M) return M;
+
+ // If stdin was empty, M is null. Cons up an empty memory buffer now.
+ const char *EmptyStr = "";
+ return MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "<stdin>");
+}
+
//===----------------------------------------------------------------------===//
// MemoryBufferMMapFile implementation.
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list