James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sun, 8 May 2022 19:16:51 -0400 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 4 | Subject: [PATCH 21/31] Remove unused functions |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 5 | |
| 6 | --- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 7 | llvm/include/llvm/Support/raw_ostream.h | 5 +- |
| 8 | llvm/lib/Support/ErrorHandling.cpp | 16 ----- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 9 | llvm/lib/Support/raw_ostream.cpp | 47 +++++++------- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 10 | llvm/unittests/ADT/SmallStringTest.cpp | 81 ------------------------- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 11 | 4 files changed, 23 insertions(+), 126 deletions(-) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 12 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 13 | diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 14 | index d56999186f719f8d91f3a047a19960caf62a066c..9a9a1f688313a5784a58a70f2cb4cc0d6ec70e79 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 15 | --- a/llvm/include/llvm/Support/raw_ostream.h |
| 16 | +++ b/llvm/include/llvm/Support/raw_ostream.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 17 | @@ -70,7 +70,6 @@ private: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 18 | /// for a \see write_impl() call to handle the data which has been put into |
| 19 | /// this buffer. |
| 20 | char *OutBufStart, *OutBufEnd, *OutBufCur; |
| 21 | - bool ColorEnabled = false; |
| 22 | |
| 23 | /// Optional stream this stream is tied to. If this stream is written to, the |
| 24 | /// tied-to stream will be flushed first. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 25 | @@ -317,9 +316,9 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 26 | |
| 27 | // Enable or disable colors. Once enable_colors(false) is called, |
| 28 | // changeColor() has no effect until enable_colors(true) is called. |
| 29 | - virtual void enable_colors(bool enable) { ColorEnabled = enable; } |
| 30 | + virtual void enable_colors(bool /*enable*/) {} |
| 31 | |
| 32 | - bool colors_enabled() const { return ColorEnabled; } |
| 33 | + bool colors_enabled() const { return false; } |
| 34 | |
| 35 | /// Tie this stream to the specified stream. Replaces any existing tied-to |
| 36 | /// stream. Specifying a nullptr unties the stream. |
| 37 | diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 38 | index 54137a331ca9e752b02c0f16ae996094a6f2fafa..e253d6f7a5ca3aee75823efdb9717dcd93fff5dc 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 39 | --- a/llvm/lib/Support/ErrorHandling.cpp |
| 40 | +++ b/llvm/lib/Support/ErrorHandling.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 41 | @@ -181,22 +181,6 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 42 | #endif |
| 43 | } |
| 44 | |
| 45 | -static void bindingsErrorHandler(void *user_data, const char *reason, |
| 46 | - bool gen_crash_diag) { |
| 47 | - LLVMFatalErrorHandler handler = |
| 48 | - LLVM_EXTENSION reinterpret_cast<LLVMFatalErrorHandler>(user_data); |
| 49 | - handler(reason); |
| 50 | -} |
| 51 | - |
| 52 | -void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler) { |
| 53 | - install_fatal_error_handler(bindingsErrorHandler, |
| 54 | - LLVM_EXTENSION reinterpret_cast<void *>(Handler)); |
| 55 | -} |
| 56 | - |
| 57 | -void LLVMResetFatalErrorHandler() { |
| 58 | - remove_fatal_error_handler(); |
| 59 | -} |
| 60 | - |
| 61 | #ifdef _WIN32 |
| 62 | |
| 63 | #include <winerror.h> |
| 64 | diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 65 | index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d78b6a5b02 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 66 | --- a/llvm/lib/Support/raw_ostream.cpp |
| 67 | +++ b/llvm/lib/Support/raw_ostream.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 68 | @@ -175,16 +175,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | -raw_ostream &raw_ostream::operator<<(const void *P) { |
| 73 | - llvm::write_hex(*this, (uintptr_t)P, HexPrintStyle::PrefixLower); |
| 74 | - return *this; |
| 75 | -} |
| 76 | - |
| 77 | -raw_ostream &raw_ostream::operator<<(double N) { |
| 78 | - llvm::write_double(*this, N, FloatStyle::Exponent); |
| 79 | - return *this; |
| 80 | -} |
| 81 | - |
| 82 | void raw_ostream::flush_nonempty() { |
| 83 | assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); |
| 84 | size_t Length = OutBufCur - OutBufStart; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 85 | @@ -327,15 +317,22 @@ static int getFD(std::string_view Filename, std::error_code &EC, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 86 | if (Filename == "-") { |
| 87 | EC = std::error_code(); |
| 88 | // Change stdout's text/binary mode based on the Flags. |
| 89 | - sys::ChangeStdoutMode(Flags); |
| 90 | + if (!(Flags & fs::OF_Text)) { |
| 91 | +#if defined(_WIN32) |
| 92 | + _setmode(_fileno(stdout), _O_BINARY); |
| 93 | +#endif |
| 94 | + } |
| 95 | return STDOUT_FILENO; |
| 96 | } |
| 97 | |
| 98 | - int FD; |
| 99 | - if (Access & sys::fs::FA_Read) |
| 100 | - EC = sys::fs::openFileForReadWrite(Filename, FD, Disp, Flags); |
| 101 | + fs::file_t F; |
| 102 | + if (Access & fs::FA_Read) |
| 103 | + F = fs::OpenFileForReadWrite(fs::path{std::string_view{Filename.data(), Filename.size()}}, EC, Disp, Flags); |
| 104 | else |
| 105 | - EC = sys::fs::openFileForWrite(Filename, FD, Disp, Flags); |
| 106 | + F = fs::OpenFileForWrite(fs::path{std::string_view{Filename.data(), Filename.size()}}, EC, Disp, Flags); |
| 107 | + if (EC) |
| 108 | + return -1; |
| 109 | + int FD = fs::FileToFd(F, EC, Flags); |
| 110 | if (EC) |
| 111 | return -1; |
| 112 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 113 | @@ -395,12 +392,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 114 | |
| 115 | // Get the starting position. |
| 116 | off_t loc = ::lseek(FD, 0, SEEK_CUR); |
| 117 | - sys::fs::file_status Status; |
| 118 | - std::error_code EC = status(FD, Status); |
| 119 | - IsRegularFile = Status.type() == sys::fs::file_type::regular_file; |
| 120 | #ifdef _WIN32 |
| 121 | - // MSVCRT's _lseek(SEEK_CUR) doesn't return -1 for pipes. |
| 122 | - SupportsSeeking = !EC && IsRegularFile; |
| 123 | + SupportsSeeking = loc != (off_t)-1 && ::GetFileType(reinterpret_cast<HANDLE>(::_get_osfhandle(FD))) != FILE_TYPE_PIPE; |
| 124 | #else |
| 125 | SupportsSeeking = !EC && loc != (off_t)-1; |
| 126 | #endif |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 127 | @@ -413,10 +406,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 128 | raw_fd_ostream::~raw_fd_ostream() { |
| 129 | if (FD >= 0) { |
| 130 | flush(); |
| 131 | - if (ShouldClose) { |
| 132 | - if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD)) |
| 133 | - error_detected(EC); |
| 134 | - } |
| 135 | + if (ShouldClose && ::close(FD) < 0) |
| 136 | + error_detected(std::error_code(errno, std::generic_category())); |
| 137 | } |
| 138 | |
| 139 | #ifdef __MINGW32__ |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 140 | @@ -511,7 +502,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 141 | |
| 142 | do { |
| 143 | size_t ChunkSize = std::min(Size, MaxWriteSize); |
| 144 | +#ifdef _WIN32 |
| 145 | + int ret = ::_write(FD, Ptr, ChunkSize); |
| 146 | +#else |
| 147 | ssize_t ret = ::write(FD, Ptr, ChunkSize); |
| 148 | +#endif |
| 149 | |
| 150 | if (ret < 0) { |
| 151 | // If it's a recoverable error, swallow it and retry the write. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 152 | @@ -554,8 +549,8 @@ void raw_fd_ostream::close() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 153 | assert(ShouldClose); |
| 154 | ShouldClose = false; |
| 155 | flush(); |
| 156 | - if (auto EC = sys::Process::SafelyCloseFileDescriptor(FD)) |
| 157 | - error_detected(EC); |
| 158 | + if (::close(FD) < 0) |
| 159 | + error_detected(std::error_code(errno, std::generic_category())); |
| 160 | FD = -1; |
| 161 | } |
| 162 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 163 | diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 164 | index 6cf14700b34739420cd3dc4ff8a4c16ce162f715..87600ea4704bc98acab9085d16cfafd3d586714e 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 165 | --- a/llvm/unittests/ADT/SmallStringTest.cpp |
| 166 | +++ b/llvm/unittests/ADT/SmallStringTest.cpp |
| 167 | @@ -129,23 +129,6 @@ TEST_F(SmallStringTest, StdStringConversion) { |
| 168 | EXPECT_EQ("abc", theStdString); |
| 169 | } |
| 170 | |
| 171 | -TEST_F(SmallStringTest, Substr) { |
| 172 | - theString = "hello"; |
| 173 | - EXPECT_EQ("lo", theString.substr(3)); |
| 174 | - EXPECT_EQ("", theString.substr(100)); |
| 175 | - EXPECT_EQ("hello", theString.substr(0, 100)); |
| 176 | - EXPECT_EQ("o", theString.substr(4, 10)); |
| 177 | -} |
| 178 | - |
| 179 | -TEST_F(SmallStringTest, Slice) { |
| 180 | - theString = "hello"; |
| 181 | - EXPECT_EQ("l", theString.slice(2, 3)); |
| 182 | - EXPECT_EQ("ell", theString.slice(1, 4)); |
| 183 | - EXPECT_EQ("llo", theString.slice(2, 100)); |
| 184 | - EXPECT_EQ("", theString.slice(2, 1)); |
| 185 | - EXPECT_EQ("", theString.slice(10, 20)); |
| 186 | -} |
| 187 | - |
| 188 | TEST_F(SmallStringTest, Find) { |
| 189 | theString = "hello"; |
| 190 | EXPECT_EQ(2U, theString.find('l')); |
| 191 | @@ -180,68 +163,4 @@ TEST_F(SmallStringTest, Find) { |
| 192 | EXPECT_EQ(0U, theString.find("")); |
| 193 | } |
| 194 | |
| 195 | -TEST_F(SmallStringTest, Count) { |
| 196 | - theString = "hello"; |
| 197 | - EXPECT_EQ(2U, theString.count('l')); |
| 198 | - EXPECT_EQ(1U, theString.count('o')); |
| 199 | - EXPECT_EQ(0U, theString.count('z')); |
| 200 | - EXPECT_EQ(0U, theString.count("helloworld")); |
| 201 | - EXPECT_EQ(1U, theString.count("hello")); |
| 202 | - EXPECT_EQ(1U, theString.count("ello")); |
| 203 | - EXPECT_EQ(0U, theString.count("zz")); |
| 204 | -} |
| 205 | - |
| 206 | -TEST_F(SmallStringTest, Realloc) { |
| 207 | - theString = "abcd"; |
| 208 | - theString.reserve(100); |
| 209 | - EXPECT_EQ("abcd", theString); |
| 210 | - unsigned const N = 100000; |
| 211 | - theString.reserve(N); |
| 212 | - for (unsigned i = 0; i < N - 4; ++i) |
| 213 | - theString.push_back('y'); |
| 214 | - EXPECT_EQ("abcdyyy", theString.slice(0, 7)); |
| 215 | -} |
| 216 | - |
| 217 | -TEST_F(SmallStringTest, Comparisons) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 218 | - EXPECT_GT( 0, SmallString<10>("aab").compare("aad")); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 219 | - EXPECT_EQ( 0, SmallString<10>("aab").compare("aab")); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 220 | - EXPECT_LT( 0, SmallString<10>("aab").compare("aaa")); |
| 221 | - EXPECT_GT( 0, SmallString<10>("aab").compare("aabb")); |
| 222 | - EXPECT_LT( 0, SmallString<10>("aab").compare("aa")); |
| 223 | - EXPECT_LT( 0, SmallString<10>("\xFF").compare("\1")); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 224 | - |
| 225 | - EXPECT_EQ(-1, SmallString<10>("AaB").compare_insensitive("aAd")); |
| 226 | - EXPECT_EQ( 0, SmallString<10>("AaB").compare_insensitive("aab")); |
| 227 | - EXPECT_EQ( 1, SmallString<10>("AaB").compare_insensitive("AAA")); |
| 228 | - EXPECT_EQ(-1, SmallString<10>("AaB").compare_insensitive("aaBb")); |
| 229 | - EXPECT_EQ( 1, SmallString<10>("AaB").compare_insensitive("aA")); |
| 230 | - EXPECT_EQ( 1, SmallString<10>("\xFF").compare_insensitive("\1")); |
| 231 | - |
| 232 | - EXPECT_EQ(-1, SmallString<10>("aab").compare_numeric("aad")); |
| 233 | - EXPECT_EQ( 0, SmallString<10>("aab").compare_numeric("aab")); |
| 234 | - EXPECT_EQ( 1, SmallString<10>("aab").compare_numeric("aaa")); |
| 235 | - EXPECT_EQ(-1, SmallString<10>("aab").compare_numeric("aabb")); |
| 236 | - EXPECT_EQ( 1, SmallString<10>("aab").compare_numeric("aa")); |
| 237 | - EXPECT_EQ(-1, SmallString<10>("1").compare_numeric("10")); |
| 238 | - EXPECT_EQ( 0, SmallString<10>("10").compare_numeric("10")); |
| 239 | - EXPECT_EQ( 0, SmallString<10>("10a").compare_numeric("10a")); |
| 240 | - EXPECT_EQ( 1, SmallString<10>("2").compare_numeric("1")); |
| 241 | - EXPECT_EQ( 0, SmallString<10>("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty")); |
| 242 | - EXPECT_EQ( 1, SmallString<10>("\xFF").compare_numeric("\1")); |
| 243 | - EXPECT_EQ( 1, SmallString<10>("V16").compare_numeric("V1_q0")); |
| 244 | - EXPECT_EQ(-1, SmallString<10>("V1_q0").compare_numeric("V16")); |
| 245 | - EXPECT_EQ(-1, SmallString<10>("V8_q0").compare_numeric("V16")); |
| 246 | - EXPECT_EQ( 1, SmallString<10>("V16").compare_numeric("V8_q0")); |
| 247 | - EXPECT_EQ(-1, SmallString<10>("V1_q0").compare_numeric("V8_q0")); |
| 248 | - EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0")); |
| 249 | -} |
| 250 | - |
| 251 | -// Check gtest prints SmallString as a string instead of a container of chars. |
| 252 | -// The code is in utils/unittest/googletest/internal/custom/gtest-printers.h |
| 253 | -TEST_F(SmallStringTest, GTestPrinter) { |
| 254 | - EXPECT_EQ(R"("foo")", ::testing::PrintToString(SmallString<1>("foo"))); |
| 255 | - const SmallVectorImpl<char> &ErasedSmallString = SmallString<1>("foo"); |
| 256 | - EXPECT_EQ(R"("foo")", ::testing::PrintToString(ErasedSmallString)); |
| 257 | -} |
| 258 | - |
| 259 | } // namespace |