aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-18 18:52:28 +0000
committerChris Lattner <sabre@nondot.org>2007-11-18 18:52:28 +0000
commit2b1f1066aca0f6a3687377636a86086fa2cd222d (patch)
tree63117495794002fdbca55b298053fb06928e6866
parent4ce0df610879e82d9853c6a38a75b1883feaee06 (diff)
Fix the Linker testcase regressions, by making MemoryBuffer::getFileOrSTDIN return
a valid but empty buffer if stdin is empty. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44219 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/MemoryBuffer.h9
-rw-r--r--lib/Support/MemoryBuffer.cpp18
2 files changed, 21 insertions, 6 deletions
diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h
index aa13bfc65a..cfef6b1c6c 100644
--- a/include/llvm/Support/MemoryBuffer.h
+++ b/include/llvm/Support/MemoryBuffer.h
@@ -88,14 +88,11 @@ public:
/// 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
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index f8779e122d..2000377794 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -117,6 +117,24 @@ MemoryBuffer *MemoryBuffer::getNewMemBuffer(unsigned Size,
}
+/// 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.
//===----------------------------------------------------------------------===//