Skip to content

Commit

Permalink
Revert "MemoryBuffer: Add a missing error-check to getOpenFileImpl"
Browse files Browse the repository at this point in the history
This reverts commit r368977 because it broke a couple of tests in lldb.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369027 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
labath committed Aug 15, 2019
1 parent 5a682e0 commit 9ecd610
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
4 changes: 1 addition & 3 deletions lib/Support/MemoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,7 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
return make_error_code(errc::not_enough_memory);
}

if (std::error_code EC =
sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset))
return EC;
sys::fs::readNativeFileSlice(FD, Buf->getBuffer(), Offset);

return std::move(Buf);
}
Expand Down
51 changes: 0 additions & 51 deletions unittests/Support/MemoryBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

#include "llvm/Support/MemoryBuffer.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -20,25 +19,6 @@

using namespace llvm;

#define ASSERT_NO_ERROR(x) \
if (std::error_code ASSERT_NO_ERROR_ec = x) { \
SmallString<128> MessageStorage; \
raw_svector_ostream Message(MessageStorage); \
Message << #x ": did not return errc::success.\n" \
<< "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \
<< "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \
GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
} else { \
}

#define ASSERT_ERROR(x) \
if (!x) { \
SmallString<128> MessageStorage; \
raw_svector_ostream Message(MessageStorage); \
Message << #x ": did not return a failure error code.\n"; \
GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \
}

namespace {

class MemoryBufferTest : public testing::Test {
Expand Down Expand Up @@ -85,37 +65,6 @@ TEST_F(MemoryBufferTest, get) {
EXPECT_EQ("this is some data", data);
}

TEST_F(MemoryBufferTest, getOpenFile) {
int FD;
SmallString<64> TestPath;
ASSERT_EQ(sys::fs::createTemporaryFile("MemoryBufferTest_getOpenFile", "temp",
FD, TestPath),
std::error_code());

FileRemover Cleanup(TestPath);
raw_fd_ostream OF(FD, /*shouldClose*/ true);
OF << "12345678";
OF.close();

{
Expected<sys::fs::file_t> File = sys::fs::openNativeFileForRead(TestPath);
ASSERT_THAT_EXPECTED(File, Succeeded());
auto OnExit =
make_scope_exit([&] { ASSERT_NO_ERROR(sys::fs::closeFile(*File)); });
ErrorOr<OwningBuffer> MB = MemoryBuffer::getOpenFile(*File, TestPath, 6);
ASSERT_NO_ERROR(MB.getError());
EXPECT_EQ("123456", MB.get()->getBuffer());
}
{
Expected<sys::fs::file_t> File = sys::fs::openNativeFileForWrite(
TestPath, sys::fs::CD_OpenExisting, sys::fs::OF_None);
ASSERT_THAT_EXPECTED(File, Succeeded());
auto OnExit =
make_scope_exit([&] { ASSERT_NO_ERROR(sys::fs::closeFile(*File)); });
ASSERT_ERROR(MemoryBuffer::getOpenFile(*File, TestPath, 6).getError());
}
}

TEST_F(MemoryBufferTest, NullTerminator4K) {
// Test that a file with size that is a multiple of the page size can be null
// terminated correctly by MemoryBuffer.
Expand Down

0 comments on commit 9ecd610

Please sign in to comment.