summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2015-04-29 14:53:25 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2015-04-29 14:53:25 +0000
commitc54a0d0bf444d159262771df250cd90a399bd9f6 (patch)
treec111952b8281b15ccec4e8bf802c324b6badbdfd
parenta951e210872adb18dbca7eb8b0832bd3a6fde416 (diff)
downloadbcm5719-llvm-c54a0d0bf444d159262771df250cd90a399bd9f6.tar.gz
bcm5719-llvm-c54a0d0bf444d159262771df250cd90a399bd9f6.zip
Relax assert to avoid spurious failures with /dev/null.
llvm-svn: 236106
-rw-r--r--llvm/include/llvm/Support/raw_ostream.h8
-rw-r--r--llvm/unittests/Support/raw_pwrite_stream_test.cpp29
2 files changed, 36 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index ed9c8b09ba4..b59317112c4 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -323,7 +323,13 @@ public:
explicit raw_pwrite_stream(bool Unbuffered = false)
: raw_ostream(Unbuffered) {}
void pwrite(const char *Ptr, size_t Size, uint64_t Offset) {
- assert(Size + Offset <= tell() && "We don't support extending the stream");
+#ifndef NDBEBUG
+ uint64_t Pos = tell();
+ // /dev/null always reports a pos of 0, so we cannot perform this check
+ // in that case.
+ if (Pos)
+ assert(Size + Offset <= Pos && "We don't support extending the stream");
+#endif
pwrite_impl(Ptr, Size, Offset);
}
};
diff --git a/llvm/unittests/Support/raw_pwrite_stream_test.cpp b/llvm/unittests/Support/raw_pwrite_stream_test.cpp
index 2792f44b605..4e521a04728 100644
--- a/llvm/unittests/Support/raw_pwrite_stream_test.cpp
+++ b/llvm/unittests/Support/raw_pwrite_stream_test.cpp
@@ -9,6 +9,7 @@
#include "gtest/gtest.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -30,4 +31,32 @@ TEST(raw_pwrite_ostreamTest, TestSVector) {
#endif
#endif
}
+
+TEST(raw_pwrite_ostreamTest, TestFD) {
+ SmallString<64> Path;
+ int FD;
+ sys::fs::createTemporaryFile("foo", "bar", FD, Path);
+ raw_fd_ostream OS(FD, true);
+ OS << "abcd";
+ StringRef Test = "test";
+ OS.pwrite(Test.data(), Test.size(), 0);
+ OS.pwrite(Test.data(), Test.size(), 0);
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+ EXPECT_DEATH(OS.pwrite("12345", 5, 0),
+ "We don't support extending the stream");
+#endif
+#endif
+}
+
+TEST(raw_pwrite_ostreamTest, TestDevNull) {
+ int FD;
+ sys::fs::openFileForWrite("/dev/null", FD, sys::fs::F_None);
+ raw_fd_ostream OS(FD, true);
+ OS << "abcd";
+ StringRef Test = "test";
+ OS.pwrite(Test.data(), Test.size(), 0);
+ OS.pwrite(Test.data(), Test.size(), 0);
+}
}
OpenPOWER on IntegriCloud