blob: 4f6ba93fffaefadf0dfd3e8fe1460fa8ff12b047 [file] [log] [blame]
James Kuszmaulb13e13f2023-11-22 20:44:04 -08001From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
James Kuszmaulcf324122023-01-14 14:07:17 -08002From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sun, 8 May 2022 19:16:51 -0400
James Kuszmaulb13e13f2023-11-22 20:44:04 -08004Subject: [PATCH 21/31] Remove unused functions
James Kuszmaulcf324122023-01-14 14:07:17 -08005
6---
James Kuszmaulcf324122023-01-14 14:07:17 -08007 llvm/include/llvm/Support/raw_ostream.h | 5 +-
8 llvm/lib/Support/ErrorHandling.cpp | 16 -----
James Kuszmaulb13e13f2023-11-22 20:44:04 -08009 llvm/lib/Support/raw_ostream.cpp | 47 +++++++-------
James Kuszmaulcf324122023-01-14 14:07:17 -080010 llvm/unittests/ADT/SmallStringTest.cpp | 81 -------------------------
James Kuszmaulb13e13f2023-11-22 20:44:04 -080011 4 files changed, 23 insertions(+), 126 deletions(-)
James Kuszmaulcf324122023-01-14 14:07:17 -080012
James Kuszmaulcf324122023-01-14 14:07:17 -080013diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080014index d56999186f719f8d91f3a047a19960caf62a066c..9a9a1f688313a5784a58a70f2cb4cc0d6ec70e79 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080015--- a/llvm/include/llvm/Support/raw_ostream.h
16+++ b/llvm/include/llvm/Support/raw_ostream.h
James Kuszmaulb13e13f2023-11-22 20:44:04 -080017@@ -70,7 +70,6 @@ private:
James Kuszmaulcf324122023-01-14 14:07:17 -080018 /// 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080025@@ -317,9 +316,9 @@ public:
James Kuszmaulcf324122023-01-14 14:07:17 -080026
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.
37diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
James Kuszmaulb13e13f2023-11-22 20:44:04 -080038index 54137a331ca9e752b02c0f16ae996094a6f2fafa..e253d6f7a5ca3aee75823efdb9717dcd93fff5dc 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080039--- a/llvm/lib/Support/ErrorHandling.cpp
40+++ b/llvm/lib/Support/ErrorHandling.cpp
James Kuszmaulb13e13f2023-11-22 20:44:04 -080041@@ -181,22 +181,6 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file,
James Kuszmaulcf324122023-01-14 14:07:17 -080042 #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>
64diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
James Kuszmaulb13e13f2023-11-22 20:44:04 -080065index 4769d34a14f3f2cbaaa4df50ea7111fe9fa2792f..f9928ac969932b6baea60a80750477d78b6a5b02 100644
James Kuszmaulcf324122023-01-14 14:07:17 -080066--- a/llvm/lib/Support/raw_ostream.cpp
67+++ b/llvm/lib/Support/raw_ostream.cpp
James Kuszmaulb13e13f2023-11-22 20:44:04 -080068@@ -175,16 +175,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str,
James Kuszmaulcf324122023-01-14 14:07:17 -080069 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 Kuszmaulb13e13f2023-11-22 20:44:04 -080085@@ -327,15 +317,22 @@ static int getFD(std::string_view Filename, std::error_code &EC,
James Kuszmaulcf324122023-01-14 14:07:17 -080086 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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800113@@ -395,12 +392,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
James Kuszmaulcf324122023-01-14 14:07:17 -0800114
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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800127@@ -413,10 +406,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered,
James Kuszmaulcf324122023-01-14 14:07:17 -0800128 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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800140@@ -511,7 +502,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
James Kuszmaulcf324122023-01-14 14:07:17 -0800141
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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800152@@ -554,8 +549,8 @@ void raw_fd_ostream::close() {
James Kuszmaulcf324122023-01-14 14:07:17 -0800153 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 Kuszmaulcf324122023-01-14 14:07:17 -0800163diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800164index 6cf14700b34739420cd3dc4ff8a4c16ce162f715..87600ea4704bc98acab9085d16cfafd3d586714e 100644
James Kuszmaulcf324122023-01-14 14:07:17 -0800165--- 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 Kuszmaulb13e13f2023-11-22 20:44:04 -0800218- EXPECT_GT( 0, SmallString<10>("aab").compare("aad"));
James Kuszmaulcf324122023-01-14 14:07:17 -0800219- EXPECT_EQ( 0, SmallString<10>("aab").compare("aab"));
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800220- 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 Kuszmaulcf324122023-01-14 14:07:17 -0800224-
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