llvm.org GIT mirror llvm / 2b1f106
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 Chris Lattner 12 years ago
2 changed file(s) with 21 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
8787
8888 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
8989 /// if the Filename is "-". If an error occurs, this returns null and fills
90 /// in *ErrStr with a reason.
90 /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
91 /// returns an empty buffer.
9192 static MemoryBuffer *getFileOrSTDIN(const char *FilenameStart,unsigned FnSize,
9293 std::string *ErrStr = 0,
93 int64_t FileSize = -1) {
94 if (FnSize == 1 && FilenameStart[0] == '-')
95 return getSTDIN();
96 return getFile(FilenameStart, FnSize, ErrStr, FileSize);
97 }
94 int64_t FileSize = -1);
9895
9996 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
10097 /// if the Filename is "-". If an error occurs, this returns null and fills
115115 return SB;
116116 }
117117
118
119 /// getFileOrSTDIN - Open the specified file as a MemoryBuffer, or open stdin
120 /// if the Filename is "-". If an error occurs, this returns null and fills
121 /// in *ErrStr with a reason. If stdin is empty, this API (unlike getSTDIN)
122 /// returns an empty buffer.
123 MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *FilenameStart,
124 unsigned FnSize,
125 std::string *ErrStr,
126 int64_t FileSize) {
127 if (FnSize != 1 || FilenameStart[0] != '-')
128 return getFile(FilenameStart, FnSize, ErrStr, FileSize);
129 MemoryBuffer *M = getSTDIN();
130 if (M) return M;
131
132 // If stdin was empty, M is null. Cons up an empty memory buffer now.
133 const char *EmptyStr = "";
134 return MemoryBuffer::getMemBuffer(EmptyStr, EmptyStr, "");
135 }
118136
119137 //===----------------------------------------------------------------------===//
120138 // MemoryBufferMMapFile implementation.