diff --git a/upstream_utils/llvm.py b/upstream_utils/llvm.py index c79ea296984..5cc224a6745 100755 --- a/upstream_utils/llvm.py +++ b/upstream_utils/llvm.py @@ -175,7 +175,7 @@ def copy_upstream_src(wpilib_root): def main(): name = "llvm" url = "https://github.com/llvm/llvm-project" - tag = "llvmorg-18.1.8" + tag = "llvmorg-19.1.4" patch_options = { "use_threeway": True, diff --git a/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch b/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch index 260b22ad861..ae1f814f477 100644 --- a/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch +++ b/upstream_utils/llvm_patches/0001-Remove-StringRef-ArrayRef-and-Optional.patch @@ -6,31 +6,30 @@ Subject: [PATCH 01/36] Remove StringRef, ArrayRef, and Optional --- llvm/include/llvm/ADT/PointerUnion.h | 1 - llvm/include/llvm/ADT/SmallSet.h | 2 +- - llvm/include/llvm/ADT/SmallString.h | 103 ++++++++++-------- + llvm/include/llvm/ADT/SmallString.h | 101 ++++++++++-------- llvm/include/llvm/ADT/SmallVector.h | 7 +- llvm/include/llvm/Support/Chrono.h | 10 +- llvm/include/llvm/Support/Compiler.h | 2 +- llvm/include/llvm/Support/ConvertUTF.h | 31 +++--- llvm/include/llvm/Support/ErrorHandling.h | 9 +- .../llvm/Support/SmallVectorMemoryBuffer.h | 6 +- - llvm/include/llvm/Support/VersionTuple.h | 6 - + llvm/include/llvm/Support/VersionTuple.h | 6 -- .../llvm/Support/Windows/WindowsSupport.h | 4 +- - llvm/include/llvm/Support/raw_ostream.h | 46 +++++--- - llvm/include/llvm/Support/xxhash.h | 16 +-- + llvm/include/llvm/Support/raw_ostream.h | 46 ++++---- + llvm/include/llvm/Support/xxhash.h | 18 ++-- llvm/lib/Support/ConvertUTFWrapper.cpp | 38 +++---- - llvm/lib/Support/ErrorHandling.cpp | 13 +-- + llvm/lib/Support/ErrorHandling.cpp | 13 ++- llvm/lib/Support/SmallVector.cpp | 5 +- - llvm/lib/Support/raw_ostream.cpp | 25 ++--- - llvm/lib/Support/xxhash.cpp | 10 +- + llvm/lib/Support/raw_ostream.cpp | 25 +++-- + llvm/lib/Support/xxhash.cpp | 12 +-- llvm/unittests/ADT/DenseMapTest.cpp | 29 +---- - llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +- - llvm/unittests/ADT/HashingTest.cpp | 2 +- + llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +-- llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 - llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++----- - llvm/unittests/ADT/SmallVectorTest.cpp | 30 +---- + llvm/unittests/ADT/SmallVectorTest.cpp | 30 ++---- llvm/unittests/Support/ConvertUTFTest.cpp | 41 ++++--- - llvm/unittests/Support/xxhashTest.cpp | 4 +- - 26 files changed, 232 insertions(+), 271 deletions(-) + llvm/unittests/Support/xxhashTest.cpp | 6 +- + 25 files changed, 232 insertions(+), 273 deletions(-) diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h index 7d4ed02b622626bb8043acb57b8ce7ed97a5f949..8ac68dbc0a791b8ac0e0ca865e69024cb642aa70 100644 @@ -63,7 +62,7 @@ index a16e8ac6f07552d98250e808190b00ee270f12b3..aeee5f97799aea7e7588d7afba1e47b4 #include #include diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h -index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413b0e36e0f 100644 +index be3193c6ef9beba622f39e3e76cd0f0c6dd422b0..9fab1a7726bc6745296f5ebb24aee4055408e5f5 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h @@ -15,8 +15,9 @@ @@ -137,14 +136,12 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize); CurrentSize += Ref.size(); } -@@ -89,26 +90,30 @@ public: +@@ -89,26 +90,28 @@ public: /// Check for string equality. This is more efficient than compare() when /// the relative ordering of inequal strings isn't needed. -- [[nodiscard]] bool equals(StringRef RHS) const { return str().equals(RHS); } -+ [[nodiscard]] bool equals(std::string_view RHS) const { -+ return str().equals(RHS); -+ } +- [[nodiscard]] bool equals(StringRef RHS) const { return str() == RHS; } ++ [[nodiscard]] bool equals(std::string_view RHS) const { return str() == RHS; } /// Check for string equality, ignoring case. - [[nodiscard]] bool equals_insensitive(StringRef RHS) const { @@ -173,7 +170,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().compare_numeric(RHS); } -@@ -116,14 +121,14 @@ public: +@@ -116,14 +119,14 @@ public: /// @name String Predicates /// @{ @@ -194,7 +191,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 } /// @} -@@ -142,7 +147,7 @@ public: +@@ -142,7 +145,7 @@ public: /// /// \returns The index of the first occurrence of \p Str, or npos if not /// found. @@ -203,7 +200,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().find(Str, From); } -@@ -150,7 +155,8 @@ public: +@@ -150,7 +153,8 @@ public: /// /// \returns The index of the last occurrence of \p C, or npos if not /// found. @@ -213,7 +210,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().rfind(C, From); } -@@ -158,7 +164,9 @@ public: +@@ -158,7 +162,9 @@ public: /// /// \returns The index of the last occurrence of \p Str, or npos if not /// found. @@ -224,7 +221,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 /// Find the first character in the string that is \p C, or npos if not /// found. Same as find. -@@ -170,7 +178,8 @@ public: +@@ -170,7 +176,8 @@ public: /// not found. /// /// Complexity: O(size() + Chars.size()) @@ -234,7 +231,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().find_first_of(Chars, From); } -@@ -184,15 +193,15 @@ public: +@@ -184,15 +191,15 @@ public: /// \p Chars, or npos if not found. /// /// Complexity: O(size() + Chars.size()) @@ -253,7 +250,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().find_last_of(C, From); } -@@ -200,8 +209,8 @@ public: +@@ -200,8 +207,8 @@ public: /// found. /// /// Complexity: O(size() + Chars.size()) @@ -264,7 +261,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().find_last_of(Chars, From); } -@@ -214,7 +223,9 @@ public: +@@ -214,7 +221,9 @@ public: /// Return the number of non-overlapped occurrences of \p Str in the /// string. @@ -275,7 +272,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 /// @} /// @name Substring Operations -@@ -229,8 +240,8 @@ public: +@@ -229,8 +238,8 @@ public: /// \param N The number of characters to included in the substring. If \p N /// exceeds the number of characters remaining in the string, the string /// suffix (starting with \p Start) will be returned. @@ -286,7 +283,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return str().substr(Start, N); } -@@ -244,15 +255,15 @@ public: +@@ -244,15 +253,15 @@ public: /// substring. If this is npos, or less than \p Start, or exceeds the /// number of characters remaining in the string, the string suffix /// (starting with \p Start) will be returned. @@ -306,7 +303,7 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 } // TODO: Make this const, if it's safe... -@@ -262,20 +273,20 @@ public: +@@ -262,20 +271,20 @@ public: return this->data(); } @@ -332,10 +329,10 @@ index a5b9eec50c8257348743f1e32ebd9a9dabd53b25..45fbf13a43a081731186b0f41c553413 return *this; } diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index 09676d792dfebd88e5c8eace666b3ab0044a962e..c96fd0e4956ee6d586f85dc79623de137e781ce0 100644 +index 17444147b102a9636fe4f0f48cfb647aaaf3ed6b..94d8da059f4f8bad50039b0d0b7993396707829c 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -27,13 +27,12 @@ +@@ -28,13 +28,12 @@ #include #include #include @@ -350,7 +347,7 @@ index 09676d792dfebd88e5c8eace666b3ab0044a962e..c96fd0e4956ee6d586f85dc79623de13 template class iterator_range; template -@@ -127,7 +126,7 @@ template struct SmallVectorAlignmentAndSize { +@@ -128,7 +127,7 @@ template struct SmallVectorAlignmentAndSize { }; /// This is the part of SmallVectorTemplateBase which does not depend on whether @@ -359,7 +356,7 @@ index 09676d792dfebd88e5c8eace666b3ab0044a962e..c96fd0e4956ee6d586f85dc79623de13 /// to avoid unnecessarily requiring T to be complete. template class SmallVectorTemplateCommon -@@ -1242,7 +1241,7 @@ public: +@@ -1243,7 +1242,7 @@ public: template ::value>> @@ -412,10 +409,10 @@ index 71859af7c7e4a595140475daf356744f52d14d24..9c9ba7002310eba5113c14957f769702 bool show_unit = consumeShowUnit(Style); diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index 8c315d255bb772d9e3c100adbd2c07b61283219b..6789f0413d8dc94cb465b6e66506b036449ee186 100644 +index d8e3794babc7449b436fa1d0bd858dab5198664b..7710bd9a08148289b5ba3b1f2dae5cccc4f26d4d 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h -@@ -319,7 +319,7 @@ +@@ -327,7 +327,7 @@ #endif /// LLVM_GSL_POINTER - Apply this to non-owning classes like @@ -639,7 +636,7 @@ index d3aacd14b2097b1e7e13c1003987c1fd52e0cf76..aabdb2f14668a990329b57f5454a0d7d template diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316ffa15939 100644 +index df9ee2e5a78586d2a2e0eb6e0698953169f7bc58..18bdf4b7d3b96d42d93ca1e4800233b34be42a78 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -14,13 +14,12 @@ @@ -657,7 +654,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 #include #include #include -@@ -208,7 +207,22 @@ public: +@@ -221,7 +220,22 @@ public: return *this; } @@ -681,7 +678,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 // Inline fast path, particularly for strings with a known length. size_t Size = Str.size(); -@@ -241,7 +255,7 @@ public: +@@ -254,7 +268,7 @@ public: // Inline fast path, particularly for constant strings where a sufficiently // smart compiler will simplify strlen. @@ -690,7 +687,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 } raw_ostream &operator<<(const std::string &Str) { -@@ -249,10 +263,6 @@ public: +@@ -262,10 +276,6 @@ public: return write(Str.data(), Str.length()); } @@ -701,7 +698,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 raw_ostream &operator<<(const SmallVectorImpl &Str) { return write(Str.data(), Str.size()); } -@@ -285,7 +295,7 @@ public: +@@ -298,7 +308,7 @@ public: /// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't /// satisfy llvm::isPrint into an escape sequence. @@ -710,7 +707,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 raw_ostream &write(unsigned char C); raw_ostream &write(const char *Ptr, size_t Size); -@@ -501,14 +511,14 @@ public: +@@ -511,14 +521,14 @@ public: /// As a special case, if Filename is "-", then the stream will use /// STDOUT_FILENO instead of opening a file. This will not close the stdout /// descriptor. @@ -730,7 +727,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags); -@@ -613,7 +623,7 @@ public: +@@ -630,7 +640,7 @@ public: /// Open the specified file for reading/writing/seeking. If an error occurs, /// information about the error is put into EC, and the stream should be /// immediately destroyed. @@ -739,7 +736,7 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 raw_fd_stream(int fd, bool shouldClose); -@@ -695,8 +705,8 @@ public: +@@ -716,8 +726,8 @@ public: void flush() = delete; @@ -747,10 +744,10 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 - StringRef str() const { return StringRef(OS.data(), OS.size()); } + /// Return a std::string_view for the vector contents. + std::string_view str() const { return std::string_view(OS.data(), OS.size()); } + SmallVectorImpl &buffer() { return OS; } void reserveExtraSpace(uint64_t ExtraSize) override { - OS.reserve(tell() + ExtraSize); -@@ -753,7 +763,7 @@ class Error; +@@ -777,7 +787,7 @@ class Error; /// for other names. For raw_fd_ostream instances, the stream writes to /// a temporary file. The final output file is atomically replaced with the /// temporary file after the \p Write function is finished. @@ -760,10 +757,10 @@ index 42663a9adf2e51ae36209faf7d465094adbf0943..9345348d9ba555022b31f94299684316 raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t); diff --git a/llvm/include/llvm/Support/xxhash.h b/llvm/include/llvm/Support/xxhash.h -index 0cef3a54e50d70177a7401324f7a4daca83c6599..3e19ebabb7ad0ff437220d9fdfe59a313386762a 100644 +index 5f8a7ab360abe24e86286b2bd6b83df7ca5fa7d3..5267e22a45f6c0c6e3bc9ca1966ed9842772918e 100644 --- a/llvm/include/llvm/Support/xxhash.h +++ b/llvm/include/llvm/Support/xxhash.h -@@ -38,16 +38,18 @@ +@@ -38,17 +38,19 @@ #ifndef LLVM_SUPPORT_XXHASH_H #define LLVM_SUPPORT_XXHASH_H @@ -775,6 +772,7 @@ index 0cef3a54e50d70177a7401324f7a4daca83c6599..3e19ebabb7ad0ff437220d9fdfe59a31 +#include namespace llvm { + -uint64_t xxHash64(llvm::StringRef Data); -uint64_t xxHash64(llvm::ArrayRef Data); +uint64_t xxHash64(std::string_view Data); @@ -787,7 +785,16 @@ index 0cef3a54e50d70177a7401324f7a4daca83c6599..3e19ebabb7ad0ff437220d9fdfe59a31 +inline uint64_t xxh3_64bits(std::string_view data) { + return xxh3_64bits(span(reinterpret_cast(data.data()), data.size())); } - } + + /*-********************************************************************** +@@ -72,7 +74,7 @@ struct XXH128_hash_t { + }; + + /// XXH3's 128-bit variant. +-XXH128_hash_t xxh3_128bits(ArrayRef data); ++XXH128_hash_t xxh3_128bits(span data); + + } // namespace llvm diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp index 3fa7365e72d34a5db941d1cbe2b1beebad5c10e6..d53462e742e61d3476915d5b2c5aa63772e78a8a 100644 @@ -922,7 +929,7 @@ index 3fa7365e72d34a5db941d1cbe2b1beebad5c10e6..d53462e742e61d3476915d5b2c5aa637 Result); } else if (sizeof(wchar_t) == 4) { diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index b8b3b7424ac6b1de782e739782f9671194ce77a1..0aa13a0f78eb370b2a673ca4a773f26820575052 100644 +index cb42e28c04a86dd60deae6fdb0b87850c1bf3727..561509e0efdf15f6e534f0621a5964d92511114c 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -14,7 +14,6 @@ @@ -1001,7 +1008,7 @@ index b6ce37842040b36fc79770ca0296255f2bb42a1a..4f6fee18b659adcbfd79822832f91417 } diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca487cde23 100644 +index 2ce54faa9857e68d9c7de4ad28f6cfa5bae86908..2dbb0674406e1860fdd0c266df64003e45b12fa3 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -167,7 +167,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) { @@ -1013,7 +1020,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca bool UseHexEscapes) { for (unsigned char c : Str) { switch (c) { -@@ -570,7 +570,7 @@ void format_object_base::home() { +@@ -564,7 +564,7 @@ void format_object_base::home() { // raw_fd_ostream //===----------------------------------------------------------------------===// @@ -1022,7 +1029,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags) { assert((Access & sys::fs::FA_Write) && -@@ -596,25 +596,25 @@ static int getFD(StringRef Filename, std::error_code &EC, +@@ -590,25 +590,25 @@ static int getFD(StringRef Filename, std::error_code &EC, return FD; } @@ -1053,7 +1060,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, sys::fs::OpenFlags Flags) -@@ -686,8 +686,7 @@ raw_fd_ostream::~raw_fd_ostream() { +@@ -680,8 +680,7 @@ raw_fd_ostream::~raw_fd_ostream() { // has_error() and clear the error flag with clear_error() before // destructing raw_ostream objects which may have errors. if (has_error()) @@ -1063,7 +1070,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca /*gen_crash_diag=*/false); } -@@ -706,7 +705,7 @@ raw_fd_ostream::~raw_fd_ostream() { +@@ -700,7 +699,7 @@ raw_fd_ostream::~raw_fd_ostream() { // the input is UTF-8 or transcode from the local codepage to UTF-8 before // quoting it. If they don't, this may mess up the encoding, but this is still // probably the best compromise we can make. @@ -1072,7 +1079,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca SmallVector WideText; // Fall back to ::write if it wasn't valid UTF-8. -@@ -749,7 +748,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -746,7 +745,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { // If this is a Windows console device, try re-encoding from UTF-8 to UTF-16 // and using WriteConsoleW. If that fails, fall back to plain write(). if (IsWindowsConsole) @@ -1081,7 +1088,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca return; #endif -@@ -925,7 +924,7 @@ raw_ostream &llvm::nulls() { +@@ -922,7 +921,7 @@ raw_ostream &llvm::nulls() { // File Streams //===----------------------------------------------------------------------===// @@ -1090,7 +1097,7 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca : raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write | sys::fs::FA_Read, sys::fs::OF_None), -@@ -998,7 +997,7 @@ void buffer_ostream::anchor() {} +@@ -1007,7 +1006,7 @@ void buffer_ostream::anchor() {} void buffer_unique_ostream::anchor() {} @@ -1100,10 +1107,10 @@ index 3d3a564af51d120786b358b96a3c90e2b7fbf9f3..220d850b9bc69f8fc2fba7cd23629eca if (OutputFileName == "-") return Write(outs()); diff --git a/llvm/lib/Support/xxhash.cpp b/llvm/lib/Support/xxhash.cpp -index 577f14189caff7d74377f7b28d8332deef4c62c4..b9c15e885a1751eaca43317323bd7a85fa201073 100644 +index cdb76d57e2c1df67e07c39f5e59284ab0ce07984..2496050eef7349ad82b54ffa6fb6bff8278c8364 100644 --- a/llvm/lib/Support/xxhash.cpp +++ b/llvm/lib/Support/xxhash.cpp -@@ -84,11 +84,11 @@ static uint64_t XXH64_avalanche(uint64_t hash) { +@@ -100,11 +100,11 @@ static uint64_t XXH64_avalanche(uint64_t hash) { return hash; } @@ -1118,7 +1125,7 @@ index 577f14189caff7d74377f7b28d8332deef4c62c4..b9c15e885a1751eaca43317323bd7a85 uint64_t H64; if (Len >= 32) { -@@ -144,7 +144,7 @@ uint64_t llvm::xxHash64(StringRef Data) { +@@ -160,7 +160,7 @@ uint64_t llvm::xxHash64(StringRef Data) { return XXH64_avalanche(H64); } @@ -1127,7 +1134,7 @@ index 577f14189caff7d74377f7b28d8332deef4c62c4..b9c15e885a1751eaca43317323bd7a85 return xxHash64({(const char *)Data.data(), Data.size()}); } -@@ -394,7 +394,7 @@ static uint64_t XXH3_hashLong_64b(const uint8_t *input, size_t len, +@@ -550,7 +550,7 @@ static uint64_t XXH3_hashLong_64b(const uint8_t *input, size_t len, (uint64_t)len * PRIME64_1); } @@ -1136,12 +1143,21 @@ index 577f14189caff7d74377f7b28d8332deef4c62c4..b9c15e885a1751eaca43317323bd7a85 auto *in = data.data(); size_t len = data.size(); if (len <= 16) +@@ -1020,7 +1020,7 @@ XXH3_hashLong_128b(const uint8_t *input, size_t len, const uint8_t *secret, + return h128; + } + +-llvm::XXH128_hash_t llvm::xxh3_128bits(ArrayRef data) { ++llvm::XXH128_hash_t llvm::xxh3_128bits(span data) { + size_t len = data.size(); + const uint8_t *input = data.data(); + diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp -index cc3244528f27e2bd7eaa385d8b7f49b2fbb7a3e6..b710ac07461ba58faa99cedeae7f209dc0f5902b 100644 +index d1bbdde8dfc267770b9d98808de54381571f2785..e93e18423507655ce8275a0718d8e5d01915985f 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp -@@ -9,11 +9,11 @@ - #include "llvm/ADT/DenseMap.h" +@@ -10,11 +10,11 @@ + #include "CountCopyAndMove.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseMapInfoVariant.h" -#include "llvm/ADT/StringRef.h" @@ -1153,8 +1169,8 @@ index cc3244528f27e2bd7eaa385d8b7f49b2fbb7a3e6..b710ac07461ba58faa99cedeae7f209d #include #include -@@ -499,31 +499,6 @@ TEST(DenseMapCustomTest, ReserveTest) { - } +@@ -523,31 +523,6 @@ TEST(DenseMapCustomTest, InsertOrAssignTest) { + EXPECT_EQ(1, CountCopyAndMove::MoveAssignments); } -// Make sure DenseMap works with StringRef keys. @@ -1185,7 +1201,7 @@ index cc3244528f27e2bd7eaa385d8b7f49b2fbb7a3e6..b710ac07461ba58faa99cedeae7f209d // Key traits that allows lookup with either an unsigned or char* key; // In the latter case, "a" == 0, "b" == 1 and so on. struct TestDenseMapInfo { -@@ -761,7 +736,7 @@ TEST(DenseMapCustomTest, VariantSupport) { +@@ -785,7 +760,7 @@ TEST(DenseMapCustomTest, VariantSupport) { // Test that gTest prints map entries as pairs instead of opaque objects. // See third-party/unittest/googletest/internal/custom/gtest-printers.h TEST(DenseMapCustomTest, PairPrinting) { @@ -1228,21 +1244,8 @@ index fc856a976946bf6decda9b6724cac66afc7bdcd6..aff9d61c7f0d48834123b04b74a2e4f7 TEST(UniqueFunctionTest, SFINAE) { EXPECT_EQ("not a function", returns("boo!")); -diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp -index ab13ee833ce556945fb9526fd13d8bd5f3e5c95a..3e80467ebd0efddcf2cbbe003bb91f1475ca9cb3 100644 ---- a/llvm/unittests/ADT/HashingTest.cpp -+++ b/llvm/unittests/ADT/HashingTest.cpp -@@ -295,7 +295,7 @@ TEST(HashingTest, HashCombineRangeGoldenTest) { - #endif - }; - for (unsigned i = 0; i < sizeof(golden_data)/sizeof(*golden_data); ++i) { -- StringRef str = golden_data[i].s; -+ std::string_view str = golden_data[i].s; - hash_code hash = hash_combine_range(str.begin(), str.end()); - #if 0 // Enable this to generate paste-able text for the above structure. - std::string member_str = "\"" + str.str() + "\","; diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp -index a97f2617cbf70783f3569709f7ee1bff03baebd2..7ed8670fd31ea2a14e6ba7f59a8ac8e35046890c 100644 +index b45318d076a3d846b7810ce8cdaed7d2d97eca87..a39b11b9f82156a78b9ad7ce7b8c28855829e611 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -12,7 +12,6 @@ @@ -1621,11 +1624,11 @@ index 6e75fbae0969ba1bf0a76c4d79a123e405a8dae7..3b07d344f15a555f11ad5f8177a0a65b // Overlong sequences of the above. EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( diff --git a/llvm/unittests/Support/xxhashTest.cpp b/llvm/unittests/Support/xxhashTest.cpp -index 7d78de6772b5159459572fe11633c76d04b86907..d61a5acd21f4d685ca631d3adb20c2649e050bc3 100644 +index 84308ce130e72818b553ea4185e8542d13182b3c..ef9a43690974ba586acc681e9f8ac49d4661031e 100644 --- a/llvm/unittests/Support/xxhashTest.cpp +++ b/llvm/unittests/Support/xxhashTest.cpp -@@ -12,7 +12,7 @@ - using namespace llvm; +@@ -32,7 +32,7 @@ static void fillTestBuffer(uint8_t *buffer, size_t len) { + } TEST(xxhashTest, Basic) { - EXPECT_EQ(0xef46db3751d8e999U, xxHash64(StringRef())); @@ -1633,7 +1636,7 @@ index 7d78de6772b5159459572fe11633c76d04b86907..d61a5acd21f4d685ca631d3adb20c264 EXPECT_EQ(0x33bf00a859c4ba3fU, xxHash64("foo")); EXPECT_EQ(0x48a37c90ad27a659U, xxHash64("bar")); EXPECT_EQ(0x69196c1b3af0bff9U, -@@ -31,7 +31,7 @@ TEST(xxhashTest, xxh3) { +@@ -51,7 +51,7 @@ TEST(xxhashTest, xxh3) { } #define F(len, expected) \ @@ -1642,3 +1645,12 @@ index 7d78de6772b5159459572fe11633c76d04b86907..d61a5acd21f4d685ca631d3adb20c264 F(0, 0x2d06800538d394c2); F(1, 0xd0d496e05c553485); F(2, 0x84d625edb7055eac); +@@ -90,7 +90,7 @@ TEST(xxhashTest, xxh3_128bits) { + + #define F(len, expected) \ + EXPECT_EQ(XXH128_hash_t(expected), \ +- xxh3_128bits(ArrayRef(sanityBuffer, size_t(len)))) ++ xxh3_128bits(span(sanityBuffer, size_t(len)))) + + F(0, (XXH128_hash_t{0x6001C324468D497FULL, + 0x99AA06D3014798D8ULL})); /* empty string */ diff --git a/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch b/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch index 1e4335b5e89..b21e044ef13 100644 --- a/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch +++ b/upstream_utils/llvm_patches/0002-Wrap-std-min-max-calls-in-parens-for-Windows-warning.patch @@ -7,14 +7,14 @@ Subject: [PATCH 02/36] Wrap std::min/max calls in parens, for Windows warnings llvm/include/llvm/ADT/DenseMap.h | 4 ++-- llvm/include/llvm/ADT/SmallVector.h | 6 +++--- llvm/include/llvm/Support/ConvertUTF.h | 2 +- - llvm/include/llvm/Support/MathExtras.h | 18 +++++++++--------- - 4 files changed, 15 insertions(+), 15 deletions(-) + llvm/include/llvm/Support/MathExtras.h | 20 ++++++++++---------- + 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h -index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004be6facafb 100644 +index 7ccc9445c0a7b882b424b2431858ea596d0eb58f..c4764fffa845a7f9eb69f262aa0ee728d08b1655 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h -@@ -416,7 +416,7 @@ protected: +@@ -432,7 +432,7 @@ protected: return 0; // +1 is required because of the strict equality. // For example if NumEntries is 48, we need to return 401. @@ -23,7 +23,7 @@ index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004b } void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) { -@@ -852,7 +852,7 @@ public: +@@ -868,7 +868,7 @@ public: // Reduce the number of buckets. unsigned NewNumBuckets = 0; if (OldNumEntries) @@ -33,10 +33,10 @@ index 3ef6a7cd1b4b587e61fcb9475d9f3516018bf2ee..108193f04486425f3b7f039cd9d2004b this->BaseT::initEmpty(); return; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index c96fd0e4956ee6d586f85dc79623de137e781ce0..d7600fe209a58deb07c63e2553f9dad62e06e973 100644 +index 94d8da059f4f8bad50039b0d0b7993396707829c..85bf5172e419b1b58f53d3cf00d4aabb58877c33 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -55,7 +55,7 @@ protected: +@@ -56,7 +56,7 @@ protected: /// The maximum value of the Size_T used. static constexpr size_t SizeTypeMax() { @@ -45,7 +45,7 @@ index c96fd0e4956ee6d586f85dc79623de137e781ce0..d7600fe209a58deb07c63e2553f9dad6 } SmallVectorBase() = delete; -@@ -289,7 +289,7 @@ public: +@@ -290,7 +290,7 @@ public: size_type size_in_bytes() const { return size() * sizeof(T); } size_type max_size() const { @@ -54,7 +54,7 @@ index c96fd0e4956ee6d586f85dc79623de137e781ce0..d7600fe209a58deb07c63e2553f9dad6 } size_t capacity_in_bytes() const { return capacity() * sizeof(T); } -@@ -721,7 +721,7 @@ public: +@@ -722,7 +722,7 @@ public: } // Assign over existing elements. @@ -77,10 +77,10 @@ index 5c0e3009c25446a34882fb98329b1d955231bb39..72321022beb373945f7935ed72944fd6 /* Some fundamental constants */ #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c91ba725d 100644 +index e568e42afcf4d20dba137346953ff4be9d27ffc7..d9de2e92d5b07bce1d02ffcfda614b9079d2df91 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h -@@ -311,26 +311,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; } +@@ -338,26 +338,26 @@ template <> constexpr size_t CTLog2<1>() { return 0; } /// (32 bit edition.) /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2 inline unsigned Log2_32(uint32_t Value) { @@ -111,7 +111,16 @@ index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c } /// A and B are either alignments or offsets. Return the minimum alignment that -@@ -482,7 +482,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { +@@ -417,7 +417,7 @@ constexpr uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) { + // happens only when Numerator = INT_MIN and Denominator = -1. + template + constexpr bool divideSignedWouldOverflow(U Numerator, V Denominator) { +- return Numerator == std::numeric_limits::min() && Denominator == -1; ++ return Numerator == (std::numeric_limits::min)() && Denominator == -1; + } + + /// Returns the integer ceil(Numerator / Denominator). Signed version. +@@ -605,7 +605,7 @@ SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) { T Z = X + Y; Overflowed = (Z < X || Z < Y); if (Overflowed) @@ -120,7 +129,7 @@ index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c else return Z; } -@@ -495,7 +495,7 @@ std::enable_if_t, T> SaturatingAdd(T X, T Y, T Z, +@@ -618,7 +618,7 @@ std::enable_if_t, T> SaturatingAdd(T X, T Y, T Z, bool Overflowed = false; T XY = SaturatingAdd(X, Y, &Overflowed); if (Overflowed) @@ -129,7 +138,7 @@ index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c return SaturatingAdd(XY, Z, Args...); } -@@ -519,7 +519,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { +@@ -642,7 +642,7 @@ SaturatingMultiply(T X, T Y, bool *ResultOverflowed = nullptr) { // Special case: if X or Y is 0, Log2_64 gives -1, and Log2Z // will necessarily be less than Log2Max as desired. int Log2Z = Log2_64(X) + Log2_64(Y); @@ -138,7 +147,7 @@ index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c int Log2Max = Log2_64(Max); if (Log2Z < Log2Max) { return X * Y; -@@ -639,9 +639,9 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { +@@ -764,9 +764,9 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { // Check how the max allowed absolute value (2^n for negative, 2^(n-1) for // positive) divided by an argument compares to the other. if (IsNegative) @@ -147,6 +156,6 @@ index aa4f4d2ed42e262f27e3f7f5ce275baf7e556c2d..5cabfdd6493fee33fbc74b831dc1fa3c else - return UX > (static_cast(std::numeric_limits::max())) / UY; + return UX > (static_cast((std::numeric_limits::max)())) / UY; + #endif } - } // End llvm namespace diff --git a/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch b/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch index ff920af4b52..22a98b4278d 100644 --- a/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch +++ b/upstream_utils/llvm_patches/0003-Change-unique_function-storage-size.patch @@ -8,7 +8,7 @@ Subject: [PATCH 03/36] Change unique_function storage size 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index c0bc30c7450fe4b2bc6b9b448824eedc8b132e52..5641a913d0a35ee2911cf872ad90c3dc864f20f5 100644 +index 49e0e8ab0db400d0a362746342099578257b2eea..3ce85530b718666afa1dafbf60699c1add423ea6 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -79,7 +79,7 @@ using EnableIfCallable = std::enable_if_t` may // still modify its own mutable members. - mutable std::aligned_storage_t + alignas(void *) mutable std::byte InlineStorage[InlineStorageSize]; diff --git a/upstream_utils/llvm_patches/0004-Threading-updates.patch b/upstream_utils/llvm_patches/0004-Threading-updates.patch index 894050c88d9..579aaf45941 100644 --- a/upstream_utils/llvm_patches/0004-Threading-updates.patch +++ b/upstream_utils/llvm_patches/0004-Threading-updates.patch @@ -7,15 +7,15 @@ Subject: [PATCH 04/36] Threading updates - Prefer scope gaurd over lock gaurd --- llvm/include/llvm/Support/Compiler.h | 6 ----- - llvm/lib/Support/ErrorHandling.cpp | 38 +++++----------------------- + llvm/lib/Support/ErrorHandling.cpp | 36 +++++----------------------- llvm/lib/Support/ManagedStatic.cpp | 10 ++++---- - 3 files changed, 11 insertions(+), 43 deletions(-) + 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index 6789f0413d8dc94cb465b6e66506b036449ee186..e608f8ea3a837a04d9c29c8bb7a1fab527d512bb 100644 +index 7710bd9a08148289b5ba3b1f2dae5cccc4f26d4d..2a6accec1e74c9869d724c7733cc75ab6af9dc8d 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h -@@ -555,7 +555,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -563,7 +563,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// initialize to some constant value. In almost all circumstances this is most /// appropriate for use with a pointer, integer, or small aggregation of /// pointers and integers. @@ -23,7 +23,7 @@ index 6789f0413d8dc94cb465b6e66506b036449ee186..e608f8ea3a837a04d9c29c8bb7a1fab5 #if __has_feature(cxx_thread_local) || defined(_MSC_VER) #define LLVM_THREAD_LOCAL thread_local #else -@@ -563,11 +562,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -571,11 +570,6 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); // we only need the restricted functionality that provides. #define LLVM_THREAD_LOCAL __thread #endif @@ -36,7 +36,7 @@ index 6789f0413d8dc94cb465b6e66506b036449ee186..e608f8ea3a837a04d9c29c8bb7a1fab5 /// \macro LLVM_ENABLE_EXCEPTIONS /// Whether LLVM is built with exception support. diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb8ba1276e 100644 +index 561509e0efdf15f6e534f0621a5964d92511114c..fbd903ed86f65dbdec5ddd69c541e2fc37a484a6 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -44,7 +44,6 @@ static void *ErrorHandlerUserData = nullptr; @@ -83,17 +83,16 @@ index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb handler = ErrorHandler; handlerData = ErrorHandlerUserData; } -@@ -126,18 +118,14 @@ void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) { - +@@ -127,7 +119,7 @@ void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) { void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler, void *user_data) { --#if LLVM_ENABLE_THREADS == 1 + #if LLVM_ENABLE_THREADS == 1 - std::lock_guard Lock(BadAllocErrorHandlerMutex); --#endif + std::scoped_lock Lock(BadAllocErrorHandlerMutex); - assert(!ErrorHandler && "Bad alloc error handler already registered!\n"); - BadAllocErrorHandler = handler; - BadAllocErrorHandlerUserData = user_data; + #endif + assert(!BadAllocErrorHandler && + "Bad alloc error handler already registered!\n"); +@@ -136,9 +128,7 @@ void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler, } void llvm::remove_bad_alloc_error_handler() { @@ -104,7 +103,7 @@ index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb BadAllocErrorHandler = nullptr; BadAllocErrorHandlerUserData = nullptr; } -@@ -148,9 +136,7 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { +@@ -149,9 +139,7 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { { // Only acquire the mutex while reading the handler, so as not to invoke a // user-supplied callback under a lock. @@ -115,7 +114,7 @@ index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb Handler = BadAllocErrorHandler; HandlerData = BadAllocErrorHandlerUserData; } -@@ -160,10 +146,6 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { +@@ -161,10 +149,6 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { llvm_unreachable("bad alloc handler should not return"); } @@ -126,7 +125,7 @@ index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb // Don't call the normal error handler. It may allocate memory. Directly write // an OOM to stderr and abort. const char *OOMMessage = "LLVM ERROR: out of memory\n"; -@@ -172,15 +154,8 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { +@@ -173,15 +157,8 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { (void)!::write(2, Reason, strlen(Reason)); (void)!::write(2, Newline, strlen(Newline)); abort(); @@ -142,7 +141,7 @@ index 0aa13a0f78eb370b2a673ca4a773f26820575052..637b669a7d0dae69ef4b34955f21a9fb // Causes crash on allocation failure. It is called prior to the handler set by // 'install_bad_alloc_error_handler'. static void out_of_memory_new_handler() { -@@ -195,7 +170,6 @@ void llvm::install_out_of_memory_new_handler() { +@@ -196,7 +173,6 @@ void llvm::install_out_of_memory_new_handler() { assert((old == nullptr || old == out_of_memory_new_handler) && "new-handler already installed"); } diff --git a/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch b/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch index 50d93406cf7..6dcd4c91ccb 100644 --- a/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch +++ b/upstream_utils/llvm_patches/0005-ifdef-guard-safety.patch @@ -9,7 +9,7 @@ Prevents redefinition if someone is pulling in real LLVM, since the macros are i 1 file changed, 42 insertions(+) diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h -index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2a451c037 100644 +index 2a6accec1e74c9869d724c7733cc75ab6af9dc8d..cb99bf5efe87d98fd73108c189182a28998bcbe9 100644 --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -90,6 +90,7 @@ @@ -137,19 +137,23 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if __has_attribute(returns_nonnull) #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) #elif defined(_MSC_VER) -@@ -277,9 +296,11 @@ +@@ -277,6 +296,7 @@ #else #define LLVM_ATTRIBUTE_RETURNS_NONNULL #endif +#endif + /// LLVM_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that + /// it is not aliased in the current scope. +@@ -288,6 +308,7 @@ + /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a /// pointer that does not alias any other valid pointer. +#ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS #ifdef __GNUC__ #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) #elif defined(_MSC_VER) -@@ -287,8 +308,10 @@ +@@ -295,8 +316,10 @@ #else #define LLVM_ATTRIBUTE_RETURNS_NOALIAS #endif @@ -160,7 +164,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough) #define LLVM_FALLTHROUGH [[fallthrough]] #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough) -@@ -300,6 +323,7 @@ +@@ -308,6 +331,7 @@ #else #define LLVM_FALLTHROUGH #endif @@ -168,7 +172,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that /// they are constant initialized. -@@ -334,11 +358,13 @@ +@@ -342,11 +366,13 @@ /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress /// pedantic diagnostics. @@ -182,7 +186,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands /// to an expression which states that it is undefined behavior for the -@@ -347,14 +373,17 @@ +@@ -355,14 +381,17 @@ /// '#else' is intentionally left out so that other macro logic (e.g., /// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether /// LLVM_BUILTIN_UNREACHABLE has a definition. @@ -200,7 +204,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if __has_builtin(__builtin_trap) || defined(__GNUC__) # define LLVM_BUILTIN_TRAP __builtin_trap() #elif defined(_MSC_VER) -@@ -366,10 +395,12 @@ +@@ -374,10 +403,12 @@ #else # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 #endif @@ -213,7 +217,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if __has_builtin(__builtin_debugtrap) # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() #elif defined(_MSC_VER) -@@ -383,9 +414,11 @@ +@@ -391,9 +422,11 @@ // program to abort if encountered. # define LLVM_BUILTIN_DEBUGTRAP #endif @@ -225,7 +229,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) #elif defined(LLVM_BUILTIN_UNREACHABLE) -@@ -394,6 +427,7 @@ +@@ -402,6 +435,7 @@ #else # define LLVM_ASSUME_ALIGNED(p, a) (p) #endif @@ -233,7 +237,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 /// \macro LLVM_PACKED /// Used to specify a packed structure. -@@ -413,6 +447,7 @@ +@@ -421,6 +455,7 @@ /// long long l; /// }; /// LLVM_PACKED_END @@ -241,7 +245,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #ifdef _MSC_VER # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop)) # define LLVM_PACKED_START __pragma(pack(push, 1)) -@@ -422,6 +457,7 @@ +@@ -430,6 +465,7 @@ # define LLVM_PACKED_START _Pragma("pack(push, 1)") # define LLVM_PACKED_END _Pragma("pack(pop)") #endif @@ -249,7 +253,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 /// \macro LLVM_MEMORY_SANITIZER_BUILD /// Whether LLVM itself is built with MemorySanitizer instrumentation. -@@ -513,11 +549,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -521,11 +557,13 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// \macro LLVM_NO_SANITIZE /// Disable a particular sanitizer for a function. @@ -263,7 +267,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 /// Mark debug helper function definitions like dump() that should not be /// stripped from debug builds. -@@ -525,17 +563,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -533,17 +571,20 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always /// get stripped in release builds. // FIXME: Move this to a private config.h as it's not usable in public headers. @@ -284,7 +288,7 @@ index e608f8ea3a837a04d9c29c8bb7a1fab527d512bb..8f68d79898fe0247f9e17709bf1c1ec2 #if defined(_MSC_VER) #define LLVM_PRETTY_FUNCTION __FUNCSIG__ #elif defined(__GNUC__) || defined(__clang__) -@@ -543,6 +584,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); +@@ -551,6 +592,7 @@ void AnnotateIgnoreWritesEnd(const char *file, int line); #else #define LLVM_PRETTY_FUNCTION __func__ #endif diff --git a/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch b/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch index baa83c2b34b..497282cb5b2 100644 --- a/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch +++ b/upstream_utils/llvm_patches/0006-Explicitly-use-std.patch @@ -24,10 +24,10 @@ index aeee5f97799aea7e7588d7afba1e47b4fa3d8c7b..4969dfb0d61c2fad805c9cb7bc0184ea /// Inequality comparison for SmallSet. diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index 637b669a7d0dae69ef4b34955f21a9fb8ba1276e..0b87b375de67dc18647e3ebe646bf323dd05e8c5 100644 +index fbd903ed86f65dbdec5ddd69c541e2fc37a484a6..c205eab6f5467e3f461a168a596e574e3876f77e 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp -@@ -213,7 +213,7 @@ void LLVMResetFatalErrorHandler() { +@@ -251,7 +251,7 @@ std::error_code llvm::mapLastWindowsError() { // I'd rather not double the line count of the following. #define MAP_ERR_TO_COND(x, y) \ case x: \ @@ -37,10 +37,10 @@ index 637b669a7d0dae69ef4b34955f21a9fb8ba1276e..0b87b375de67dc18647e3ebe646bf323 std::error_code llvm::mapWindowsError(unsigned EV) { switch (EV) { diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp -index 7ed8670fd31ea2a14e6ba7f59a8ac8e35046890c..531f81ab5b3fc1dcff731230f3cb7649cb90aedf 100644 +index a39b11b9f82156a78b9ad7ce7b8c28855829e611..a6c2b329f072639706aa221feb8c08e33533f813 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp -@@ -298,7 +298,7 @@ TEST(SmallPtrSetTest, dereferenceAndIterate) { +@@ -259,7 +259,7 @@ TEST(SmallPtrSetTest, dereferenceAndIterate) { // Sort. We should hit the first element just once and the final element N // times. diff --git a/upstream_utils/llvm_patches/0007-Remove-format_provider.patch b/upstream_utils/llvm_patches/0007-Remove-format_provider.patch index 914aeb183ef..1cd071f60bb 100644 --- a/upstream_utils/llvm_patches/0007-Remove-format_provider.patch +++ b/upstream_utils/llvm_patches/0007-Remove-format_provider.patch @@ -142,7 +142,7 @@ index 9c9ba7002310eba5113c14957f769702c61f4326..b269ff8bb5db7bb3c62c3a87daf255b1 #endif // LLVM_SUPPORT_CHRONO_H diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 9345348d9ba555022b31f94299684316ffa15939..862a1db876e9b8467a8839dae8f6632f18d5e7a0 100644 +index 18bdf4b7d3b96d42d93ca1e4800233b34be42a78..6c2eedf99d003a29243fbb2a9a280fe12dd49d8a 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -27,12 +27,6 @@ diff --git a/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch b/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch index f5996fd9668..01a99ad6526 100644 --- a/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch +++ b/upstream_utils/llvm_patches/0008-Add-compiler-warning-pragmas.patch @@ -17,7 +17,7 @@ Subject: [PATCH 08/36] Add compiler warning pragmas 10 files changed, 72 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index 5641a913d0a35ee2911cf872ad90c3dc864f20f5..043d8d90fff03d571a923c264b49be37a5dffa09 100644 +index 3ce85530b718666afa1dafbf60699c1add423ea6..da61b606eb44bdbdeb4674c9c7eab9f691124f9c 100644 --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -56,6 +56,13 @@ namespace llvm { @@ -34,7 +34,7 @@ index 5641a913d0a35ee2911cf872ad90c3dc864f20f5..043d8d90fff03d571a923c264b49be37 namespace detail { template -@@ -412,6 +419,10 @@ public: +@@ -411,6 +418,10 @@ public: } }; @@ -46,10 +46,10 @@ index 5641a913d0a35ee2911cf872ad90c3dc864f20f5..043d8d90fff03d571a923c264b49be37 #endif // LLVM_ADT_FUNCTIONEXTRAS_H diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h -index a5477362a50793985e1e9df9dc77c8a1d5b5846b..08d6edb14eb3cd51405329aae61b9782266a2590 100644 +index 109966257b51c015754f6410aec5fa9b8de435ae..a33c6eec308c8722f88b09f73f954d39558c3d62 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h -@@ -56,6 +56,11 @@ +@@ -57,6 +57,11 @@ #include #include @@ -61,7 +61,7 @@ index a5477362a50793985e1e9df9dc77c8a1d5b5846b..08d6edb14eb3cd51405329aae61b9782 namespace llvm { template struct DenseMapInfo; -@@ -697,4 +702,8 @@ struct hash { +@@ -677,4 +682,8 @@ struct hash { } // namespace std; @@ -71,7 +71,7 @@ index a5477362a50793985e1e9df9dc77c8a1d5b5846b..08d6edb14eb3cd51405329aae61b9782 + #endif diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index d7600fe209a58deb07c63e2553f9dad62e06e973..d7788e94b5379f5eba6fbddee50e4b4359da9d80 100644 +index 85bf5172e419b1b58f53d3cf00d4aabb58877c33..ec340afd4519f4070389434006bf7f2afdbf2993 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -14,6 +14,14 @@ @@ -90,10 +90,10 @@ index d7600fe209a58deb07c63e2553f9dad62e06e973..d7788e94b5379f5eba6fbddee50e4b43 #include "llvm/Support/type_traits.h" #include diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 5cabfdd6493fee33fbc74b831dc1fa3c91ba725d..7541447fa2db5e1634d952b1f39957eb725611f4 100644 +index d9de2e92d5b07bce1d02ffcfda614b9079d2df91..6028ba8ead7627b4821aa8642f5069b305605c5e 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h -@@ -208,6 +208,11 @@ inline uint64_t maxUIntN(uint64_t N) { +@@ -231,6 +231,11 @@ inline uint64_t maxUIntN(uint64_t N) { return UINT64_MAX >> (64 - N); } @@ -104,8 +104,8 @@ index 5cabfdd6493fee33fbc74b831dc1fa3c91ba725d..7541447fa2db5e1634d952b1f39957eb + /// Gets the minimum value for a N-bit signed integer. inline int64_t minIntN(int64_t N) { - assert(N > 0 && N <= 64 && "integer width out of range"); -@@ -215,6 +220,10 @@ inline int64_t minIntN(int64_t N) { + assert(N <= 64 && "integer width out of range"); +@@ -240,6 +245,10 @@ inline int64_t minIntN(int64_t N) { return UINT64_C(1) + ~(UINT64_C(1) << (N - 1)); } @@ -115,7 +115,7 @@ index 5cabfdd6493fee33fbc74b831dc1fa3c91ba725d..7541447fa2db5e1634d952b1f39957eb + /// Gets the maximum value for a N-bit signed integer. inline int64_t maxIntN(int64_t N) { - assert(N > 0 && N <= 64 && "integer width out of range"); + assert(N <= 64 && "integer width out of range"); diff --git a/llvm/include/llvm/Support/MemAlloc.h b/llvm/include/llvm/Support/MemAlloc.h index f3f378b7697a18f57b189c5322b080fe23d45bec..0028e871f6a05baf6172c60c602b8b26e5f116c6 100644 --- a/llvm/include/llvm/Support/MemAlloc.h @@ -146,7 +146,7 @@ index f3f378b7697a18f57b189c5322b080fe23d45bec..0028e871f6a05baf6172c60c602b8b26 + #endif diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 220d850b9bc69f8fc2fba7cd23629eca487cde23..65810ca93fdc1290e3188b5f4fb292a1e1e79b60 100644 +index 2dbb0674406e1860fdd0c266df64003e45b12fa3..e248eb67df9144bb4cf14e3d3acab161a95d1ce3 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -10,6 +10,10 @@ @@ -161,7 +161,7 @@ index 220d850b9bc69f8fc2fba7cd23629eca487cde23..65810ca93fdc1290e3188b5f4fb292a1 #include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp -index b710ac07461ba58faa99cedeae7f209dc0f5902b..1f232d3046292c0da940ba4bef7d50604556e4c2 100644 +index e93e18423507655ce8275a0718d8e5d01915985f..b930a21f8b43b64835436fcd27f4802a7987827f 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -6,6 +6,10 @@ @@ -173,8 +173,8 @@ index b710ac07461ba58faa99cedeae7f209dc0f5902b..1f232d3046292c0da940ba4bef7d5060 +#endif + #include "llvm/ADT/DenseMap.h" + #include "CountCopyAndMove.h" #include "llvm/ADT/DenseMapInfo.h" - #include "llvm/ADT/DenseMapInfoVariant.h" diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp index e0f11b60a0223da7c00a47c20b61136bd608bae6..9c802ab30721c9ce58ed65052a6ab467039226ff 100644 --- a/llvm/unittests/ADT/MapVectorTest.cpp diff --git a/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch b/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch index 071e7891297..20763b3641f 100644 --- a/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch +++ b/upstream_utils/llvm_patches/0009-Remove-unused-functions.patch @@ -4,26 +4,24 @@ Date: Sun, 8 May 2022 13:43:50 -0400 Subject: [PATCH 09/36] Remove unused functions --- - llvm/include/llvm/ADT/SmallString.h | 79 ------ + llvm/include/llvm/ADT/SmallString.h | 77 ------ llvm/include/llvm/Support/Errno.h | 9 - llvm/include/llvm/Support/VersionTuple.h | 39 --- llvm/include/llvm/Support/raw_ostream.h | 129 +-------- llvm/lib/Support/raw_ostream.cpp | 332 ----------------------- - 5 files changed, 8 insertions(+), 580 deletions(-) + 5 files changed, 8 insertions(+), 578 deletions(-) diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h -index 45fbf13a43a081731186b0f41c553413b0e36e0f..cb6136d8fd1886e8dc444cb807b33a5f1e18aa44 100644 +index 9fab1a7726bc6745296f5ebb24aee4055408e5f5..cb6136d8fd1886e8dc444cb807b33a5f1e18aa44 100644 --- a/llvm/include/llvm/ADT/SmallString.h +++ b/llvm/include/llvm/ADT/SmallString.h -@@ -88,17 +88,6 @@ public: +@@ -88,15 +88,6 @@ public: /// @name String Comparison /// @{ - /// Check for string equality. This is more efficient than compare() when - /// the relative ordering of inequal strings isn't needed. -- [[nodiscard]] bool equals(std::string_view RHS) const { -- return str().equals(RHS); -- } +- [[nodiscard]] bool equals(std::string_view RHS) const { return str() == RHS; } - - /// Check for string equality, ignoring case. - [[nodiscard]] bool equals_insensitive(std::string_view RHS) const { @@ -33,7 +31,7 @@ index 45fbf13a43a081731186b0f41c553413b0e36e0f..cb6136d8fd1886e8dc444cb807b33a5f /// compare - Compare two strings; the result is negative, zero, or positive /// if this string is lexicographically less than, equal to, or greater than /// the \p RHS. -@@ -106,31 +95,6 @@ public: +@@ -104,31 +95,6 @@ public: return str().compare(RHS); } @@ -65,7 +63,7 @@ index 45fbf13a43a081731186b0f41c553413b0e36e0f..cb6136d8fd1886e8dc444cb807b33a5f /// @} /// @name String Searching /// @{ -@@ -215,49 +179,6 @@ public: +@@ -213,49 +179,6 @@ public: } /// @} @@ -186,10 +184,10 @@ index e1cdce77ce8659305c99a21e01f9b3cc3481a5fd..9102ff063afedc03bd524b2805cba98e } // end namespace llvm diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc4e956dac 100644 +index 6c2eedf99d003a29243fbb2a9a280fe12dd49d8a..cbeb712e2a69426d83457cb1065fff4ca80a669d 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h -@@ -261,32 +261,6 @@ public: +@@ -274,32 +274,6 @@ public: return write(Str.data(), Str.size()); } @@ -222,7 +220,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc /// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't /// satisfy llvm::isPrint into an escape sequence. raw_ostream &write_escaped(std::string_view Str, bool UseHexEscapes = false); -@@ -294,21 +268,6 @@ public: +@@ -307,21 +281,6 @@ public: raw_ostream &write(unsigned char C); raw_ostream &write(const char *Ptr, size_t Size); @@ -244,7 +242,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc /// indent - Insert 'NumSpaces' spaces. raw_ostream &indent(unsigned NumSpaces); -@@ -323,14 +282,19 @@ public: +@@ -336,14 +295,19 @@ public: /// @param BG if true change the background, default: change foreground /// @returns itself so it can be used within << invocations virtual raw_ostream &changeColor(enum Colors Color, bool Bold = false, @@ -267,7 +265,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc /// This function determines if this stream is connected to a "tty" or /// "console" window. That is, the output would be displayed to the user -@@ -405,10 +369,6 @@ private: +@@ -414,10 +378,6 @@ private: /// unused bytes in the buffer. void copy_to_buffer(const char *Ptr, size_t Size); @@ -275,18 +273,18 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc - /// flushing. The result is affected by calls to enable_color(). - bool prepare_colors(); - - /// Flush the tied-to stream (if present) and then write the required data. - void flush_tied_then_write(const char *Ptr, size_t Size); + virtual void anchor(); + }; -@@ -460,7 +420,6 @@ class raw_fd_ostream : public raw_pwrite_stream { +@@ -466,7 +426,6 @@ class raw_fd_ostream : public raw_pwrite_stream { bool ShouldClose; bool SupportsSeeking = false; bool IsRegularFile = false; - mutable std::optional HasColors; - #ifdef _WIN32 - /// True if this fd refers to a Windows console device. Mintty and other -@@ -536,10 +495,6 @@ public: + /// Optional stream this stream is tied to. If this stream is written to, the + /// tied-to stream will be flushed first. +@@ -546,10 +505,6 @@ public: /// to the offset specified from the beginning of the file. uint64_t seek(uint64_t off); @@ -294,10 +292,10 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc - - bool has_colors() const override; - - std::error_code error() const { return EC; } - - /// Return the value of the flag in this raw_fd_ostream indicating whether an -@@ -558,38 +513,6 @@ public: + /// Tie this stream to the specified stream. Replaces any existing tied-to + /// stream. Specifying a nullptr unties the stream. This is intended for to + /// tie errs() to outs(), so that outs() is flushed whenever something is +@@ -575,38 +530,6 @@ public: /// - from The Zen of Python, by Tim Peters /// void clear_error() { EC = std::error_code(); } @@ -336,7 +334,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc }; /// This returns a reference to a raw_fd_ostream for standard output. Use it -@@ -619,19 +542,6 @@ public: +@@ -636,19 +559,6 @@ public: /// immediately destroyed. raw_fd_stream(std::string_view Filename, std::error_code &EC); @@ -356,7 +354,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc /// Check if \p OS is a pointer of type raw_fd_stream*. static bool classof(const raw_ostream *OS); }; -@@ -749,29 +659,6 @@ public: +@@ -773,29 +683,6 @@ public: ~buffer_unique_ostream() override { *OS << str(); } }; @@ -387,7 +385,7 @@ index 862a1db876e9b8467a8839dae8f6632f18d5e7a0..95019180a9deb406ed4f2991c664a4cc #endif // LLVM_SUPPORT_RAW_OSTREAM_H diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333289b6248 100644 +index e248eb67df9144bb4cf14e3d3acab161a95d1ce3..ee9d2b0cda0a4f338e4b089304203f220a5ed1c4 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -19,7 +19,6 @@ @@ -448,8 +446,8 @@ index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333 raw_ostream &raw_ostream::write_escaped(std::string_view Str, bool UseHexEscapes) { for (unsigned char c : Str) { -@@ -316,173 +272,6 @@ void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) { - write_impl(Ptr, Size); +@@ -310,173 +266,6 @@ void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) { + OutBufCur += Size; } -// Formatted output. @@ -622,7 +620,7 @@ index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333 template static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) { static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, -@@ -513,63 +302,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) { +@@ -507,63 +296,8 @@ raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) { return write_padding<'\0'>(*this, NumZeros); } @@ -686,7 +684,7 @@ index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333 //===----------------------------------------------------------------------===// // raw_fd_ostream //===----------------------------------------------------------------------===// -@@ -865,31 +599,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { +@@ -862,31 +596,6 @@ size_t raw_fd_ostream::preferred_buffer_size() const { #endif } @@ -718,7 +716,7 @@ index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333 void raw_fd_ostream::anchor() {} //===----------------------------------------------------------------------===// -@@ -940,19 +649,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) +@@ -937,19 +646,6 @@ raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) EC = std::make_error_code(std::errc::invalid_argument); } @@ -731,14 +729,14 @@ index 65810ca93fdc1290e3188b5f4fb292a1e1e79b60..c65fb70a4d22db51f4140b910c308333 - if (Ret >= 0) - inc_pos(Ret); - else -- error_detected(std::error_code(errno, std::generic_category())); +- error_detected(errnoAsErrorCode()); - return Ret; -} - bool raw_fd_stream::classof(const raw_ostream *OS) { return OS->get_kind() == OStreamKind::OK_FDStream; } -@@ -1000,31 +696,3 @@ void raw_pwrite_stream::anchor() {} +@@ -1009,31 +705,3 @@ void raw_pwrite_stream::anchor() {} void buffer_ostream::anchor() {} void buffer_unique_ostream::anchor() {} diff --git a/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch b/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch index cdb642e87c5..d784205b01c 100644 --- a/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch +++ b/upstream_utils/llvm_patches/0010-Detemplatize-SmallVectorBase.patch @@ -9,10 +9,10 @@ Subject: [PATCH 10/36] Detemplatize SmallVectorBase 2 files changed, 18 insertions(+), 54 deletions(-) diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d093e1242 100644 +index ec340afd4519f4070389434006bf7f2afdbf2993..6b12ea17aaa894dc9a719ade4c41a3f7df4304e9 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -56,19 +56,19 @@ using EnableIfConvertibleToInputIterator = std::enable_if_t, where a /// 32 bit size would limit the vector to ~4GB. SmallVectors are used for /// buffering bitcode output - which can exceed 4GB. @@ -37,7 +37,7 @@ index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d /// This is a helper for \a grow() that's out of line to reduce code /// duplication. This function will report a fatal error if it can't grow at -@@ -107,7 +107,7 @@ protected: +@@ -108,7 +108,7 @@ protected: /// This does not construct or destroy any elements in the vector. void set_size(size_t N) { assert(N <= capacity()); // implies no overflow in assignment @@ -46,7 +46,7 @@ index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d } /// Set the array data pointer to \p Begin and capacity to \p N. -@@ -117,19 +117,14 @@ protected: +@@ -118,19 +118,14 @@ protected: void set_allocation_range(void *Begin, size_t N) { assert(N <= SizeTypeMax()); BeginX = Begin; @@ -69,7 +69,7 @@ index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d alignas(T) char FirstEl[sizeof(T)]; }; -@@ -138,8 +133,8 @@ template struct SmallVectorAlignmentAndSize { +@@ -139,8 +134,8 @@ template struct SmallVectorAlignmentAndSize { /// to avoid unnecessarily requiring T to be complete. template class SmallVectorTemplateCommon @@ -80,7 +80,7 @@ index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d protected: /// Find the address of the first element. For this pointer math to be valid -@@ -461,7 +456,7 @@ template +@@ -462,7 +457,7 @@ template T *SmallVectorTemplateBase::mallocForGrow( size_t MinSize, size_t &NewCapacity) { return static_cast( @@ -89,7 +89,7 @@ index d7788e94b5379f5eba6fbddee50e4b4359da9d80..b953ae45a34772eb7fd04c3af0275a7d this->getFirstEl(), MinSize, sizeof(T), NewCapacity)); } -@@ -1333,12 +1328,6 @@ template SmallVector to_vector_of(R &&Range) { +@@ -1334,12 +1329,6 @@ template SmallVector to_vector_of(R &&Range) { return {std::begin(Range), std::end(Range)}; } diff --git a/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch b/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch index d9610107453..3bab41b93f5 100644 --- a/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch +++ b/upstream_utils/llvm_patches/0011-Add-vectors-to-raw_ostream.patch @@ -9,7 +9,7 @@ Subject: [PATCH 11/36] Add vectors to raw_ostream 2 files changed, 162 insertions(+) diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9691759d4 100644 +index cbeb712e2a69426d83457cb1065fff4ca80a669d..a6799603a0106262520ba1c9fda14a7967b12a63 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -24,6 +24,7 @@ @@ -20,7 +20,7 @@ index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9 namespace llvm { -@@ -261,12 +262,24 @@ public: +@@ -274,12 +275,24 @@ public: return write(Str.data(), Str.size()); } @@ -45,8 +45,8 @@ index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9 /// indent - Insert 'NumSpaces' spaces. raw_ostream &indent(unsigned NumSpaces); -@@ -617,6 +630,108 @@ public: - } +@@ -641,6 +654,108 @@ public: + static bool classof(const raw_ostream *OS); }; +/// A raw_ostream that writes to a vector. This is a @@ -155,11 +155,11 @@ index 95019180a9deb406ed4f2991c664a4cc4e956dac..e7526e016a858ad728feb7cf1c5014b9 class raw_null_ostream : public raw_pwrite_stream { /// See raw_ostream::write_impl. diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index c65fb70a4d22db51f4140b910c308333289b6248..57d3091fd5cc5b416e814f9f33811f0fa7afe9cf 100644 +index ee9d2b0cda0a4f338e4b089304203f220a5ed1c4..6c330c92e7dbeb27310b053d1a82de73b42ee6f8 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -668,6 +668,53 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size, - memcpy(OS.data() + Offset, Ptr, Size); +@@ -677,6 +677,53 @@ bool raw_svector_ostream::classof(const raw_ostream *OS) { + return OS->get_kind() == OStreamKind::OK_SVecStream; } +//===----------------------------------------------------------------------===// diff --git a/upstream_utils/llvm_patches/0012-Extra-collections-features.patch b/upstream_utils/llvm_patches/0012-Extra-collections-features.patch index 6db0699ad1e..557dc158ded 100644 --- a/upstream_utils/llvm_patches/0012-Extra-collections-features.patch +++ b/upstream_utils/llvm_patches/0012-Extra-collections-features.patch @@ -8,7 +8,7 @@ Subject: [PATCH 12/36] Extra collections features 1 file changed, 8 insertions(+) diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 57d3091fd5cc5b416e814f9f33811f0fa7afe9cf..5bec803ccc76ce287b7ff3ea037d5e490a7af20c 100644 +index 6c330c92e7dbeb27310b053d1a82de73b42ee6f8..7086368a3598ccad9502112f734c9ad81252ebec 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -77,6 +77,14 @@ constexpr raw_ostream::Colors raw_ostream::WHITE; diff --git a/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch b/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch index ebf7baf9c71..f6704bf20b1 100644 --- a/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch +++ b/upstream_utils/llvm_patches/0014-Delete-numbers-from-MathExtras.patch @@ -8,12 +8,12 @@ Subject: [PATCH 14/36] Delete numbers from MathExtras 1 file changed, 36 deletions(-) diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 7541447fa2db5e1634d952b1f39957eb725611f4..60b3b9012a32dda5e7c3ba1dc5923ffa68df8215 100644 +index 6028ba8ead7627b4821aa8642f5069b305605c5e..b9084182158757647cc9896320a353a373b0f9ec 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h -@@ -24,42 +24,6 @@ - - namespace llvm { +@@ -40,42 +40,6 @@ template > + using common_sint = + std::common_type_t, std::make_signed_t>; -/// Mathematical constants. -namespace numbers { diff --git a/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch b/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch index 92a744d351b..31848ba7124 100644 --- a/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch +++ b/upstream_utils/llvm_patches/0015-Add-lerp-and-sgn.patch @@ -4,16 +4,16 @@ Date: Tue, 3 May 2022 22:50:24 -0400 Subject: [PATCH 15/36] Add lerp and sgn --- - llvm/include/llvm/Support/MathExtras.h | 20 ++++++++++++++++++++ - 1 file changed, 20 insertions(+) + llvm/include/llvm/Support/MathExtras.h | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index 60b3b9012a32dda5e7c3ba1dc5923ffa68df8215..daa79d99578e934ca001d1de5d2772ff961b8fc3 100644 +index b9084182158757647cc9896320a353a373b0f9ec..4033e032b5979a4f25b4c16f3988fb11087ed6bb 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h -@@ -617,6 +617,26 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { - return UX > (static_cast((std::numeric_limits::max)())) / UY; - } +@@ -751,6 +751,27 @@ using stack_float_t = volatile float; + using stack_float_t = float; + #endif +// Typesafe implementation of the signum function. +// Returns -1 if negative, 1 if positive, 0 if 0. @@ -35,6 +35,7 @@ index 60b3b9012a32dda5e7c3ba1dc5923ffa68df8215..daa79d99578e934ca001d1de5d2772ff +constexpr T Lerp(const T& startValue, const T& endValue, double t) { + return startValue + (endValue - startValue) * t; +} - } // End llvm namespace ++ + } // namespace llvm #endif diff --git a/upstream_utils/llvm_patches/0016-Fixup-includes.patch b/upstream_utils/llvm_patches/0016-Fixup-includes.patch index caa2953a66c..821a9d2d142 100644 --- a/upstream_utils/llvm_patches/0016-Fixup-includes.patch +++ b/upstream_utils/llvm_patches/0016-Fixup-includes.patch @@ -6,12 +6,12 @@ Subject: [PATCH 16/36] Fixup includes --- llvm/include/llvm/Support/PointerLikeTypeTraits.h | 1 + llvm/lib/Support/ConvertUTFWrapper.cpp | 1 + - llvm/lib/Support/ErrorHandling.cpp | 7 +++---- + llvm/lib/Support/ErrorHandling.cpp | 9 ++++----- llvm/lib/Support/raw_ostream.cpp | 11 ++++++----- llvm/unittests/ADT/SmallPtrSetTest.cpp | 2 ++ llvm/unittests/ADT/SmallVectorTest.cpp | 1 + llvm/unittests/Support/ConvertUTFTest.cpp | 2 ++ - 7 files changed, 16 insertions(+), 9 deletions(-) + 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Support/PointerLikeTypeTraits.h b/llvm/include/llvm/Support/PointerLikeTypeTraits.h index 1b15f930bd87d97d51824af5e62ea5f222a6b4c9..acadd5e89a1651cfbad67a5b1b0933d1f288d094 100644 @@ -38,7 +38,7 @@ index d53462e742e61d3476915d5b2c5aa63772e78a8a..34054140489e4d536ace4650207c783d #include "llvm/Support/SwapByteOrder.h" #include diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index 0b87b375de67dc18647e3ebe646bf323dd05e8c5..3a88178cfbbcf7062a958c7de820247bc913ab33 100644 +index c205eab6f5467e3f461a168a596e574e3876f77e..8c22a46cd0f1faa2becb0a686bf1b6fd5b1e46c9 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -28,12 +28,11 @@ @@ -57,8 +57,17 @@ index 0b87b375de67dc18647e3ebe646bf323dd05e8c5..3a88178cfbbcf7062a958c7de820247b #endif using namespace llvm; +@@ -212,7 +211,7 @@ void LLVMResetFatalErrorHandler() { + #ifdef _WIN32 + + #define WIN32_NO_STATUS +-#include "llvm/Support/Windows/WindowsSupport.h" ++#include "Windows/WindowsSupport.h" + #undef WIN32_NO_STATUS + #include + #include diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 5bec803ccc76ce287b7ff3ea037d5e490a7af20c..ae5428825f7f62ad8e742490448d40aea7506990 100644 +index 7086368a3598ccad9502112f734c9ad81252ebec..e173687cafdd04894c27ccd5efb109a7411f1398 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -15,6 +15,8 @@ @@ -96,7 +105,7 @@ index 5bec803ccc76ce287b7ff3ea037d5e490a7af20c..ae5428825f7f62ad8e742490448d40ae using namespace llvm; diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp -index 531f81ab5b3fc1dcff731230f3cb7649cb90aedf..3db8b6e37d31a0a3cc304da8fc4cbbe1d89252b5 100644 +index a6c2b329f072639706aa221feb8c08e33533f813..4c1a144a7a52eb38c7af2d20749901974b29f962 100644 --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp @@ -15,6 +15,8 @@ diff --git a/upstream_utils/llvm_patches/0018-Windows-support.patch b/upstream_utils/llvm_patches/0018-Windows-support.patch index 15e423509bc..8be65a64e25 100644 --- a/upstream_utils/llvm_patches/0018-Windows-support.patch +++ b/upstream_utils/llvm_patches/0018-Windows-support.patch @@ -204,10 +204,10 @@ index bc04c5ab5113563fb82d7b3b168985369b611f4b..57eb64a6017a6964ab14b40b8c6b3563 ConvertUTF_RESTORE_WARNINGS diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index ae5428825f7f62ad8e742490448d40aea7506990..9ea41cad8fed864b53e2e463450c066fb4e00131 100644 +index e173687cafdd04894c27ccd5efb109a7411f1398..6ed93793a64c523102626d581656d2f9509f7d5d 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -535,7 +535,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -532,7 +532,6 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { DWORD WinLastError = GetLastError(); if (WinLastError == ERROR_BROKEN_PIPE || (WinLastError == ERROR_NO_DATA && errno == EINVAL)) { diff --git a/upstream_utils/llvm_patches/0019-Remove-call-to-RtlGetLastNtStatus.patch b/upstream_utils/llvm_patches/0019-Remove-call-to-RtlGetLastNtStatus.patch new file mode 100644 index 00000000000..e5cf079d1f3 --- /dev/null +++ b/upstream_utils/llvm_patches/0019-Remove-call-to-RtlGetLastNtStatus.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Tue, 17 Sep 2024 21:19:52 -0700 +Subject: [PATCH 19/36] Remove call to RtlGetLastNtStatus() + +--- + llvm/lib/Support/ErrorHandling.cpp | 23 ----------------------- + 1 file changed, 23 deletions(-) + +diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp +index 8c22a46cd0f1faa2becb0a686bf1b6fd5b1e46c9..df951849da74091b1a5705c0de483e7497f6e03d 100644 +--- a/llvm/lib/Support/ErrorHandling.cpp ++++ b/llvm/lib/Support/ErrorHandling.cpp +@@ -216,34 +216,11 @@ void LLVMResetFatalErrorHandler() { + #include + #include + +-// This is equivalent to NtCurrentTeb()->LastStatusValue, but the public +-// _TEB definition does not expose the LastStatusValue field directly. +-// Avoid offsetting into this structure by calling RtlGetLastNtStatus +-// from ntdll.dll. +-// +-// The return of this function will roughly match that of +-// GetLastError, but this lower level API disambiguates some cases +-// that GetLastError does not. +-// +-// For more information, see: +-// https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm +-// https://github.com/llvm/llvm-project/issues/89137 +-extern "C" NTSYSAPI NTSTATUS NTAPI RtlGetLastNtStatus(); +- + // This function obtains the last error code and maps it. It may call + // RtlGetLastNtStatus, which is a lower level API that can return a + // more specific error code than GetLastError. + std::error_code llvm::mapLastWindowsError() { + unsigned EV = ::GetLastError(); +- // The mapping of NTSTATUS to Win32 error loses some information; special +- // case the generic ERROR_ACCESS_DENIED code to check the underlying +- // NTSTATUS and potentially return a more accurate error code. +- if (EV == ERROR_ACCESS_DENIED) { +- llvm::errc code = RtlGetLastNtStatus() == STATUS_DELETE_PENDING +- ? errc::delete_pending +- : errc::permission_denied; +- return make_error_code(code); +- } + return mapWindowsError(EV); + } + diff --git a/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch b/upstream_utils/llvm_patches/0020-Prefer-fmtlib.patch similarity index 91% rename from upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch rename to upstream_utils/llvm_patches/0020-Prefer-fmtlib.patch index c2704d278cc..61637316edc 100644 --- a/upstream_utils/llvm_patches/0019-Prefer-fmtlib.patch +++ b/upstream_utils/llvm_patches/0020-Prefer-fmtlib.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:46:20 -0400 -Subject: [PATCH 19/36] Prefer fmtlib +Subject: [PATCH 20/36] Prefer fmtlib --- llvm/lib/Support/ErrorHandling.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index 3a88178cfbbcf7062a958c7de820247bc913ab33..4d992442d153d088f6a7a1fc13e3c84012c45a06 100644 +index df951849da74091b1a5705c0de483e7497f6e03d..f9f2c0047e0193f86ada6b4d9ae5b68445c6a593 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -22,7 +22,7 @@ @@ -37,7 +37,7 @@ index 3a88178cfbbcf7062a958c7de820247bc913ab33..4d992442d153d088f6a7a1fc13e3c840 } // If we reached here, we are failing ungracefully. Run the interrupt handlers -@@ -176,11 +168,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, +@@ -179,11 +171,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, // llvm_unreachable is intended to be used to indicate "impossible" // situations, and not legitimate runtime errors. if (msg) diff --git a/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch b/upstream_utils/llvm_patches/0021-Prefer-wpi-s-fs.h.patch similarity index 87% rename from upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch rename to upstream_utils/llvm_patches/0021-Prefer-wpi-s-fs.h.patch index ad4189436d9..91c66052955 100644 --- a/upstream_utils/llvm_patches/0020-Prefer-wpi-s-fs.h.patch +++ b/upstream_utils/llvm_patches/0021-Prefer-wpi-s-fs.h.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 16:49:36 -0400 -Subject: [PATCH 20/36] Prefer wpi's fs.h +Subject: [PATCH 21/36] Prefer wpi's fs.h --- llvm/include/llvm/Support/raw_ostream.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index e7526e016a858ad728feb7cf1c5014b9691759d4..d56999186f719f8d91f3a047a19960caf62a066c 100644 +index a6799603a0106262520ba1c9fda14a7967b12a63..39a600c2ed7cd1cfecb46ff17929ffcb389207d7 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h @@ -26,18 +26,15 @@ diff --git a/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch b/upstream_utils/llvm_patches/0022-Remove-unused-functions.patch similarity index 89% rename from upstream_utils/llvm_patches/0021-Remove-unused-functions.patch rename to upstream_utils/llvm_patches/0022-Remove-unused-functions.patch index c326bc4cbe1..dc0aae101c0 100644 --- a/upstream_utils/llvm_patches/0021-Remove-unused-functions.patch +++ b/upstream_utils/llvm_patches/0022-Remove-unused-functions.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 19:16:51 -0400 -Subject: [PATCH 21/36] Remove unused functions +Subject: [PATCH 22/36] Remove unused functions --- llvm/include/llvm/Support/raw_ostream.h | 5 +- @@ -11,18 +11,18 @@ Subject: [PATCH 21/36] Remove unused functions 4 files changed, 23 insertions(+), 126 deletions(-) diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index d56999186f719f8d91f3a047a19960caf62a066c..9a9a1f688313a5784a58a70f2cb4cc0d6ec70e79 100644 +index 39a600c2ed7cd1cfecb46ff17929ffcb389207d7..9bb9260eecf35b0f71d144256fc956a80b2da8a3 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h -@@ -70,7 +70,6 @@ private: +@@ -71,7 +71,6 @@ private: /// for a \see write_impl() call to handle the data which has been put into /// this buffer. char *OutBufStart, *OutBufEnd, *OutBufCur; - bool ColorEnabled = false; - /// Optional stream this stream is tied to. If this stream is written to, the - /// tied-to stream will be flushed first. -@@ -317,9 +316,9 @@ public: + enum class BufferKind { + Unbuffered = 0, +@@ -330,9 +329,9 @@ public: // Enable or disable colors. Once enable_colors(false) is called, // changeColor() has no effect until enable_colors(true) is called. @@ -32,13 +32,13 @@ index d56999186f719f8d91f3a047a19960caf62a066c..9a9a1f688313a5784a58a70f2cb4cc0d - bool colors_enabled() const { return ColorEnabled; } + bool colors_enabled() const { return false; } - /// Tie this stream to the specified stream. Replaces any existing tied-to - /// stream. Specifying a nullptr unties the stream. + //===--------------------------------------------------------------------===// + // Subclass Interface diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index 4d992442d153d088f6a7a1fc13e3c84012c45a06..e19a38256ce714359b85076cf49056f379764d8d 100644 +index f9f2c0047e0193f86ada6b4d9ae5b68445c6a593..c699e64f2b5e3aab5465388c2b8a197c57273365 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp -@@ -181,22 +181,6 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, +@@ -184,22 +184,6 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, #endif } @@ -60,9 +60,9 @@ index 4d992442d153d088f6a7a1fc13e3c84012c45a06..e19a38256ce714359b85076cf49056f3 - #ifdef _WIN32 - #include + #define WIN32_NO_STATUS diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a6060eadfee1 100644 +index 6ed93793a64c523102626d581656d2f9509f7d5d..7e9a58db056e315cdcec22af0439017dee737c8f 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -176,16 +176,6 @@ raw_ostream &raw_ostream::write_escaped(std::string_view Str, @@ -82,7 +82,7 @@ index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a606 void raw_ostream::flush_nonempty() { assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); size_t Length = OutBufCur - OutBufStart; -@@ -328,15 +318,22 @@ static int getFD(std::string_view Filename, std::error_code &EC, +@@ -322,15 +312,22 @@ static int getFD(std::string_view Filename, std::error_code &EC, if (Filename == "-") { EC = std::error_code(); // Change stdout's text/binary mode based on the Flags. @@ -110,7 +110,7 @@ index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a606 if (EC) return -1; -@@ -396,12 +393,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, +@@ -390,12 +387,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, // Get the starting position. off_t loc = ::lseek(FD, 0, SEEK_CUR); @@ -124,7 +124,7 @@ index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a606 #else SupportsSeeking = !EC && loc != (off_t)-1; #endif -@@ -414,10 +407,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, +@@ -408,10 +401,8 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered, raw_fd_ostream::~raw_fd_ostream() { if (FD >= 0) { flush(); @@ -137,7 +137,7 @@ index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a606 } #ifdef __MINGW32__ -@@ -512,7 +503,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { +@@ -509,7 +500,11 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { do { size_t ChunkSize = std::min(Size, MaxWriteSize); @@ -149,7 +149,7 @@ index 9ea41cad8fed864b53e2e463450c066fb4e00131..44149e85876f089756dcce151670a606 if (ret < 0) { // If it's a recoverable error, swallow it and retry the write. -@@ -555,8 +550,8 @@ void raw_fd_ostream::close() { +@@ -552,8 +547,8 @@ void raw_fd_ostream::close() { assert(ShouldClose); ShouldClose = false; flush(); diff --git a/upstream_utils/llvm_patches/0022-OS-specific-changes.patch b/upstream_utils/llvm_patches/0023-OS-specific-changes.patch similarity index 87% rename from upstream_utils/llvm_patches/0022-OS-specific-changes.patch rename to upstream_utils/llvm_patches/0023-OS-specific-changes.patch index 91f1302b168..eb353121296 100644 --- a/upstream_utils/llvm_patches/0022-OS-specific-changes.patch +++ b/upstream_utils/llvm_patches/0023-OS-specific-changes.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Sun, 8 May 2022 19:30:43 -0400 -Subject: [PATCH 22/36] OS-specific changes +Subject: [PATCH 23/36] OS-specific changes --- llvm/lib/Support/ErrorHandling.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp -index e19a38256ce714359b85076cf49056f379764d8d..54b1c09d61d43a936373da8d3bb69b9b1325bf48 100644 +index c699e64f2b5e3aab5465388c2b8a197c57273365..8fdbe1a0ceb5c9f270124f9fe78fb78e0fdb7a33 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -96,15 +96,7 @@ void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) { @@ -28,7 +28,7 @@ index e19a38256ce714359b85076cf49056f379764d8d..54b1c09d61d43a936373da8d3bb69b9b } void llvm::install_bad_alloc_error_handler(fatal_error_handler_t handler, -@@ -141,9 +133,15 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { +@@ -144,9 +136,15 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { // an OOM to stderr and abort. const char *OOMMessage = "LLVM ERROR: out of memory\n"; const char *Newline = "\n"; diff --git a/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch b/upstream_utils/llvm_patches/0024-Use-SmallVector-for-UTF-conversion.patch similarity index 99% rename from upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch rename to upstream_utils/llvm_patches/0024-Use-SmallVector-for-UTF-conversion.patch index bb096a2b05f..7b3ef96b2e5 100644 --- a/upstream_utils/llvm_patches/0023-Use-SmallVector-for-UTF-conversion.patch +++ b/upstream_utils/llvm_patches/0024-Use-SmallVector-for-UTF-conversion.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Mon, 9 May 2022 00:04:30 -0400 -Subject: [PATCH 23/36] Use SmallVector for UTF conversion +Subject: [PATCH 24/36] Use SmallVector for UTF conversion --- llvm/include/llvm/Support/ConvertUTF.h | 6 +++--- diff --git a/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch b/upstream_utils/llvm_patches/0025-Prefer-to-use-static-pointers-in-raw_ostream.patch similarity index 79% rename from upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch rename to upstream_utils/llvm_patches/0025-Prefer-to-use-static-pointers-in-raw_ostream.patch index ecab45a58bd..98ab588ed5b 100644 --- a/upstream_utils/llvm_patches/0024-Prefer-to-use-static-pointers-in-raw_ostream.patch +++ b/upstream_utils/llvm_patches/0025-Prefer-to-use-static-pointers-in-raw_ostream.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Thu, 19 May 2022 00:58:36 -0400 -Subject: [PATCH 24/36] Prefer to use static pointers in raw_ostream +Subject: [PATCH 25/36] Prefer to use static pointers in raw_ostream See #1401 --- @@ -9,10 +9,10 @@ See #1401 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 44149e85876f089756dcce151670a6060eadfee1..8fe686142b8cdba76287a3b8b97569fde922f2bf 100644 +index 7e9a58db056e315cdcec22af0439017dee737c8f..b417bebdef3a2f2e12e46e65ad7885d243b477a7 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp -@@ -615,9 +615,9 @@ raw_fd_ostream &llvm::outs() { +@@ -612,9 +612,9 @@ raw_fd_ostream &llvm::outs() { EC = enableAutoConversion(STDOUT_FILENO); assert(!EC); #endif @@ -24,7 +24,7 @@ index 44149e85876f089756dcce151670a6060eadfee1..8fe686142b8cdba76287a3b8b97569fd } raw_fd_ostream &llvm::errs() { -@@ -626,8 +626,8 @@ raw_fd_ostream &llvm::errs() { +@@ -623,8 +623,8 @@ raw_fd_ostream &llvm::errs() { std::error_code EC = enableAutoConversion(STDERR_FILENO); assert(!EC); #endif diff --git a/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch b/upstream_utils/llvm_patches/0026-constexpr-endian-byte-swap.patch similarity index 85% rename from upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch rename to upstream_utils/llvm_patches/0026-constexpr-endian-byte-swap.patch index 5b13f98db01..14cbf252359 100644 --- a/upstream_utils/llvm_patches/0025-constexpr-endian-byte-swap.patch +++ b/upstream_utils/llvm_patches/0026-constexpr-endian-byte-swap.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Fri, 1 Mar 2024 11:56:17 -0800 -Subject: [PATCH 25/36] constexpr endian byte swap +Subject: [PATCH 26/36] constexpr endian byte swap --- llvm/include/llvm/Support/Endian.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h -index 4c0405cf1e2f69c6268d708badc2aef6dd968b51..f31fbf70fb723d19634e61ea4f21549fc767e58c 100644 +index 5831fe66a1f7b71f26aac179c4e2c904d0ad4255..62e19c04e5dc565dd94c5c38f7c6b141fbcb56a3 100644 --- a/llvm/include/llvm/Support/Endian.h +++ b/llvm/include/llvm/Support/Endian.h @@ -50,7 +50,9 @@ template diff --git a/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch b/upstream_utils/llvm_patches/0027-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch similarity index 97% rename from upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch rename to upstream_utils/llvm_patches/0027-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch index 28831db7bc6..a36d168a929 100644 --- a/upstream_utils/llvm_patches/0026-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch +++ b/upstream_utils/llvm_patches/0027-Copy-type-traits-from-STLExtras.h-into-PointerUnion..patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 10 Aug 2022 17:07:52 -0700 -Subject: [PATCH 26/36] Copy type traits from STLExtras.h into PointerUnion.h +Subject: [PATCH 27/36] Copy type traits from STLExtras.h into PointerUnion.h --- llvm/include/llvm/ADT/PointerUnion.h | 46 ++++++++++++++++++++++++++++ diff --git a/upstream_utils/llvm_patches/0027-Unused-variable-in-release-mode.patch b/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch similarity index 85% rename from upstream_utils/llvm_patches/0027-Unused-variable-in-release-mode.patch rename to upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch index 252180c3f3a..6f523d657a1 100644 --- a/upstream_utils/llvm_patches/0027-Unused-variable-in-release-mode.patch +++ b/upstream_utils/llvm_patches/0028-Unused-variable-in-release-mode.patch @@ -1,14 +1,14 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 10 Jul 2023 00:53:43 +0200 -Subject: [PATCH 27/36] Unused variable in release mode +Subject: [PATCH 28/36] Unused variable in release mode --- llvm/include/llvm/ADT/DenseMap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h -index 108193f04486425f3b7f039cd9d2004be6facafb..e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65 100644 +index c4764fffa845a7f9eb69f262aa0ee728d08b1655..e77fa3bade8133ae73fd271a582d8500269bfe7e 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -124,7 +124,7 @@ public: diff --git a/upstream_utils/llvm_patches/0028-Use-C-20-bit-header.patch b/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch similarity index 94% rename from upstream_utils/llvm_patches/0028-Use-C-20-bit-header.patch rename to upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch index 58377691687..b39012d60e3 100644 --- a/upstream_utils/llvm_patches/0028-Use-C-20-bit-header.patch +++ b/upstream_utils/llvm_patches/0029-Use-C-20-bit-header.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 11 Jul 2023 22:56:09 -0700 -Subject: [PATCH 28/36] Use C++20 header +Subject: [PATCH 29/36] Use C++20 header --- llvm/include/llvm/ADT/DenseMap.h | 3 +- @@ -11,7 +11,7 @@ Subject: [PATCH 28/36] Use C++20 header 4 files changed, 31 insertions(+), 341 deletions(-) diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h -index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bdce659e9d 100644 +index e77fa3bade8133ae73fd271a582d8500269bfe7e..bf39eaf5ac230221defcdd1b7711b77089d05642 100644 --- a/llvm/include/llvm/ADT/DenseMap.h +++ b/llvm/include/llvm/ADT/DenseMap.h @@ -23,6 +23,7 @@ @@ -22,7 +22,7 @@ index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bd #include #include #include -@@ -933,7 +934,7 @@ class SmallDenseMap +@@ -949,7 +950,7 @@ class SmallDenseMap public: explicit SmallDenseMap(unsigned NumInitBuckets = 0) { if (NumInitBuckets > InlineBuckets) @@ -32,10 +32,10 @@ index e9bd3bfa4a6fe0fa26ff20069bbadc816c8baa65..93b50c9e53af4ea3af5fd0329a8a03bd } diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h -index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe4a79f936 100644 +index a33c6eec308c8722f88b09f73f954d39558c3d62..36b4d4b58b414bd6f61437fb597cd596cb16e66f 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h -@@ -49,6 +49,7 @@ +@@ -50,6 +50,7 @@ #include "llvm/Support/SwapByteOrder.h" #include "llvm/Support/type_traits.h" #include @@ -43,7 +43,7 @@ index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe #include #include #include -@@ -224,30 +225,30 @@ inline uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed) { +@@ -208,30 +209,30 @@ inline uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed) { uint64_t b = fetch64(s + 8); uint64_t c = fetch64(s + len - 8) * k2; uint64_t d = fetch64(s + len - 16) * k0; @@ -85,7 +85,7 @@ index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe uint64_t r = shift_mix((vf + ws) * k2 + (wf + vs) * k0); return shift_mix((seed ^ (r * k0)) + vs) * k2; } -@@ -280,7 +281,7 @@ struct hash_state { +@@ -264,7 +265,7 @@ struct hash_state { hash_state state = {0, seed, hash_16_bytes(seed, k1), @@ -94,7 +94,7 @@ index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe seed * k1, shift_mix(seed), 0}; -@@ -294,10 +295,10 @@ struct hash_state { +@@ -278,10 +279,10 @@ struct hash_state { static void mix_32_bytes(const char *s, uint64_t &a, uint64_t &b) { a += fetch64(s); uint64_t c = fetch64(s + 24); @@ -107,7 +107,7 @@ index 08d6edb14eb3cd51405329aae61b9782266a2590..e84d53e6bf2f741be562b9d66bf0bdfe a += c; } -@@ -305,11 +306,11 @@ struct hash_state { +@@ -289,11 +290,11 @@ struct hash_state { /// We mix all 64 bytes even when the chunk length is smaller, but we /// record the actual length. void mix(const char *s) { @@ -454,7 +454,7 @@ index c42b5e686bdc9cf3da71d8edaddc08216fe5fb2a..a19b6a9b80da2965f1308d3e7b0ade59 #endif diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h -index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb1d9bb985 100644 +index 4033e032b5979a4f25b4c16f3988fb11087ed6bb..219f8894849e80ee70a4b4cf40194682740ec865 100644 --- a/llvm/include/llvm/Support/MathExtras.h +++ b/llvm/include/llvm/Support/MathExtras.h @@ -15,6 +15,7 @@ @@ -465,22 +465,22 @@ index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb #include #include #include -@@ -235,12 +236,12 @@ constexpr inline bool isShiftedMask_64(uint64_t Value) { +@@ -262,12 +263,12 @@ constexpr bool isShiftedMask_64(uint64_t Value) { /// Return true if the argument is a power of two > 0. /// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) - constexpr inline bool isPowerOf2_32(uint32_t Value) { + constexpr bool isPowerOf2_32(uint32_t Value) { - return llvm::has_single_bit(Value); + return std::has_single_bit(Value); } /// Return true if the argument is a power of two > 0 (64 bit edition.) - constexpr inline bool isPowerOf2_64(uint64_t Value) { + constexpr bool isPowerOf2_64(uint64_t Value) { - return llvm::has_single_bit(Value); + return std::has_single_bit(Value); } /// Return true if the argument contains a non-empty sequence of ones with the -@@ -252,8 +253,8 @@ inline bool isShiftedMask_32(uint32_t Value, unsigned &MaskIdx, +@@ -279,8 +280,8 @@ inline bool isShiftedMask_32(uint32_t Value, unsigned &MaskIdx, unsigned &MaskLen) { if (!isShiftedMask_32(Value)) return false; @@ -491,7 +491,7 @@ index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb return true; } -@@ -265,8 +266,8 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx, +@@ -292,8 +293,8 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx, unsigned &MaskLen) { if (!isShiftedMask_64(Value)) return false; @@ -502,7 +502,7 @@ index daa79d99578e934ca001d1de5d2772ff961b8fc3..f66e64b601d01f17dc6c7a4e568cc4eb return true; } -@@ -284,26 +285,26 @@ template <> constexpr inline size_t CTLog2<1>() { return 0; } +@@ -311,26 +312,26 @@ template <> constexpr size_t CTLog2<1>() { return 0; } /// (32 bit edition.) /// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1, Log2_32(6) == 2 inline unsigned Log2_32(uint32_t Value) { diff --git a/upstream_utils/llvm_patches/0029-Remove-DenseMap-GTest-printer-test.patch b/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch similarity index 80% rename from upstream_utils/llvm_patches/0029-Remove-DenseMap-GTest-printer-test.patch rename to upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch index f99bf819988..688940ff26a 100644 --- a/upstream_utils/llvm_patches/0029-Remove-DenseMap-GTest-printer-test.patch +++ b/upstream_utils/llvm_patches/0030-Remove-DenseMap-GTest-printer-test.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 30 Jul 2023 14:17:37 -0700 -Subject: [PATCH 29/36] Remove DenseMap GTest printer test +Subject: [PATCH 30/36] Remove DenseMap GTest printer test LLVM modifies internal GTest headers to support it, which we can't do. --- @@ -9,10 +9,10 @@ LLVM modifies internal GTest headers to support it, which we can't do. 1 file changed, 7 deletions(-) diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp -index 1f232d3046292c0da940ba4bef7d50604556e4c2..8d90d5afea79c619590cc32539e5124d02b1349c 100644 +index b930a21f8b43b64835436fcd27f4802a7987827f..b49100899c658fa952d37e526880913d57d07c5c 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp -@@ -737,11 +737,4 @@ TEST(DenseMapCustomTest, VariantSupport) { +@@ -761,11 +761,4 @@ TEST(DenseMapCustomTest, VariantSupport) { EXPECT_FALSE(DenseMapInfo::isEqual(Keys[2], Keys[2])); } diff --git a/upstream_utils/llvm_patches/0030-Replace-deprecated-std-aligned_storage_t.patch b/upstream_utils/llvm_patches/0030-Replace-deprecated-std-aligned_storage_t.patch deleted file mode 100644 index d4746e17fd5..00000000000 --- a/upstream_utils/llvm_patches/0030-Replace-deprecated-std-aligned_storage_t.patch +++ /dev/null @@ -1,31 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tyler Veness -Date: Fri, 15 Sep 2023 18:26:50 -0700 -Subject: [PATCH 30/36] Replace deprecated std::aligned_storage_t - ---- - llvm/include/llvm/ADT/FunctionExtras.h | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h -index 043d8d90fff03d571a923c264b49be37a5dffa09..a62d5ce00d784def5ae21b8d91cea40cee7bf942 100644 ---- a/llvm/include/llvm/ADT/FunctionExtras.h -+++ b/llvm/include/llvm/ADT/FunctionExtras.h -@@ -38,6 +38,7 @@ - #include "llvm/Support/Compiler.h" - #include "llvm/Support/MemAlloc.h" - #include "llvm/Support/type_traits.h" -+#include - #include - #include - #include -@@ -168,8 +169,7 @@ protected: - // provide four pointers worth of storage here. - // This is mutable as an inlined `const unique_function` may - // still modify its own mutable members. -- mutable std::aligned_storage_t -- InlineStorage; -+ alignas(void*) mutable std::byte InlineStorage[InlineStorageSize]; - } StorageUnion; - - // A compressed pointer to either our dispatching callback or our table of diff --git a/upstream_utils/llvm_patches/0031-raw_ostream-Add-SetNumBytesInBuffer.patch b/upstream_utils/llvm_patches/0031-raw_ostream-Add-SetNumBytesInBuffer.patch index d3955d000bd..4a54a15a178 100644 --- a/upstream_utils/llvm_patches/0031-raw_ostream-Add-SetNumBytesInBuffer.patch +++ b/upstream_utils/llvm_patches/0031-raw_ostream-Add-SetNumBytesInBuffer.patch @@ -8,10 +8,10 @@ Subject: [PATCH 31/36] raw_ostream: Add SetNumBytesInBuffer 1 file changed, 5 insertions(+) diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h -index 9a9a1f688313a5784a58a70f2cb4cc0d6ec70e79..d832bcb97b4131a08ba3692eb438455e4c9764e4 100644 +index 9bb9260eecf35b0f71d144256fc956a80b2da8a3..c5765a05fb493c6a5bb6b619f0fbdb8d986e21ed 100644 --- a/llvm/include/llvm/Support/raw_ostream.h +++ b/llvm/include/llvm/Support/raw_ostream.h -@@ -356,6 +356,11 @@ protected: +@@ -365,6 +365,11 @@ protected: SetBufferAndMode(BufferStart, Size, BufferKind::ExternalBuffer); } diff --git a/upstream_utils/llvm_patches/0032-raw_ostream-Replace-errnoAsErrorCode.patch b/upstream_utils/llvm_patches/0032-raw_ostream-Replace-errnoAsErrorCode.patch new file mode 100644 index 00000000000..3c0d269eab4 --- /dev/null +++ b/upstream_utils/llvm_patches/0032-raw_ostream-Replace-errnoAsErrorCode.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Tyler Veness +Date: Tue, 17 Sep 2024 15:30:31 -0700 +Subject: [PATCH 32/36] raw_ostream: Replace errnoAsErrorCode() + +--- + llvm/lib/Support/raw_ostream.cpp | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp +index b417bebdef3a2f2e12e46e65ad7885d243b477a7..0330f8da01341a9b78a2e5e73e74d696285fbb51 100644 +--- a/llvm/lib/Support/raw_ostream.cpp ++++ b/llvm/lib/Support/raw_ostream.cpp +@@ -531,7 +531,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { + } + #endif + // Otherwise it's a non-recoverable error. Note it and quit. +- error_detected(errnoAsErrorCode()); ++ error_detected(std::error_code(errno, std::generic_category())); + break; + } + +@@ -561,7 +561,7 @@ uint64_t raw_fd_ostream::seek(uint64_t off) { + pos = ::lseek(FD, off, SEEK_SET); + #endif + if (pos == (uint64_t)-1) +- error_detected(errnoAsErrorCode()); ++ error_detected(std::error_code(errno, std::generic_category())); + return pos; + } + diff --git a/upstream_utils/llvm_patches/0033-Add-back-removed-raw_string_ostream-write_impl.patch b/upstream_utils/llvm_patches/0033-Add-back-removed-raw_string_ostream-write_impl.patch deleted file mode 100644 index 8ec4eaf0be0..00000000000 --- a/upstream_utils/llvm_patches/0033-Add-back-removed-raw_string_ostream-write_impl.patch +++ /dev/null @@ -1,28 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Tyler Veness -Date: Fri, 1 Mar 2024 11:37:36 -0800 -Subject: [PATCH 33/36] Add back removed raw_string_ostream::write_impl() - ---- - llvm/lib/Support/raw_ostream.cpp | 8 ++++++++ - 1 file changed, 8 insertions(+) - -diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 8fe686142b8cdba76287a3b8b97569fde922f2bf..9134f3d3db220ec5afb87b72cb9aed76c52a80ca 100644 ---- a/llvm/lib/Support/raw_ostream.cpp -+++ b/llvm/lib/Support/raw_ostream.cpp -@@ -656,6 +656,14 @@ bool raw_fd_stream::classof(const raw_ostream *OS) { - return OS->get_kind() == OStreamKind::OK_FDStream; - } - -+//===----------------------------------------------------------------------===// -+// raw_string_ostream -+//===----------------------------------------------------------------------===// -+ -+void raw_string_ostream::write_impl(const char *Ptr, size_t Size) { -+ OS.append(Ptr, Size); -+} -+ - //===----------------------------------------------------------------------===// - // raw_svector_ostream - //===----------------------------------------------------------------------===// diff --git a/upstream_utils/llvm_patches/0032-type_traits.h-Add-is_constexpr.patch b/upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch similarity index 94% rename from upstream_utils/llvm_patches/0032-type_traits.h-Add-is_constexpr.patch rename to upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch index 5c5e3208b92..1b2497e7d66 100644 --- a/upstream_utils/llvm_patches/0032-type_traits.h-Add-is_constexpr.patch +++ b/upstream_utils/llvm_patches/0033-type_traits.h-Add-is_constexpr.patch @@ -1,7 +1,7 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 2 Dec 2023 15:21:32 -0800 -Subject: [PATCH 32/36] type_traits.h: Add is_constexpr() +Subject: [PATCH 33/36] type_traits.h: Add is_constexpr() --- llvm/include/llvm/Support/type_traits.h | 5 +++++ diff --git a/upstream_utils/llvm_patches/0034-Remove-auto-conversion-from-raw_ostream.patch b/upstream_utils/llvm_patches/0034-Remove-auto-conversion-from-raw_ostream.patch index b0fa86f2fbd..f6d52db9b1f 100644 --- a/upstream_utils/llvm_patches/0034-Remove-auto-conversion-from-raw_ostream.patch +++ b/upstream_utils/llvm_patches/0034-Remove-auto-conversion-from-raw_ostream.patch @@ -4,11 +4,11 @@ Date: Sun, 17 Mar 2024 14:51:11 -0700 Subject: [PATCH 34/36] Remove auto-conversion from raw_ostream --- - llvm/lib/Support/raw_ostream.cpp | 9 --------- - 1 file changed, 9 deletions(-) + llvm/lib/Support/raw_ostream.cpp | 11 +---------- + 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp -index 9134f3d3db220ec5afb87b72cb9aed76c52a80ca..efba615e1b77de335ab343cc56ce9b00ccf3f462 100644 +index 0330f8da01341a9b78a2e5e73e74d696285fbb51..46c277c461868ee291eedc764f4b5609b3903312 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -19,7 +19,6 @@ @@ -19,7 +19,7 @@ index 9134f3d3db220ec5afb87b72cb9aed76c52a80ca..efba615e1b77de335ab343cc56ce9b00 #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" -@@ -611,10 +610,6 @@ void raw_fd_ostream::anchor() {} +@@ -608,21 +607,13 @@ void raw_fd_ostream::anchor() {} raw_fd_ostream &llvm::outs() { // Set buffer settings to model stdout behavior. std::error_code EC; @@ -30,14 +30,15 @@ index 9134f3d3db220ec5afb87b72cb9aed76c52a80ca..efba615e1b77de335ab343cc56ce9b00 static raw_fd_ostream* S = new raw_fd_ostream("-", EC, sys::fs::OF_None); assert(!EC); return *S; -@@ -622,10 +617,6 @@ raw_fd_ostream &llvm::outs() { + } raw_fd_ostream &llvm::errs() { - // Set standard error to be unbuffered and tied to outs() by default. +- // Set standard error to be unbuffered. -#ifdef __MVS__ - std::error_code EC = enableAutoConversion(STDERR_FILENO); - assert(!EC); -#endif ++ // Set standard error to be unbuffered and tied to outs() by default. static raw_fd_ostream* S = new raw_fd_ostream(STDERR_FILENO, false, true); return *S; } diff --git a/upstream_utils/llvm_patches/0035-Add-SmallVector-erase_if.patch b/upstream_utils/llvm_patches/0035-Add-SmallVector-erase_if.patch index 5e7c254c040..1478e3c2e6b 100644 --- a/upstream_utils/llvm_patches/0035-Add-SmallVector-erase_if.patch +++ b/upstream_utils/llvm_patches/0035-Add-SmallVector-erase_if.patch @@ -8,10 +8,10 @@ Subject: [PATCH 35/36] Add SmallVector erase_if() 1 file changed, 8 insertions(+) diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h -index b953ae45a34772eb7fd04c3af0275a7d093e1242..f4ec2d673e0edac516dd605e7aebbf7dd9d99cc5 100644 +index 6b12ea17aaa894dc9a719ade4c41a3f7df4304e9..2d53728f3ce621beb578a0ad9e8d6176b5d0eb66 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h -@@ -1328,6 +1328,14 @@ template SmallVector to_vector_of(R &&Range) { +@@ -1329,6 +1329,14 @@ template SmallVector to_vector_of(R &&Range) { return {std::begin(Range), std::end(Range)}; } diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/ErrorHandling.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/ErrorHandling.cpp index dce4ae6514e..60837ee1d37 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/ErrorHandling.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/ErrorHandling.cpp @@ -94,8 +94,11 @@ void wpi::report_fatal_error(std::string_view Reason, bool GenCrashDiag) { void wpi::install_bad_alloc_error_handler(fatal_error_handler_t handler, void *user_data) { +#if LLVM_ENABLE_THREADS == 1 std::scoped_lock Lock(BadAllocErrorHandlerMutex); - assert(!ErrorHandler && "Bad alloc error handler already registered!\n"); +#endif + assert(!BadAllocErrorHandler && + "Bad alloc error handler already registered!\n"); BadAllocErrorHandler = handler; BadAllocErrorHandlerUserData = user_data; } @@ -174,8 +177,20 @@ void wpi::wpi_unreachable_internal(const char *msg, const char *file, #ifdef _WIN32 +#define WIN32_NO_STATUS +#include "Windows/WindowsSupport.h" +#undef WIN32_NO_STATUS +#include #include +// This function obtains the last error code and maps it. It may call +// RtlGetLastNtStatus, which is a lower level API that can return a +// more specific error code than GetLastError. +std::error_code wpi::mapLastWindowsError() { + unsigned EV = ::GetLastError(); + return mapWindowsError(EV); +} + // I'd rather not double the line count of the following. #define MAP_ERR_TO_COND(x, y) \ case x: \ diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/Hashing.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/Hashing.cpp deleted file mode 100644 index a719d3ffd99..00000000000 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/Hashing.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//===-------------- lib/Support/Hashing.cpp -------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file provides implementation bits for the LLVM common hashing -// infrastructure. Documentation and most of the other information is in the -// header file. -// -//===----------------------------------------------------------------------===// - -#include "wpi/Hashing.h" - -using namespace wpi; - -// Provide a definition and static initializer for the fixed seed. This -// initializer should always be zero to ensure its value can never appear to be -// non-zero, even during dynamic initialization. -uint64_t wpi::hashing::detail::fixed_seed_override = 0; - -// Implement the function for forced setting of the fixed seed. -// FIXME: Use atomic operations here so that there is no data race. -void wpi::set_fixed_execution_hash_seed(uint64_t fixed_value) { - hashing::detail::fixed_seed_override = fixed_value; -} diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp index ba5bf131253..15c5c84dce9 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/raw_ostream.cpp @@ -172,7 +172,7 @@ void raw_ostream::flush_nonempty() { assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty."); size_t Length = OutBufCur - OutBufStart; OutBufCur = OutBufStart; - flush_tied_then_write(OutBufStart, Length); + write_impl(OutBufStart, Length); } raw_ostream &raw_ostream::write(unsigned char C) { @@ -180,7 +180,7 @@ raw_ostream &raw_ostream::write(unsigned char C) { if (LLVM_UNLIKELY(OutBufCur >= OutBufEnd)) { if (LLVM_UNLIKELY(!OutBufStart)) { if (BufferMode == BufferKind::Unbuffered) { - flush_tied_then_write(reinterpret_cast(&C), 1); + write_impl(reinterpret_cast(&C), 1); return *this; } // Set up a buffer and start over. @@ -200,7 +200,7 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { if (LLVM_UNLIKELY(size_t(OutBufEnd - OutBufCur) < Size)) { if (LLVM_UNLIKELY(!OutBufStart)) { if (BufferMode == BufferKind::Unbuffered) { - flush_tied_then_write(Ptr, Size); + write_impl(Ptr, Size); return *this; } // Set up a buffer and start over. @@ -216,7 +216,7 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { if (LLVM_UNLIKELY(OutBufCur == OutBufStart)) { assert(NumBytes != 0 && "undefined behavior"); size_t BytesToWrite = Size - (Size % NumBytes); - flush_tied_then_write(Ptr, BytesToWrite); + write_impl(Ptr, BytesToWrite); size_t BytesRemaining = Size - BytesToWrite; if (BytesRemaining > size_t(OutBufEnd - OutBufCur)) { // Too much left over to copy into our buffer. @@ -257,12 +257,6 @@ void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) { OutBufCur += Size; } -void raw_ostream::flush_tied_then_write(const char *Ptr, size_t Size) { - if (TiedStream) - TiedStream->flush(); - write_impl(Ptr, Size); -} - template static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) { static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, @@ -471,6 +465,9 @@ static bool write_console_impl(int FD, std::string_view Data) { #endif void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { + if (TiedStream) + TiedStream->flush(); + assert(FD >= 0 && "File already closed."); pos += Size; @@ -663,6 +660,10 @@ void raw_svector_ostream::pwrite_impl(const char *Ptr, size_t Size, memcpy(OS.data() + Offset, Ptr, Size); } +bool raw_svector_ostream::classof(const raw_ostream *OS) { + return OS->get_kind() == OStreamKind::OK_SVecStream; +} + //===----------------------------------------------------------------------===// // raw_vector_ostream //===----------------------------------------------------------------------===// diff --git a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/xxhash.cpp b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/xxhash.cpp index 323e8354dde..5f54087f231 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/xxhash.cpp +++ b/wpiutil/src/main/native/thirdparty/llvm/cpp/llvm/xxhash.cpp @@ -1,36 +1,36 @@ /* -* xxHash - Fast Hash algorithm -* Copyright (C) 2012-2021, Yann Collet -* -* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following disclaimer -* in the documentation and/or other materials provided with the -* distribution. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -* You can contact the author at : -* - xxHash homepage: http://www.xxhash.com -* - xxHash source repository : https://github.com/Cyan4973/xxHash -*/ + * xxHash - Extremely Fast Hash algorithm + * Copyright (C) 2012-2023, Yann Collet + * + * BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * You can contact the author at : + * - xxHash homepage: http://www.xxhash.com + * - xxHash source repository : https://github.com/Cyan4973/xxHash + */ // xxhash64 is based on commit d2df04efcbef7d7f6886d345861e5dfda4edacc1. Removed // everything but a simple interface for computing xxh64. @@ -38,12 +38,28 @@ // xxh3_64bits is based on commit d5891596637d21366b9b1dcf2c0007a3edb26a9e (July // 2023). +// xxh3_128bits is based on commit b0adcc54188c3130b1793e7b19c62eb1e669f7df +// (June 2024). + #include "wpi/xxhash.h" #include "wpi/Compiler.h" #include "wpi/Endian.h" #include +#if !defined(LLVM_XXH_USE_NEON) +#if (defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) && \ + !defined(__ARM_BIG_ENDIAN) +#define LLVM_XXH_USE_NEON 1 +#else +#define LLVM_XXH_USE_NEON 0 +#endif +#endif + +#if LLVM_XXH_USE_NEON +#include +#endif + using namespace wpi; using namespace support; @@ -297,12 +313,12 @@ static uint64_t XXH3_len_17to128_64b(const uint8_t *input, size_t len, } constexpr size_t XXH3_MIDSIZE_MAX = 240; +constexpr size_t XXH3_MIDSIZE_STARTOFFSET = 3; +constexpr size_t XXH3_MIDSIZE_LASTOFFSET = 17; LLVM_ATTRIBUTE_NOINLINE static uint64_t XXH3_len_129to240_64b(const uint8_t *input, size_t len, const uint8_t *secret, uint64_t seed) { - constexpr size_t XXH3_MIDSIZE_STARTOFFSET = 3; - constexpr size_t XXH3_MIDSIZE_LASTOFFSET = 17; uint64_t acc = (uint64_t)len * PRIME64_1; const unsigned nbRounds = len / 16; for (unsigned i = 0; i < 8; ++i) @@ -320,6 +336,144 @@ static uint64_t XXH3_len_129to240_64b(const uint8_t *input, size_t len, return XXH3_avalanche(acc); } +#if LLVM_XXH_USE_NEON + +#define XXH3_accumulate_512 XXH3_accumulate_512_neon +#define XXH3_scrambleAcc XXH3_scrambleAcc_neon + +// NEON implementation based on commit a57f6cce2698049863af8c25787084ae0489d849 +// (July 2024), with the following removed: +// - workaround for suboptimal codegen on older GCC +// - compiler barriers against instruction reordering +// - WebAssembly SIMD support +// - configurable split between NEON and scalar lanes (benchmarking shows no +// penalty when fully doing SIMD on the Apple M1) + +#if defined(__GNUC__) || defined(__clang__) +#define XXH_ALIASING __attribute__((__may_alias__)) +#else +#define XXH_ALIASING /* nothing */ +#endif + +typedef uint64x2_t xxh_aliasing_uint64x2_t XXH_ALIASING; + +LLVM_ATTRIBUTE_ALWAYS_INLINE static uint64x2_t XXH_vld1q_u64(void const *ptr) { + return vreinterpretq_u64_u8(vld1q_u8((uint8_t const *)ptr)); +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE +static void XXH3_accumulate_512_neon(uint64_t *acc, const uint8_t *input, + const uint8_t *secret) { + xxh_aliasing_uint64x2_t *const xacc = (xxh_aliasing_uint64x2_t *)acc; + +#ifdef __clang__ +#pragma clang loop unroll(full) +#endif + for (size_t i = 0; i < XXH_ACC_NB / 2; i += 2) { + /* data_vec = input[i]; */ + uint64x2_t data_vec_1 = XXH_vld1q_u64(input + (i * 16)); + uint64x2_t data_vec_2 = XXH_vld1q_u64(input + ((i + 1) * 16)); + + /* key_vec = secret[i]; */ + uint64x2_t key_vec_1 = XXH_vld1q_u64(secret + (i * 16)); + uint64x2_t key_vec_2 = XXH_vld1q_u64(secret + ((i + 1) * 16)); + + /* data_swap = swap(data_vec) */ + uint64x2_t data_swap_1 = vextq_u64(data_vec_1, data_vec_1, 1); + uint64x2_t data_swap_2 = vextq_u64(data_vec_2, data_vec_2, 1); + + /* data_key = data_vec ^ key_vec; */ + uint64x2_t data_key_1 = veorq_u64(data_vec_1, key_vec_1); + uint64x2_t data_key_2 = veorq_u64(data_vec_2, key_vec_2); + + /* + * If we reinterpret the 64x2 vectors as 32x4 vectors, we can use a + * de-interleave operation for 4 lanes in 1 step with `vuzpq_u32` to + * get one vector with the low 32 bits of each lane, and one vector + * with the high 32 bits of each lane. + * + * The intrinsic returns a double vector because the original ARMv7-a + * instruction modified both arguments in place. AArch64 and SIMD128 emit + * two instructions from this intrinsic. + * + * [ dk11L | dk11H | dk12L | dk12H ] -> [ dk11L | dk12L | dk21L | dk22L ] + * [ dk21L | dk21H | dk22L | dk22H ] -> [ dk11H | dk12H | dk21H | dk22H ] + */ + uint32x4x2_t unzipped = vuzpq_u32(vreinterpretq_u32_u64(data_key_1), + vreinterpretq_u32_u64(data_key_2)); + + /* data_key_lo = data_key & 0xFFFFFFFF */ + uint32x4_t data_key_lo = unzipped.val[0]; + /* data_key_hi = data_key >> 32 */ + uint32x4_t data_key_hi = unzipped.val[1]; + + /* + * Then, we can split the vectors horizontally and multiply which, as for + * most widening intrinsics, have a variant that works on both high half + * vectors for free on AArch64. A similar instruction is available on + * SIMD128. + * + * sum = data_swap + (u64x2) data_key_lo * (u64x2) data_key_hi + */ + uint64x2_t sum_1 = vmlal_u32(data_swap_1, vget_low_u32(data_key_lo), + vget_low_u32(data_key_hi)); + uint64x2_t sum_2 = vmlal_u32(data_swap_2, vget_high_u32(data_key_lo), + vget_high_u32(data_key_hi)); + + /* xacc[i] = acc_vec + sum; */ + xacc[i] = vaddq_u64(xacc[i], sum_1); + xacc[i + 1] = vaddq_u64(xacc[i + 1], sum_2); + } +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE +static void XXH3_scrambleAcc_neon(uint64_t *acc, const uint8_t *secret) { + xxh_aliasing_uint64x2_t *const xacc = (xxh_aliasing_uint64x2_t *)acc; + + /* { prime32_1, prime32_1 } */ + uint32x2_t const kPrimeLo = vdup_n_u32(PRIME32_1); + /* { 0, prime32_1, 0, prime32_1 } */ + uint32x4_t const kPrimeHi = + vreinterpretq_u32_u64(vdupq_n_u64((uint64_t)PRIME32_1 << 32)); + + for (size_t i = 0; i < XXH_ACC_NB / 2; ++i) { + /* xacc[i] ^= (xacc[i] >> 47); */ + uint64x2_t acc_vec = XXH_vld1q_u64(acc + (2 * i)); + uint64x2_t shifted = vshrq_n_u64(acc_vec, 47); + uint64x2_t data_vec = veorq_u64(acc_vec, shifted); + + /* xacc[i] ^= secret[i]; */ + uint64x2_t key_vec = XXH_vld1q_u64(secret + (i * 16)); + uint64x2_t data_key = veorq_u64(data_vec, key_vec); + + /* + * xacc[i] *= XXH_PRIME32_1 + * + * Expanded version with portable NEON intrinsics + * + * lo(x) * lo(y) + (hi(x) * lo(y) << 32) + * + * prod_hi = hi(data_key) * lo(prime) << 32 + * + * Since we only need 32 bits of this multiply a trick can be used, + * reinterpreting the vector as a uint32x4_t and multiplying by + * { 0, prime, 0, prime } to cancel out the unwanted bits and avoid the + * shift. + */ + uint32x4_t prod_hi = vmulq_u32(vreinterpretq_u32_u64(data_key), kPrimeHi); + + /* Extract low bits for vmlal_u32 */ + uint32x2_t data_key_lo = vmovn_u64(data_key); + + /* xacc[i] = prod_hi + lo(data_key) * XXH_PRIME32_1; */ + xacc[i] = vmlal_u32(vreinterpretq_u64_u32(prod_hi), data_key_lo, kPrimeLo); + } +} +#else + +#define XXH3_accumulate_512 XXH3_accumulate_512_scalar +#define XXH3_scrambleAcc XXH3_scrambleAcc_scalar + LLVM_ATTRIBUTE_ALWAYS_INLINE static void XXH3_accumulate_512_scalar(uint64_t *acc, const uint8_t *input, const uint8_t *secret) { @@ -332,20 +486,23 @@ static void XXH3_accumulate_512_scalar(uint64_t *acc, const uint8_t *input, } LLVM_ATTRIBUTE_ALWAYS_INLINE -static void XXH3_accumulate_scalar(uint64_t *acc, const uint8_t *input, - const uint8_t *secret, size_t nbStripes) { - for (size_t n = 0; n < nbStripes; ++n) - XXH3_accumulate_512_scalar(acc, input + n * XXH_STRIPE_LEN, - secret + n * XXH_SECRET_CONSUME_RATE); -} - -static void XXH3_scrambleAcc(uint64_t *acc, const uint8_t *secret) { +static void XXH3_scrambleAcc_scalar(uint64_t *acc, const uint8_t *secret) { for (size_t i = 0; i < XXH_ACC_NB; ++i) { acc[i] ^= acc[i] >> 47; acc[i] ^= endian::read64le(secret + 8 * i); acc[i] *= PRIME32_1; } } +#endif + +LLVM_ATTRIBUTE_ALWAYS_INLINE +static void XXH3_accumulate(uint64_t *acc, const uint8_t *input, + const uint8_t *secret, size_t nbStripes) { + for (size_t n = 0; n < nbStripes; ++n) { + XXH3_accumulate_512(acc, input + n * XXH_STRIPE_LEN, + secret + n * XXH_SECRET_CONSUME_RATE); + } +} static uint64_t XXH3_mix2Accs(const uint64_t *acc, const uint8_t *secret) { return XXH3_mul128_fold64(acc[0] ^ endian::read64le(secret), @@ -372,21 +529,20 @@ static uint64_t XXH3_hashLong_64b(const uint8_t *input, size_t len, PRIME64_4, PRIME32_2, PRIME64_5, PRIME32_1, }; for (size_t n = 0; n < nb_blocks; ++n) { - XXH3_accumulate_scalar(acc, input + n * block_len, secret, - nbStripesPerBlock); + XXH3_accumulate(acc, input + n * block_len, secret, nbStripesPerBlock); XXH3_scrambleAcc(acc, secret + secretSize - XXH_STRIPE_LEN); } /* last partial block */ const size_t nbStripes = (len - 1 - (block_len * nb_blocks)) / XXH_STRIPE_LEN; assert(nbStripes <= secretSize / XXH_SECRET_CONSUME_RATE); - XXH3_accumulate_scalar(acc, input + nb_blocks * block_len, secret, nbStripes); + XXH3_accumulate(acc, input + nb_blocks * block_len, secret, nbStripes); /* last stripe */ constexpr size_t XXH_SECRET_LASTACC_START = 7; - XXH3_accumulate_512_scalar(acc, input + len - XXH_STRIPE_LEN, - secret + secretSize - XXH_STRIPE_LEN - - XXH_SECRET_LASTACC_START); + XXH3_accumulate_512(acc, input + len - XXH_STRIPE_LEN, + secret + secretSize - XXH_STRIPE_LEN - + XXH_SECRET_LASTACC_START); /* converge into final hash */ constexpr size_t XXH_SECRET_MERGEACCS_START = 11; @@ -405,3 +561,482 @@ uint64_t wpi::xxh3_64bits(std::span data) { return XXH3_len_129to240_64b(in, len, kSecret, 0); return XXH3_hashLong_64b(in, len, kSecret, sizeof(kSecret)); } + +/* ========================================== + * XXH3 128 bits (a.k.a XXH128) + * ========================================== + * XXH3's 128-bit variant has better mixing and strength than the 64-bit + * variant, even without counting the significantly larger output size. + * + * For example, extra steps are taken to avoid the seed-dependent collisions + * in 17-240 byte inputs (See XXH3_mix16B and XXH128_mix32B). + * + * This strength naturally comes at the cost of some speed, especially on short + * lengths. Note that longer hashes are about as fast as the 64-bit version + * due to it using only a slight modification of the 64-bit loop. + * + * XXH128 is also more oriented towards 64-bit machines. It is still extremely + * fast for a _128-bit_ hash on 32-bit (it usually clears XXH64). + */ + +/*! + * @internal + * @def XXH_rotl32(x,r) + * @brief 32-bit rotate left. + * + * @param x The 32-bit integer to be rotated. + * @param r The number of bits to rotate. + * @pre + * @p r > 0 && @p r < 32 + * @note + * @p x and @p r may be evaluated multiple times. + * @return The rotated result. + */ +#if __has_builtin(__builtin_rotateleft32) && \ + __has_builtin(__builtin_rotateleft64) +#define XXH_rotl32 __builtin_rotateleft32 +#define XXH_rotl64 __builtin_rotateleft64 +/* Note: although _rotl exists for minGW (GCC under windows), performance seems + * poor */ +#elif defined(_MSC_VER) +#define XXH_rotl32(x, r) _rotl(x, r) +#define XXH_rotl64(x, r) _rotl64(x, r) +#else +#define XXH_rotl32(x, r) (((x) << (r)) | ((x) >> (32 - (r)))) +#define XXH_rotl64(x, r) (((x) << (r)) | ((x) >> (64 - (r)))) +#endif + +#define XXH_mult32to64(x, y) ((uint64_t)(uint32_t)(x) * (uint64_t)(uint32_t)(y)) + +/*! + * @brief Calculates a 64->128-bit long multiply. + * + * Uses `__uint128_t` and `_umul128` if available, otherwise uses a scalar + * version. + * + * @param lhs , rhs The 64-bit integers to be multiplied + * @return The 128-bit result represented in an @ref XXH128_hash_t. + */ +static XXH128_hash_t XXH_mult64to128(uint64_t lhs, uint64_t rhs) { + /* + * GCC/Clang __uint128_t method. + * + * On most 64-bit targets, GCC and Clang define a __uint128_t type. + * This is usually the best way as it usually uses a native long 64-bit + * multiply, such as MULQ on x86_64 or MUL + UMULH on aarch64. + * + * Usually. + * + * Despite being a 32-bit platform, Clang (and emscripten) define this type + * despite not having the arithmetic for it. This results in a laggy + * compiler builtin call which calculates a full 128-bit multiply. + * In that case it is best to use the portable one. + * https://github.com/Cyan4973/xxHash/issues/211#issuecomment-515575677 + */ +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__wasm__) && \ + defined(__SIZEOF_INT128__) || \ + (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 128) + + __uint128_t const product = (__uint128_t)lhs * (__uint128_t)rhs; + XXH128_hash_t r128; + r128.low64 = (uint64_t)(product); + r128.high64 = (uint64_t)(product >> 64); + return r128; + + /* + * MSVC for x64's _umul128 method. + * + * uint64_t _umul128(uint64_t Multiplier, uint64_t Multiplicand, uint64_t + * *HighProduct); + * + * This compiles to single operand MUL on x64. + */ +#elif (defined(_M_X64) || defined(_M_IA64)) && !defined(_M_ARM64EC) + +#ifndef _MSC_VER +#pragma intrinsic(_umul128) +#endif + uint64_t product_high; + uint64_t const product_low = _umul128(lhs, rhs, &product_high); + XXH128_hash_t r128; + r128.low64 = product_low; + r128.high64 = product_high; + return r128; + + /* + * MSVC for ARM64's __umulh method. + * + * This compiles to the same MUL + UMULH as GCC/Clang's __uint128_t method. + */ +#elif defined(_M_ARM64) || defined(_M_ARM64EC) + +#ifndef _MSC_VER +#pragma intrinsic(__umulh) +#endif + XXH128_hash_t r128; + r128.low64 = lhs * rhs; + r128.high64 = __umulh(lhs, rhs); + return r128; + +#else + /* + * Portable scalar method. Optimized for 32-bit and 64-bit ALUs. + * + * This is a fast and simple grade school multiply, which is shown below + * with base 10 arithmetic instead of base 0x100000000. + * + * 9 3 // D2 lhs = 93 + * x 7 5 // D2 rhs = 75 + * ---------- + * 1 5 // D2 lo_lo = (93 % 10) * (75 % 10) = 15 + * 4 5 | // D2 hi_lo = (93 / 10) * (75 % 10) = 45 + * 2 1 | // D2 lo_hi = (93 % 10) * (75 / 10) = 21 + * + 6 3 | | // D2 hi_hi = (93 / 10) * (75 / 10) = 63 + * --------- + * 2 7 | // D2 cross = (15 / 10) + (45 % 10) + 21 = 27 + * + 6 7 | | // D2 upper = (27 / 10) + (45 / 10) + 63 = 67 + * --------- + * 6 9 7 5 // D4 res = (27 * 10) + (15 % 10) + (67 * 100) = 6975 + * + * The reasons for adding the products like this are: + * 1. It avoids manual carry tracking. Just like how + * (9 * 9) + 9 + 9 = 99, the same applies with this for UINT64_MAX. + * This avoids a lot of complexity. + * + * 2. It hints for, and on Clang, compiles to, the powerful UMAAL + * instruction available in ARM's Digital Signal Processing extension + * in 32-bit ARMv6 and later, which is shown below: + * + * void UMAAL(xxh_u32 *RdLo, xxh_u32 *RdHi, xxh_u32 Rn, xxh_u32 Rm) + * { + * uint64_t product = (uint64_t)*RdLo * (uint64_t)*RdHi + Rn + Rm; + * *RdLo = (xxh_u32)(product & 0xFFFFFFFF); + * *RdHi = (xxh_u32)(product >> 32); + * } + * + * This instruction was designed for efficient long multiplication, and + * allows this to be calculated in only 4 instructions at speeds + * comparable to some 64-bit ALUs. + * + * 3. It isn't terrible on other platforms. Usually this will be a couple + * of 32-bit ADD/ADCs. + */ + + /* First calculate all of the cross products. */ + uint64_t const lo_lo = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs & 0xFFFFFFFF); + uint64_t const hi_lo = XXH_mult32to64(lhs >> 32, rhs & 0xFFFFFFFF); + uint64_t const lo_hi = XXH_mult32to64(lhs & 0xFFFFFFFF, rhs >> 32); + uint64_t const hi_hi = XXH_mult32to64(lhs >> 32, rhs >> 32); + + /* Now add the products together. These will never overflow. */ + uint64_t const cross = (lo_lo >> 32) + (hi_lo & 0xFFFFFFFF) + lo_hi; + uint64_t const upper = (hi_lo >> 32) + (cross >> 32) + hi_hi; + uint64_t const lower = (cross << 32) | (lo_lo & 0xFFFFFFFF); + + XXH128_hash_t r128; + r128.low64 = lower; + r128.high64 = upper; + return r128; +#endif +} + +/*! Seems to produce slightly better code on GCC for some reason. */ +LLVM_ATTRIBUTE_ALWAYS_INLINE constexpr uint64_t XXH_xorshift64(uint64_t v64, + int shift) { + return v64 ^ (v64 >> shift); +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH3_len_1to3_128b(const uint8_t *input, size_t len, const uint8_t *secret, + uint64_t seed) { + /* A doubled version of 1to3_64b with different constants. */ + /* + * len = 1: combinedl = { input[0], 0x01, input[0], input[0] } + * len = 2: combinedl = { input[1], 0x02, input[0], input[1] } + * len = 3: combinedl = { input[2], 0x03, input[0], input[1] } + */ + uint8_t const c1 = input[0]; + uint8_t const c2 = input[len >> 1]; + uint8_t const c3 = input[len - 1]; + uint32_t const combinedl = ((uint32_t)c1 << 16) | ((uint32_t)c2 << 24) | + ((uint32_t)c3 << 0) | ((uint32_t)len << 8); + uint32_t const combinedh = XXH_rotl32(byteswap(combinedl), 13); + uint64_t const bitflipl = + (endian::read32le(secret) ^ endian::read32le(secret + 4)) + seed; + uint64_t const bitfliph = + (endian::read32le(secret + 8) ^ endian::read32le(secret + 12)) - seed; + uint64_t const keyed_lo = (uint64_t)combinedl ^ bitflipl; + uint64_t const keyed_hi = (uint64_t)combinedh ^ bitfliph; + XXH128_hash_t h128; + h128.low64 = XXH64_avalanche(keyed_lo); + h128.high64 = XXH64_avalanche(keyed_hi); + return h128; +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH3_len_4to8_128b(const uint8_t *input, size_t len, const uint8_t *secret, + uint64_t seed) { + seed ^= (uint64_t)byteswap((uint32_t)seed) << 32; + uint32_t const input_lo = endian::read32le(input); + uint32_t const input_hi = endian::read32le(input + len - 4); + uint64_t const input_64 = input_lo + ((uint64_t)input_hi << 32); + uint64_t const bitflip = + (endian::read64le(secret + 16) ^ endian::read64le(secret + 24)) + seed; + uint64_t const keyed = input_64 ^ bitflip; + + /* Shift len to the left to ensure it is even, this avoids even multiplies. + */ + XXH128_hash_t m128 = XXH_mult64to128(keyed, PRIME64_1 + (len << 2)); + + m128.high64 += (m128.low64 << 1); + m128.low64 ^= (m128.high64 >> 3); + + m128.low64 = XXH_xorshift64(m128.low64, 35); + m128.low64 *= PRIME_MX2; + m128.low64 = XXH_xorshift64(m128.low64, 28); + m128.high64 = XXH3_avalanche(m128.high64); + return m128; +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH3_len_9to16_128b(const uint8_t *input, size_t len, const uint8_t *secret, + uint64_t seed) { + uint64_t const bitflipl = + (endian::read64le(secret + 32) ^ endian::read64le(secret + 40)) - seed; + uint64_t const bitfliph = + (endian::read64le(secret + 48) ^ endian::read64le(secret + 56)) + seed; + uint64_t const input_lo = endian::read64le(input); + uint64_t input_hi = endian::read64le(input + len - 8); + XXH128_hash_t m128 = + XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, PRIME64_1); + /* + * Put len in the middle of m128 to ensure that the length gets mixed to + * both the low and high bits in the 128x64 multiply below. + */ + m128.low64 += (uint64_t)(len - 1) << 54; + input_hi ^= bitfliph; + /* + * Add the high 32 bits of input_hi to the high 32 bits of m128, then + * add the long product of the low 32 bits of input_hi and PRIME32_2 to + * the high 64 bits of m128. + * + * The best approach to this operation is different on 32-bit and 64-bit. + */ + if (sizeof(void *) < sizeof(uint64_t)) { /* 32-bit */ + /* + * 32-bit optimized version, which is more readable. + * + * On 32-bit, it removes an ADC and delays a dependency between the two + * halves of m128.high64, but it generates an extra mask on 64-bit. + */ + m128.high64 += (input_hi & 0xFFFFFFFF00000000ULL) + + XXH_mult32to64((uint32_t)input_hi, PRIME32_2); + } else { + /* + * 64-bit optimized (albeit more confusing) version. + * + * Uses some properties of addition and multiplication to remove the mask: + * + * Let: + * a = input_hi.lo = (input_hi & 0x00000000FFFFFFFF) + * b = input_hi.hi = (input_hi & 0xFFFFFFFF00000000) + * c = PRIME32_2 + * + * a + (b * c) + * Inverse Property: x + y - x == y + * a + (b * (1 + c - 1)) + * Distributive Property: x * (y + z) == (x * y) + (x * z) + * a + (b * 1) + (b * (c - 1)) + * Identity Property: x * 1 == x + * a + b + (b * (c - 1)) + * + * Substitute a, b, and c: + * input_hi.hi + input_hi.lo + ((uint64_t)input_hi.lo * (PRIME32_2 + * - 1)) + * + * Since input_hi.hi + input_hi.lo == input_hi, we get this: + * input_hi + ((uint64_t)input_hi.lo * (PRIME32_2 - 1)) + */ + m128.high64 += input_hi + XXH_mult32to64((uint32_t)input_hi, PRIME32_2 - 1); + } + /* m128 ^= XXH_swap64(m128 >> 64); */ + m128.low64 ^= byteswap(m128.high64); + + /* 128x64 multiply: h128 = m128 * PRIME64_2; */ + XXH128_hash_t h128 = XXH_mult64to128(m128.low64, PRIME64_2); + h128.high64 += m128.high64 * PRIME64_2; + + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = XXH3_avalanche(h128.high64); + return h128; +} + +/* + * Assumption: `secret` size is >= XXH3_SECRET_SIZE_MIN + */ +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH3_len_0to16_128b(const uint8_t *input, size_t len, const uint8_t *secret, + uint64_t seed) { + if (len > 8) + return XXH3_len_9to16_128b(input, len, secret, seed); + if (len >= 4) + return XXH3_len_4to8_128b(input, len, secret, seed); + if (len) + return XXH3_len_1to3_128b(input, len, secret, seed); + XXH128_hash_t h128; + uint64_t const bitflipl = + endian::read64le(secret + 64) ^ endian::read64le(secret + 72); + uint64_t const bitfliph = + endian::read64le(secret + 80) ^ endian::read64le(secret + 88); + h128.low64 = XXH64_avalanche(seed ^ bitflipl); + h128.high64 = XXH64_avalanche(seed ^ bitfliph); + return h128; +} + +/* + * A bit slower than XXH3_mix16B, but handles multiply by zero better. + */ +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH128_mix32B(XXH128_hash_t acc, const uint8_t *input_1, const uint8_t *input_2, + const uint8_t *secret, uint64_t seed) { + acc.low64 += XXH3_mix16B(input_1, secret + 0, seed); + acc.low64 ^= endian::read64le(input_2) + endian::read64le(input_2 + 8); + acc.high64 += XXH3_mix16B(input_2, secret + 16, seed); + acc.high64 ^= endian::read64le(input_1) + endian::read64le(input_1 + 8); + return acc; +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE static XXH128_hash_t +XXH3_len_17to128_128b(const uint8_t *input, size_t len, const uint8_t *secret, + size_t secretSize, uint64_t seed) { + (void)secretSize; + + XXH128_hash_t acc; + acc.low64 = len * PRIME64_1; + acc.high64 = 0; + + if (len > 32) { + if (len > 64) { + if (len > 96) { + acc = + XXH128_mix32B(acc, input + 48, input + len - 64, secret + 96, seed); + } + acc = XXH128_mix32B(acc, input + 32, input + len - 48, secret + 64, seed); + } + acc = XXH128_mix32B(acc, input + 16, input + len - 32, secret + 32, seed); + } + acc = XXH128_mix32B(acc, input, input + len - 16, secret, seed); + XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * PRIME64_1) + (acc.high64 * PRIME64_4) + + ((len - seed) * PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (uint64_t)0 - XXH3_avalanche(h128.high64); + return h128; +} + +LLVM_ATTRIBUTE_NOINLINE static XXH128_hash_t +XXH3_len_129to240_128b(const uint8_t *input, size_t len, const uint8_t *secret, + size_t secretSize, uint64_t seed) { + (void)secretSize; + + XXH128_hash_t acc; + unsigned i; + acc.low64 = len * PRIME64_1; + acc.high64 = 0; + /* + * We set as `i` as offset + 32. We do this so that unchanged + * `len` can be used as upper bound. This reaches a sweet spot + * where both x86 and aarch64 get simple agen and good codegen + * for the loop. + */ + for (i = 32; i < 160; i += 32) { + acc = XXH128_mix32B(acc, input + i - 32, input + i - 16, secret + i - 32, + seed); + } + acc.low64 = XXH3_avalanche(acc.low64); + acc.high64 = XXH3_avalanche(acc.high64); + /* + * NB: `i <= len` will duplicate the last 32-bytes if + * len % 32 was zero. This is an unfortunate necessity to keep + * the hash result stable. + */ + for (i = 160; i <= len; i += 32) { + acc = XXH128_mix32B(acc, input + i - 32, input + i - 16, + secret + XXH3_MIDSIZE_STARTOFFSET + i - 160, seed); + } + /* last bytes */ + acc = + XXH128_mix32B(acc, input + len - 16, input + len - 32, + secret + XXH3_SECRETSIZE_MIN - XXH3_MIDSIZE_LASTOFFSET - 16, + (uint64_t)0 - seed); + + XXH128_hash_t h128; + h128.low64 = acc.low64 + acc.high64; + h128.high64 = (acc.low64 * PRIME64_1) + (acc.high64 * PRIME64_4) + + ((len - seed) * PRIME64_2); + h128.low64 = XXH3_avalanche(h128.low64); + h128.high64 = (uint64_t)0 - XXH3_avalanche(h128.high64); + return h128; +} + +LLVM_ATTRIBUTE_ALWAYS_INLINE XXH128_hash_t +XXH3_hashLong_128b(const uint8_t *input, size_t len, const uint8_t *secret, + size_t secretSize) { + const size_t nbStripesPerBlock = + (secretSize - XXH_STRIPE_LEN) / XXH_SECRET_CONSUME_RATE; + const size_t block_len = XXH_STRIPE_LEN * nbStripesPerBlock; + const size_t nb_blocks = (len - 1) / block_len; + alignas(16) uint64_t acc[XXH_ACC_NB] = { + PRIME32_3, PRIME64_1, PRIME64_2, PRIME64_3, + PRIME64_4, PRIME32_2, PRIME64_5, PRIME32_1, + }; + + for (size_t n = 0; n < nb_blocks; ++n) { + XXH3_accumulate(acc, input + n * block_len, secret, nbStripesPerBlock); + XXH3_scrambleAcc(acc, secret + secretSize - XXH_STRIPE_LEN); + } + + /* last partial block */ + const size_t nbStripes = (len - 1 - (block_len * nb_blocks)) / XXH_STRIPE_LEN; + assert(nbStripes <= secretSize / XXH_SECRET_CONSUME_RATE); + XXH3_accumulate(acc, input + nb_blocks * block_len, secret, nbStripes); + + /* last stripe */ + constexpr size_t XXH_SECRET_LASTACC_START = 7; + XXH3_accumulate_512(acc, input + len - XXH_STRIPE_LEN, + secret + secretSize - XXH_STRIPE_LEN - + XXH_SECRET_LASTACC_START); + + /* converge into final hash */ + static_assert(sizeof(acc) == 64); + XXH128_hash_t h128; + constexpr size_t XXH_SECRET_MERGEACCS_START = 11; + h128.low64 = XXH3_mergeAccs(acc, secret + XXH_SECRET_MERGEACCS_START, + (uint64_t)len * PRIME64_1); + h128.high64 = XXH3_mergeAccs( + acc, secret + secretSize - sizeof(acc) - XXH_SECRET_MERGEACCS_START, + ~((uint64_t)len * PRIME64_2)); + return h128; +} + +wpi::XXH128_hash_t wpi::xxh3_128bits(std::span data) { + size_t len = data.size(); + const uint8_t *input = data.data(); + + /* + * If an action is to be taken if `secret` conditions are not respected, + * it should be done here. + * For now, it's a contract pre-condition. + * Adding a check and a branch here would cost performance at every hash. + */ + if (len <= 16) + return XXH3_len_0to16_128b(input, len, kSecret, /*seed64=*/0); + if (len <= 128) + return XXH3_len_17to128_128b(input, len, kSecret, sizeof(kSecret), + /*seed64=*/0); + if (len <= XXH3_MIDSIZE_MAX) + return XXH3_len_129to240_128b(input, len, kSecret, sizeof(kSecret), + /*seed64=*/0); + return XXH3_hashLong_128b(input, len, kSecret, sizeof(kSecret)); +} diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/ADL.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/ADL.h index 3be8691d4f7..c379387f79a 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/ADL.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/ADL.h @@ -37,6 +37,22 @@ constexpr auto end_impl(RangeT &&range) return end(std::forward(range)); } +using std::rbegin; + +template +constexpr auto rbegin_impl(RangeT &&range) + -> decltype(rbegin(std::forward(range))) { + return rbegin(std::forward(range)); +} + +using std::rend; + +template +constexpr auto rend_impl(RangeT &&range) + -> decltype(rend(std::forward(range))) { + return rend(std::forward(range)); +} + using std::swap; template @@ -72,6 +88,22 @@ constexpr auto adl_end(RangeT &&range) return adl_detail::end_impl(std::forward(range)); } +/// Returns the reverse-begin iterator to \p range using `std::rbegin` and +/// function found through Argument-Dependent Lookup (ADL). +template +constexpr auto adl_rbegin(RangeT &&range) + -> decltype(adl_detail::rbegin_impl(std::forward(range))) { + return adl_detail::rbegin_impl(std::forward(range)); +} + +/// Returns the reverse-end iterator to \p range using `std::rend` and +/// functions found through Argument-Dependent Lookup (ADL). +template +constexpr auto adl_rend(RangeT &&range) + -> decltype(adl_detail::rend_impl(std::forward(range))) { + return adl_detail::rend_impl(std::forward(range)); +} + /// Swaps \p lhs with \p rhs using `std::swap` and functions found through /// Argument-Dependent Lookup (ADL). template diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h index 60692f2b4de..9d1ee1104d5 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Casting.h @@ -801,6 +801,52 @@ template return unique_dyn_cast_or_null(Val); } +//===----------------------------------------------------------------------===// +// Isa Predicates +//===----------------------------------------------------------------------===// + +/// These are wrappers over isa* function that allow them to be used in generic +/// algorithms such as `llvm:all_of`, `wpi::none_of`, etc. This is accomplished +/// by exposing the isa* functions through function objects with a generic +/// function call operator. + +namespace detail { +template struct IsaCheckPredicate { + template [[nodiscard]] bool operator()(const T &Val) const { + return isa(Val); + } +}; + +template struct IsaAndPresentCheckPredicate { + template [[nodiscard]] bool operator()(const T &Val) const { + return isa_and_present(Val); + } +}; +} // namespace detail + +/// Function object wrapper for the `wpi::isa` type check. The function call +/// operator returns true when the value can be cast to any type in `Types`. +/// Example: +/// ``` +/// SmallVector myTypes = ...; +/// if (wpi::all_of(myTypes, wpi::IsaPred)) +/// ... +/// ``` +template +inline constexpr detail::IsaCheckPredicate IsaPred{}; + +/// Function object wrapper for the `wpi::isa_and_present` type check. The +/// function call operator returns true when the value can be cast to any type +/// in `Types`, or if the value is not present (e.g., nullptr). Example: +/// ``` +/// SmallVector myTypes = ...; +/// if (wpi::all_of(myTypes, wpi::IsaAndPresentPred)) +/// ... +/// ``` +template +inline constexpr detail::IsaAndPresentCheckPredicate + IsaAndPresentPred{}; + } // end namespace wpi #endif // WPIUTIL_WPI_CASTING_H diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h index 59362dc1dab..4674123987f 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Compiler.h @@ -297,6 +297,14 @@ #endif #endif +/// LLVM_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that +/// it is not aliased in the current scope. +#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) +#define LLVM_ATTRIBUTE_RESTRICT __restrict +#else +#define LLVM_ATTRIBUTE_RESTRICT +#endif + /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a /// pointer that does not alias any other valid pointer. #ifndef LLVM_ATTRIBUTE_RETURNS_NOALIAS diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMap.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMap.h index 2b872de732d..f92cdcdb602 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMap.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMap.h @@ -313,6 +313,22 @@ class DenseMapBase : public DebugEpochBase { insert(*I); } + template + std::pair insert_or_assign(const KeyT &Key, V &&Val) { + auto Ret = try_emplace(Key, std::forward(Val)); + if (!Ret.second) + Ret.first->second = std::forward(Val); + return Ret; + } + + template + std::pair insert_or_assign(KeyT &&Key, V &&Val) { + auto Ret = try_emplace(std::move(Key), std::forward(Val)); + if (!Ret.second) + Ret.first->second = std::forward(Val); + return Ret; + } + /// Returns the value associated to the key in the map if it exists. If it /// does not exist, emplace a default value for the key and returns a /// reference to the newly created value. diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMapInfo.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMapInfo.h index 9e939effb51..ce6bc5f368a 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMapInfo.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/DenseMapInfo.h @@ -23,20 +23,22 @@ namespace wpi { +namespace densemap::detail { +// A bit mixer with very low latency using one multiplications and one +// xor-shift. The constant is from splitmix64. +inline uint64_t mix(uint64_t x) { + x *= 0xbf58476d1ce4e5b9u; + x ^= x >> 31; + return x; +} +} // namespace densemap::detail + namespace detail { /// Simplistic combination of 32-bit hash values into 32-bit hash values. -static inline unsigned combineHashValue(unsigned a, unsigned b) { - uint64_t key = (uint64_t)a << 32 | (uint64_t)b; - key += ~(key << 32); - key ^= (key >> 22); - key += ~(key << 13); - key ^= (key >> 8); - key += (key << 3); - key ^= (key >> 15); - key += ~(key << 27); - key ^= (key >> 31); - return (unsigned)key; +inline unsigned combineHashValue(unsigned a, unsigned b) { + uint64_t x = (uint64_t)a << 32 | (uint64_t)b; + return (unsigned)densemap::detail::mix(x); } } // end namespace detail @@ -137,7 +139,10 @@ template<> struct DenseMapInfo { static inline unsigned long getTombstoneKey() { return ~0UL - 1L; } static unsigned getHashValue(const unsigned long& Val) { - return (unsigned)(Val * 37UL); + if constexpr (sizeof(Val) == 4) + return DenseMapInfo::getHashValue(Val); + else + return densemap::detail::mix(Val); } static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) { @@ -151,7 +156,7 @@ template<> struct DenseMapInfo { static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; } static unsigned getHashValue(const unsigned long long& Val) { - return (unsigned)(Val * 37ULL); + return densemap::detail::mix(Val); } static bool isEqual(const unsigned long long& LHS, @@ -297,6 +302,24 @@ template struct DenseMapInfo> { } }; +// Provide DenseMapInfo for enum classes. +template +struct DenseMapInfo>> { + using UnderlyingType = std::underlying_type_t; + using Info = DenseMapInfo; + + static Enum getEmptyKey() { return static_cast(Info::getEmptyKey()); } + + static Enum getTombstoneKey() { + return static_cast(Info::getTombstoneKey()); + } + + static unsigned getHashValue(const Enum &Val) { + return Info::getHashValue(static_cast(Val)); + } + + static bool isEqual(const Enum &LHS, const Enum &RHS) { return LHS == RHS; } +}; } // end namespace wpi #endif // WPIUTIL_WPI_DENSEMAPINFO_H diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h index bfbf1e7eb34..57b28385136 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Endian.h @@ -74,7 +74,8 @@ template /// Read a value of a particular endianness from a buffer, and increment the /// buffer past that value. -template +template [[nodiscard]] inline value_type readNext(const CharT *&memory, endianness endian) { value_type ret = read(memory, endian); @@ -82,8 +83,8 @@ template return ret; } -template +template [[nodiscard]] inline value_type readNext(const CharT *&memory) { return readNext(memory, endian); } @@ -104,6 +105,21 @@ inline void write(void *memory, value_type value) { write(memory, value, endian); } +/// Write a value of a particular endianness, and increment the buffer past that +/// value. +template +inline void writeNext(CharT *&memory, value_type value, endianness endian) { + write(memory, value, endian); + memory += sizeof(value_type); +} + +template +inline void writeNext(CharT *&memory, value_type value) { + writeNext(memory, value, endian); +} + template using make_unsigned_t = std::make_unsigned_t; diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Errc.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Errc.h index dee28dfdc10..651cd32c31b 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Errc.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Errc.h @@ -38,6 +38,10 @@ enum class errc { bad_address = int(std::errc::bad_address), bad_file_descriptor = int(std::errc::bad_file_descriptor), broken_pipe = int(std::errc::broken_pipe), + // There is no delete_pending in std::errc; this error code is negative to + // avoid conflicts. This error roughly corresponds with Windows' + // STATUS_DELETE_PENDING 0xC0000056. + delete_pending = -56, device_or_resource_busy = int(std::errc::device_or_resource_busy), directory_not_empty = int(std::errc::directory_not_empty), executable_format_error = int(std::errc::executable_format_error), diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h index a0ae149fb36..cc07b064b7e 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/FunctionExtras.h @@ -38,7 +38,6 @@ #include "wpi/Compiler.h" #include "wpi/MemAlloc.h" #include "wpi/type_traits.h" -#include #include #include #include @@ -169,7 +168,7 @@ template class UniqueFunctionBase { // provide four pointers worth of storage here. // This is mutable as an inlined `const unique_function` may // still modify its own mutable members. - alignas(void*) mutable std::byte InlineStorage[InlineStorageSize]; + alignas(void *) mutable std::byte InlineStorage[InlineStorageSize]; } StorageUnion; // A compressed pointer to either our dispatching callback or our table of diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h index a232488ef56..94a126c47ae 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/Hashing.h @@ -131,23 +131,6 @@ hash_code hash_value(const std::basic_string &arg); /// Compute a hash_code for a standard string. template hash_code hash_value(const std::optional &arg); -/// Override the execution seed with a fixed value. -/// -/// This hashing library uses a per-execution seed designed to change on each -/// run with high probability in order to ensure that the hash codes are not -/// attackable and to ensure that output which is intended to be stable does -/// not rely on the particulars of the hash codes produced. -/// -/// That said, there are use cases where it is important to be able to -/// reproduce *exactly* a specific behavior. To that end, we provide a function -/// which will forcibly set the seed to a fixed value. This must be done at the -/// start of the program, before any hashes are computed. Also, it cannot be -/// undone. This makes it thread-hostile and very hard to use outside of -/// immediately on start of a simple program designed for reproducible -/// behavior. -void set_fixed_execution_hash_seed(uint64_t fixed_value); - - // All of the implementation details of actually computing the various hash // code values are held within this namespace. These routines are included in // the header file mainly to allow inlining and constant propagation. @@ -327,24 +310,20 @@ struct hash_state { } }; - -/// A global, fixed seed-override variable. -/// -/// This variable can be set using the \see wpi::set_fixed_execution_seed -/// function. See that function for details. Do not, under any circumstances, -/// set or read this variable. -extern uint64_t fixed_seed_override; - +/// In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic +/// per process (address of a function in LLVMSupport) to prevent having users +/// depend on the particular hash values. On platforms without ASLR, this is +/// still likely non-deterministic per build. inline uint64_t get_execution_seed() { - // FIXME: This needs to be a per-execution seed. This is just a placeholder - // implementation. Switching to a per-execution seed is likely to flush out - // instability bugs and so will happen as its own commit. - // - // However, if there is a fixed seed override set the first time this is - // called, return that instead of the per-execution seed. - const uint64_t seed_prime = 0xff51afd7ed558ccdULL; - static uint64_t seed = fixed_seed_override ? fixed_seed_override : seed_prime; - return seed; + // Work around x86-64 negative offset folding for old Clang -fno-pic + // https://reviews.llvm.org/D93931 +#if LLVM_ENABLE_ABI_BREAKING_CHECKS && \ + (!defined(__clang__) || __clang_major__ > 11) + return static_cast( + reinterpret_cast(&install_fatal_error_handler)); +#else + return 0xff51afd7ed558ccdULL; +#endif } diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h index 4ccea3e3f8e..9af57c3e7ce 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/MathExtras.h @@ -24,6 +24,22 @@ #include namespace wpi { +/// Some template parameter helpers to optimize for bitwidth, for functions that +/// take multiple arguments. + +// We can't verify signedness, since callers rely on implicit coercions to +// signed/unsigned. +template +using enableif_int = + std::enable_if_t && std::is_integral_v>; + +// Use std::common_type_t to widen only up to the widest argument. +template > +using common_uint = + std::common_type_t, std::make_unsigned_t>; +template > +using common_sint = + std::common_type_t, std::make_signed_t>; /// Create a bitmask with the N right-most bits set to 1, and all other /// bits set to 0. Only unsigned types are allowed. @@ -31,7 +47,9 @@ template T maskTrailingOnes(unsigned N) { static_assert(std::is_unsigned_v, "Invalid type!"); const unsigned Bits = CHAR_BIT * sizeof(T); assert(N <= Bits && "Invalid bit index"); - return N == 0 ? 0 : (T(-1) >> (Bits - N)); + if (N == 0) + return 0; + return T(-1) >> (Bits - N); } /// Create a bitmask with the N left-most bits set to 1, and all other @@ -98,22 +116,24 @@ template T reverseBits(T Val) { // ambiguity. /// Return the high 32 bits of a 64 bit value. -constexpr inline uint32_t Hi_32(uint64_t Value) { +constexpr uint32_t Hi_32(uint64_t Value) { return static_cast(Value >> 32); } /// Return the low 32 bits of a 64 bit value. -constexpr inline uint32_t Lo_32(uint64_t Value) { +constexpr uint32_t Lo_32(uint64_t Value) { return static_cast(Value); } /// Make a 64-bit integer from a high / low pair of 32-bit integers. -constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) { +constexpr uint64_t Make_64(uint32_t High, uint32_t Low) { return ((uint64_t)High << 32) | (uint64_t)Low; } /// Checks if an integer fits into the given bit width. -template constexpr inline bool isInt(int64_t x) { +template constexpr bool isInt(int64_t x) { + if constexpr (N == 0) + return 0 == x; if constexpr (N == 8) return static_cast(x) == x; if constexpr (N == 16) @@ -128,16 +148,16 @@ template constexpr inline bool isInt(int64_t x) { /// Checks if a signed integer is an N bit number shifted left by S. template -constexpr inline bool isShiftedInt(int64_t x) { - static_assert( - N > 0, "isShiftedInt<0> doesn't make sense (refers to a 0-bit number."); +constexpr bool isShiftedInt(int64_t x) { + static_assert(S < 64, "isShiftedInt with S >= 64 is too much."); static_assert(N + S <= 64, "isShiftedInt with N + S > 64 is too wide."); return isInt(x) && (x % (UINT64_C(1) << S) == 0); } /// Checks if an unsigned integer fits into the given bit width. -template constexpr inline bool isUInt(uint64_t x) { - static_assert(N > 0, "isUInt<0> doesn't make sense"); +template constexpr bool isUInt(uint64_t x) { + if constexpr (N == 0) + return 0 == x; if constexpr (N == 8) return static_cast(x) == x; if constexpr (N == 16) @@ -152,24 +172,27 @@ template constexpr inline bool isUInt(uint64_t x) { /// Checks if a unsigned integer is an N bit number shifted left by S. template -constexpr inline bool isShiftedUInt(uint64_t x) { - static_assert( - N > 0, "isShiftedUInt<0> doesn't make sense (refers to a 0-bit number)"); +constexpr bool isShiftedUInt(uint64_t x) { + static_assert(S < 64, "isShiftedUInt with S >= 64 is too much."); static_assert(N + S <= 64, "isShiftedUInt with N + S > 64 is too wide."); - // Per the two static_asserts above, S must be strictly less than 64. So - // 1 << S is not undefined behavior. + // S must be strictly less than 64. So 1 << S is not undefined behavior. return isUInt(x) && (x % (UINT64_C(1) << S) == 0); } /// Gets the maximum value for a N-bit unsigned integer. inline uint64_t maxUIntN(uint64_t N) { - assert(N > 0 && N <= 64 && "integer width out of range"); + assert(N <= 64 && "integer width out of range"); // uint64_t(1) << 64 is undefined behavior, so we can't do // (uint64_t(1) << N) - 1 // without checking first that N != 64. But this works and doesn't have a - // branch. + // branch for N != 0. + // Unfortunately, shifting a uint64_t right by 64 bit is undefined + // behavior, so the condition on N == 0 is necessary. Fortunately, most + // optimizers do not emit branches for this check. + if (N == 0) + return 0; return UINT64_MAX >> (64 - N); } @@ -180,8 +203,10 @@ inline uint64_t maxUIntN(uint64_t N) { /// Gets the minimum value for a N-bit signed integer. inline int64_t minIntN(int64_t N) { - assert(N > 0 && N <= 64 && "integer width out of range"); + assert(N <= 64 && "integer width out of range"); + if (N == 0) + return 0; return UINT64_C(1) + ~(UINT64_C(1) << (N - 1)); } @@ -191,10 +216,12 @@ inline int64_t minIntN(int64_t N) { /// Gets the maximum value for a N-bit signed integer. inline int64_t maxIntN(int64_t N) { - assert(N > 0 && N <= 64 && "integer width out of range"); + assert(N <= 64 && "integer width out of range"); // This relies on two's complement wraparound when N == 64, so we convert to // int64_t only at the very end to avoid UB. + if (N == 0) + return 0; return (UINT64_C(1) << (N - 1)) - 1; } @@ -211,36 +238,36 @@ inline bool isIntN(unsigned N, int64_t x) { /// Return true if the argument is a non-empty sequence of ones starting at the /// least significant bit with the remainder zero (32 bit version). /// Ex. isMask_32(0x0000FFFFU) == true. -constexpr inline bool isMask_32(uint32_t Value) { +constexpr bool isMask_32(uint32_t Value) { return Value && ((Value + 1) & Value) == 0; } /// Return true if the argument is a non-empty sequence of ones starting at the /// least significant bit with the remainder zero (64 bit version). -constexpr inline bool isMask_64(uint64_t Value) { +constexpr bool isMask_64(uint64_t Value) { return Value && ((Value + 1) & Value) == 0; } /// Return true if the argument contains a non-empty sequence of ones with the /// remainder zero (32 bit version.) Ex. isShiftedMask_32(0x0000FF00U) == true. -constexpr inline bool isShiftedMask_32(uint32_t Value) { +constexpr bool isShiftedMask_32(uint32_t Value) { return Value && isMask_32((Value - 1) | Value); } /// Return true if the argument contains a non-empty sequence of ones with the /// remainder zero (64 bit version.) -constexpr inline bool isShiftedMask_64(uint64_t Value) { +constexpr bool isShiftedMask_64(uint64_t Value) { return Value && isMask_64((Value - 1) | Value); } /// Return true if the argument is a power of two > 0. /// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) -constexpr inline bool isPowerOf2_32(uint32_t Value) { +constexpr bool isPowerOf2_32(uint32_t Value) { return std::has_single_bit(Value); } /// Return true if the argument is a power of two > 0 (64 bit edition.) -constexpr inline bool isPowerOf2_64(uint64_t Value) { +constexpr bool isPowerOf2_64(uint64_t Value) { return std::has_single_bit(Value); } @@ -273,13 +300,13 @@ inline bool isShiftedMask_64(uint64_t Value, unsigned &MaskIdx, /// Compile time Log2. /// Valid only for positive powers of two. -template constexpr inline size_t CTLog2() { +template constexpr size_t CTLog2() { static_assert(kValue > 0 && wpi::isPowerOf2_64(kValue), "Value is not a valid power of 2"); return 1 + CTLog2(); } -template <> constexpr inline size_t CTLog2<1>() { return 0; } +template <> constexpr size_t CTLog2<1>() { return 0; } /// Return the floor log base 2 of the specified value, -1 if the value is zero. /// (32 bit edition.) @@ -309,7 +336,8 @@ inline unsigned Log2_64_Ceil(uint64_t Value) { /// A and B are either alignments or offsets. Return the minimum alignment that /// may be assumed after adding the two together. -constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) { +template > +constexpr T MinAlign(U A, V B) { // The largest power of 2 that divides both A and B. // // Replace "-Value" by "1+~Value" in the following commented code to avoid @@ -318,9 +346,14 @@ constexpr inline uint64_t MinAlign(uint64_t A, uint64_t B) { return (A | B) & (1 + ~(A | B)); } +/// Fallback when arguments aren't integral. +constexpr uint64_t MinAlign(uint64_t A, uint64_t B) { + return (A | B) & (1 + ~(A | B)); +} + /// Returns the next power of two (in 64-bits) that is strictly greater than A. /// Returns zero on overflow. -constexpr inline uint64_t NextPowerOf2(uint64_t A) { +constexpr uint64_t NextPowerOf2(uint64_t A) { A |= (A >> 1); A |= (A >> 2); A |= (A >> 4); @@ -338,7 +371,81 @@ inline uint64_t PowerOf2Ceil(uint64_t A) { return UINT64_C(1) << Log2_64_Ceil(A); } -/// Returns the next integer (mod 2**64) that is greater than or equal to +/// Returns the integer ceil(Numerator / Denominator). Unsigned version. +/// Guaranteed to never overflow. +template > +constexpr T divideCeil(U Numerator, V Denominator) { + assert(Denominator && "Division by zero"); + T Bias = (Numerator != 0); + return (Numerator - Bias) / Denominator + Bias; +} + +/// Fallback when arguments aren't integral. +constexpr uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) { + assert(Denominator && "Division by zero"); + uint64_t Bias = (Numerator != 0); + return (Numerator - Bias) / Denominator + Bias; +} + +// Check whether divideCeilSigned or divideFloorSigned would overflow. This +// happens only when Numerator = INT_MIN and Denominator = -1. +template +constexpr bool divideSignedWouldOverflow(U Numerator, V Denominator) { + return Numerator == (std::numeric_limits::min)() && Denominator == -1; +} + +/// Returns the integer ceil(Numerator / Denominator). Signed version. +/// Overflow is explicitly forbidden with an assert. +template > +constexpr T divideCeilSigned(U Numerator, V Denominator) { + assert(Denominator && "Division by zero"); + assert(!divideSignedWouldOverflow(Numerator, Denominator) && + "Divide would overflow"); + if (!Numerator) + return 0; + // C's integer division rounds towards 0. + T Bias = Denominator >= 0 ? 1 : -1; + bool SameSign = (Numerator >= 0) == (Denominator >= 0); + return SameSign ? (Numerator - Bias) / Denominator + 1 + : Numerator / Denominator; +} + +/// Returns the integer floor(Numerator / Denominator). Signed version. +/// Overflow is explicitly forbidden with an assert. +template > +constexpr T divideFloorSigned(U Numerator, V Denominator) { + assert(Denominator && "Division by zero"); + assert(!divideSignedWouldOverflow(Numerator, Denominator) && + "Divide would overflow"); + if (!Numerator) + return 0; + // C's integer division rounds towards 0. + T Bias = Denominator >= 0 ? -1 : 1; + bool SameSign = (Numerator >= 0) == (Denominator >= 0); + return SameSign ? Numerator / Denominator + : (Numerator - Bias) / Denominator - 1; +} + +/// Returns the remainder of the Euclidean division of LHS by RHS. Result is +/// always non-negative. +template > +constexpr T mod(U Numerator, V Denominator) { + assert(Denominator >= 1 && "Mod by non-positive number"); + T Mod = Numerator % Denominator; + return Mod < 0 ? Mod + Denominator : Mod; +} + +/// Returns (Numerator / Denominator) rounded by round-half-up. Guaranteed to +/// never overflow. +template > +constexpr T divideNearest(U Numerator, V Denominator) { + assert(Denominator && "Division by zero"); + T Mod = Numerator % Denominator; + return (Numerator / Denominator) + + (Mod > (static_cast(Denominator) - 1) / 2); +} + +/// Returns the next integer (mod 2**nbits) that is greater than or equal to /// \p Value and is a multiple of \p Align. \p Align must be non-zero. /// /// Examples: @@ -348,18 +455,29 @@ inline uint64_t PowerOf2Ceil(uint64_t A) { /// alignTo(~0LL, 8) = 0 /// alignTo(321, 255) = 510 /// \endcode -inline uint64_t alignTo(uint64_t Value, uint64_t Align) { +/// +/// Will overflow only if result is not representable in T. +template > +constexpr T alignTo(U Value, V Align) { assert(Align != 0u && "Align can't be 0."); - return (Value + Align - 1) / Align * Align; + T CeilDiv = divideCeil(Value, Align); + return CeilDiv * Align; } -inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { +/// Fallback when arguments aren't integral. +constexpr uint64_t alignTo(uint64_t Value, uint64_t Align) { + assert(Align != 0u && "Align can't be 0."); + uint64_t CeilDiv = divideCeil(Value, Align); + return CeilDiv * Align; +} + +constexpr uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { assert(Align != 0 && (Align & (Align - 1)) == 0 && "Align must be a power of 2"); // Replace unary minus to avoid compilation error on Windows: // "unary minus operator applied to unsigned type, result still unsigned" - uint64_t negAlign = (~Align) + 1; - return (Value + Align - 1) & negAlign; + uint64_t NegAlign = (~Align) + 1; + return (Value + Align - 1) & NegAlign; } /// If non-zero \p Skew is specified, the return value will be a minimal integer @@ -374,73 +492,78 @@ inline uint64_t alignToPowerOf2(uint64_t Value, uint64_t Align) { /// alignTo(~0LL, 8, 3) = 3 /// alignTo(321, 255, 42) = 552 /// \endcode -inline uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew) { +/// +/// May overflow. +template , W>> +constexpr T alignTo(U Value, V Align, W Skew) { assert(Align != 0u && "Align can't be 0."); Skew %= Align; return alignTo(Value - Skew, Align) + Skew; } -/// Returns the next integer (mod 2**64) that is greater than or equal to +/// Returns the next integer (mod 2**nbits) that is greater than or equal to /// \p Value and is a multiple of \c Align. \c Align must be non-zero. -template constexpr inline uint64_t alignTo(uint64_t Value) { +/// +/// Will overflow only if result is not representable in T. +template > +constexpr T alignTo(V Value) { static_assert(Align != 0u, "Align must be non-zero"); - return (Value + Align - 1) / Align * Align; + T CeilDiv = divideCeil(Value, Align); + return CeilDiv * Align; } -/// Returns the integer ceil(Numerator / Denominator). -inline uint64_t divideCeil(uint64_t Numerator, uint64_t Denominator) { - return alignTo(Numerator, Denominator) / Denominator; -} - -/// Returns the integer nearest(Numerator / Denominator). -inline uint64_t divideNearest(uint64_t Numerator, uint64_t Denominator) { - return (Numerator + (Denominator / 2)) / Denominator; -} - -/// Returns the largest uint64_t less than or equal to \p Value and is -/// \p Skew mod \p Align. \p Align must be non-zero -inline uint64_t alignDown(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { +/// Returns the largest unsigned integer less than or equal to \p Value and is +/// \p Skew mod \p Align. \p Align must be non-zero. Guaranteed to never +/// overflow. +template , W>> +constexpr T alignDown(U Value, V Align, W Skew = 0) { assert(Align != 0u && "Align can't be 0."); Skew %= Align; return (Value - Skew) / Align * Align + Skew; } /// Sign-extend the number in the bottom B bits of X to a 32-bit integer. -/// Requires 0 < B <= 32. -template constexpr inline int32_t SignExtend32(uint32_t X) { - static_assert(B > 0, "Bit width can't be 0."); +/// Requires B <= 32. +template constexpr int32_t SignExtend32(uint32_t X) { static_assert(B <= 32, "Bit width out of range."); + if constexpr (B == 0) + return 0; return int32_t(X << (32 - B)) >> (32 - B); } /// Sign-extend the number in the bottom B bits of X to a 32-bit integer. -/// Requires 0 < B <= 32. +/// Requires B <= 32. inline int32_t SignExtend32(uint32_t X, unsigned B) { - assert(B > 0 && "Bit width can't be 0."); assert(B <= 32 && "Bit width out of range."); + if (B == 0) + return 0; return int32_t(X << (32 - B)) >> (32 - B); } /// Sign-extend the number in the bottom B bits of X to a 64-bit integer. -/// Requires 0 < B <= 64. -template constexpr inline int64_t SignExtend64(uint64_t x) { - static_assert(B > 0, "Bit width can't be 0."); +/// Requires B <= 64. +template constexpr int64_t SignExtend64(uint64_t x) { static_assert(B <= 64, "Bit width out of range."); + if constexpr (B == 0) + return 0; return int64_t(x << (64 - B)) >> (64 - B); } /// Sign-extend the number in the bottom B bits of X to a 64-bit integer. -/// Requires 0 < B <= 64. +/// Requires B <= 64. inline int64_t SignExtend64(uint64_t X, unsigned B) { - assert(B > 0 && "Bit width can't be 0."); assert(B <= 64 && "Bit width out of range."); + if (B == 0) + return 0; return int64_t(X << (64 - B)) >> (64 - B); } /// Subtract two unsigned integers, X and Y, of type T and return the absolute /// value of the result. -template -std::enable_if_t, T> AbsoluteDifference(T X, T Y) { +template > +constexpr T AbsoluteDifference(U X, V Y) { return X > Y ? (X - Y) : (Y - X); } @@ -538,7 +661,6 @@ SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed = nullptr) { /// Use this rather than HUGE_VALF; the latter causes warnings on MSVC. extern const float huge_valf; - /// Add two signed integers, computing the two's complement truncated result, /// returning true if overflow occurred. template @@ -595,6 +717,9 @@ std::enable_if_t, T> SubOverflow(T X, T Y, T &Result) { /// result, returning true if an overflow ocurred. template std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { +#if __has_builtin(__builtin_mul_overflow) + return __builtin_mul_overflow(X, Y, &Result); +#else // Perform the unsigned multiplication on absolute values. using U = std::make_unsigned_t; const U UX = X < 0 ? (0 - static_cast(X)) : static_cast(X); @@ -616,8 +741,17 @@ std::enable_if_t, T> MulOverflow(T X, T Y, T &Result) { return UX > (static_cast((std::numeric_limits::max)()) + U(1)) / UY; else return UX > (static_cast((std::numeric_limits::max)())) / UY; +#endif } +/// Type to force float point values onto the stack, so that x86 doesn't add +/// hidden precision, avoiding rounding differences on various platforms. +#if defined(__i386__) || defined(_M_IX86) +using stack_float_t = volatile float; +#else +using stack_float_t = float; +#endif + // Typesafe implementation of the signum function. // Returns -1 if negative, 1 if positive, 0 if 0. template @@ -638,6 +772,7 @@ template constexpr T Lerp(const T& startValue, const T& endValue, double t) { return startValue + (endValue - startValue) * t; } -} // End wpi namespace + +} // namespace wpi #endif diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallPtrSet.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallPtrSet.h index db2b471509d..e782150f31f 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallPtrSet.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallPtrSet.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace wpi { @@ -126,22 +127,11 @@ class SmallPtrSetImplBase : public DebugEpochBase { std::pair insert_imp(const void *Ptr) { if (isSmall()) { // Check to see if it is already in the set. - const void **LastTombstone = nullptr; for (const void **APtr = SmallArray, **E = SmallArray + NumNonEmpty; APtr != E; ++APtr) { const void *Value = *APtr; if (Value == Ptr) return std::make_pair(APtr, false); - if (Value == getTombstoneMarker()) - LastTombstone = APtr; - } - - // Did we find any tombstone marker? - if (LastTombstone != nullptr) { - *LastTombstone = Ptr; - --NumTombstones; - incrementEpoch(); - return std::make_pair(LastTombstone, true); } // Nope, there isn't. If we stay small, just 'pushback' now. @@ -160,14 +150,27 @@ class SmallPtrSetImplBase : public DebugEpochBase { /// that the derived class can check that the right type of pointer is passed /// in. bool erase_imp(const void * Ptr) { - const void *const *P = find_imp(Ptr); - if (P == EndPointer()) + if (isSmall()) { + for (const void **APtr = SmallArray, **E = SmallArray + NumNonEmpty; + APtr != E; ++APtr) { + if (*APtr == Ptr) { + *APtr = SmallArray[--NumNonEmpty]; + incrementEpoch(); + return true; + } + } + return false; + } + + auto *Bucket = FindBucketFor(Ptr); + if (*Bucket != Ptr) return false; - const void **Loc = const_cast(P); - assert(*Loc == Ptr && "broken find!"); - *Loc = getTombstoneMarker(); + *const_cast(Bucket) = getTombstoneMarker(); NumTombstones++; + // Treat this consistently from an API perspective, even if we don't + // actually invalidate iterators here. + incrementEpoch(); return true; } @@ -191,9 +194,9 @@ class SmallPtrSetImplBase : public DebugEpochBase { return EndPointer(); } -private: bool isSmall() const { return CurArray == SmallArray; } +private: std::pair insert_imp_big(const void *Ptr); const void * const *FindBucketFor(const void *Ptr) const; @@ -311,31 +314,6 @@ class LLVM_DEBUGEPOCHBASE_HANDLEBASE_EMPTYBASE SmallPtrSetIterator } }; -/// RoundUpToPowerOfTwo - This is a helper template that rounds N up to the next -/// power of two (which means N itself if N is already a power of two). -template -struct RoundUpToPowerOfTwo; - -/// RoundUpToPowerOfTwoH - If N is not a power of two, increase it. This is a -/// helper template used to implement RoundUpToPowerOfTwo. -template -struct RoundUpToPowerOfTwoH { - enum { Val = N }; -}; -template -struct RoundUpToPowerOfTwoH { - enum { - // We could just use NextVal = N+1, but this converges faster. N|(N-1) sets - // the right-most zero bits to one all at once, e.g. 0b0011000 -> 0b0011111. - Val = RoundUpToPowerOfTwo<(N|(N-1)) + 1>::Val - }; -}; - -template -struct RoundUpToPowerOfTwo { - enum { Val = RoundUpToPowerOfTwoH::Val }; -}; - /// A templated base class for \c SmallPtrSet which provides the /// typesafe interface that is common across all small sizes. /// @@ -375,11 +353,61 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase { return insert(Ptr).first; } - /// erase - If the set contains the specified pointer, remove it and return - /// true, otherwise return false. + /// Remove pointer from the set. + /// + /// Returns whether the pointer was in the set. Invalidates iterators if + /// true is returned. To remove elements while iterating over the set, use + /// remove_if() instead. bool erase(PtrType Ptr) { return erase_imp(PtrTraits::getAsVoidPointer(Ptr)); } + + /// Remove elements that match the given predicate. + /// + /// This method is a safe replacement for the following pattern, which is not + /// valid, because the erase() calls would invalidate the iterator: + /// + /// for (PtrType *Ptr : Set) + /// if (Pred(P)) + /// Set.erase(P); + /// + /// Returns whether anything was removed. It is safe to read the set inside + /// the predicate function. However, the predicate must not modify the set + /// itself, only indicate a removal by returning true. + template + bool remove_if(UnaryPredicate P) { + bool Removed = false; + if (isSmall()) { + const void **APtr = SmallArray, **E = SmallArray + NumNonEmpty; + while (APtr != E) { + PtrType Ptr = PtrTraits::getFromVoidPointer(const_cast(*APtr)); + if (P(Ptr)) { + *APtr = *--E; + --NumNonEmpty; + incrementEpoch(); + Removed = true; + } else { + ++APtr; + } + } + return Removed; + } + + for (const void **APtr = CurArray, **E = EndPointer(); APtr != E; ++APtr) { + const void *Value = *APtr; + if (Value == getTombstoneMarker() || Value == getEmptyMarker()) + continue; + PtrType Ptr = PtrTraits::getFromVoidPointer(const_cast(Value)); + if (P(Ptr)) { + *APtr = getTombstoneMarker(); + ++NumTombstones; + incrementEpoch(); + Removed = true; + } + } + return Removed; + } + /// count - Return 1 if the specified pointer is in the set, 0 otherwise. size_type count(ConstPtrType Ptr) const { return find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)) != EndPointer(); @@ -456,8 +484,18 @@ class SmallPtrSet : public SmallPtrSetImpl { using BaseT = SmallPtrSetImpl; + // A constexpr version of wpi::bit_ceil. + // TODO: Replace this with std::bit_ceil once C++20 is available. + static constexpr size_t RoundUpToPowerOfTwo(size_t X) { + size_t C = 1; + size_t CMax = C << (std::numeric_limits::digits - 1); + while (C < X && C < CMax) + C <<= 1; + return C; + } + // Make sure that SmallSize is a power of two, round up if not. - enum { SmallSizePowTwo = RoundUpToPowerOfTwo::Val }; + static constexpr size_t SmallSizePowTwo = RoundUpToPowerOfTwo(SmallSize); /// SmallStorage - Fixed size storage used in 'small mode'. const void *SmallStorage[SmallSizePowTwo]; diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h index b86254f56d9..0747e8d72e1 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/SmallVector.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/WindowsError.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/WindowsError.h index 54a52369324..172cc70fac8 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/WindowsError.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/WindowsError.h @@ -12,6 +12,7 @@ #include namespace wpi { +std::error_code mapLastWindowsError(); std::error_code mapWindowsError(unsigned EV); } diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h index 3e0b56b7043..0f8418035ff 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/iterator_range.h @@ -48,9 +48,10 @@ class iterator_range { // See https://github.com/llvm/llvm-project/issues/63843 template #else - template , IteratorT>::value> * = nullptr> + template < + typename Container, + std::enable_if_t, IteratorT>::value> * = nullptr> #endif iterator_range(Container &&c) : begin_iterator(adl_begin(c)), end_iterator(adl_end(c)) { @@ -65,7 +66,8 @@ class iterator_range { }; template -iterator_range(Container &&) -> iterator_range>; +iterator_range(Container &&) + -> iterator_range>; /// Convenience function for iterating over sub-ranges. /// diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/raw_ostream.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/raw_ostream.h index 06ff2063fdb..2b1c8d10af7 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/raw_ostream.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/raw_ostream.h @@ -46,6 +46,7 @@ class raw_ostream { enum class OStreamKind { OK_OStream, OK_FDStream, + OK_SVecStream, }; private: @@ -71,10 +72,6 @@ class raw_ostream { /// this buffer. char *OutBufStart, *OutBufEnd, *OutBufCur; - /// Optional stream this stream is tied to. If this stream is written to, the - /// tied-to stream will be flushed first. - raw_ostream *TiedStream = nullptr; - enum class BufferKind { Unbuffered = 0, InternalBuffer, @@ -92,6 +89,14 @@ class raw_ostream { MAGENTA, CYAN, WHITE, + BRIGHT_BLACK, + BRIGHT_RED, + BRIGHT_GREEN, + BRIGHT_YELLOW, + BRIGHT_BLUE, + BRIGHT_MAGENTA, + BRIGHT_CYAN, + BRIGHT_WHITE, SAVEDCOLOR, RESET, }; @@ -104,6 +109,14 @@ class raw_ostream { static constexpr Colors MAGENTA = Colors::MAGENTA; static constexpr Colors CYAN = Colors::CYAN; static constexpr Colors WHITE = Colors::WHITE; + static constexpr Colors BRIGHT_BLACK = Colors::BRIGHT_BLACK; + static constexpr Colors BRIGHT_RED = Colors::BRIGHT_RED; + static constexpr Colors BRIGHT_GREEN = Colors::BRIGHT_GREEN; + static constexpr Colors BRIGHT_YELLOW = Colors::BRIGHT_YELLOW; + static constexpr Colors BRIGHT_BLUE = Colors::BRIGHT_BLUE; + static constexpr Colors BRIGHT_MAGENTA = Colors::BRIGHT_MAGENTA; + static constexpr Colors BRIGHT_CYAN = Colors::BRIGHT_CYAN; + static constexpr Colors BRIGHT_WHITE = Colors::BRIGHT_WHITE; static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR; static constexpr Colors RESET = Colors::RESET; @@ -320,10 +333,6 @@ class raw_ostream { bool colors_enabled() const { return false; } - /// Tie this stream to the specified stream. Replaces any existing tied-to - /// stream. Specifying a nullptr unties the stream. - void tie(raw_ostream *TieTo) { TiedStream = TieTo; } - //===--------------------------------------------------------------------===// // Subclass Interface //===--------------------------------------------------------------------===// @@ -383,9 +392,6 @@ class raw_ostream { /// unused bytes in the buffer. void copy_to_buffer(const char *Ptr, size_t Size); - /// Flush the tied-to stream (if present) and then write the required data. - void flush_tied_then_write(const char *Ptr, size_t Size); - virtual void anchor(); }; @@ -435,6 +441,10 @@ class raw_fd_ostream : public raw_pwrite_stream { bool SupportsSeeking = false; bool IsRegularFile = false; + /// Optional stream this stream is tied to. If this stream is written to, the + /// tied-to stream will be flushed first. + raw_ostream *TiedStream = nullptr; + #ifdef _WIN32 /// True if this fd refers to a Windows console device. Mintty and other /// terminal emulators are TTYs, but they are not consoles. @@ -509,6 +519,13 @@ class raw_fd_ostream : public raw_pwrite_stream { /// to the offset specified from the beginning of the file. uint64_t seek(uint64_t off); + /// Tie this stream to the specified stream. Replaces any existing tied-to + /// stream. Specifying a nullptr unties the stream. This is intended for to + /// tie errs() to outs(), so that outs() is flushed whenever something is + /// written to errs(), preventing weird and hard-to-test output when stderr + /// is redirected to stdout. + void tie(raw_ostream *TieTo) { TiedStream = TieTo; } + std::error_code error() const { return EC; } /// Return the value of the flag in this raw_fd_ostream indicating whether an @@ -615,7 +632,11 @@ class raw_svector_ostream : public raw_pwrite_stream { /// /// \param O The vector to write to; this should generally have at least 128 /// bytes free to avoid any extraneous memory overhead. - explicit raw_svector_ostream(SmallVectorImpl &O) : OS(O) { + explicit raw_svector_ostream(SmallVectorImpl &O) + : raw_pwrite_stream(false, raw_ostream::OStreamKind::OK_SVecStream), + OS(O) { + // FIXME: here and in a few other places, set directly to unbuffered in the + // ctor. SetUnbuffered(); } @@ -625,10 +646,13 @@ class raw_svector_ostream : public raw_pwrite_stream { /// Return a std::string_view for the vector contents. std::string_view str() const { return std::string_view(OS.data(), OS.size()); } + SmallVectorImpl &buffer() { return OS; } void reserveExtraSpace(uint64_t ExtraSize) override { OS.reserve(tell() + ExtraSize); } + + static bool classof(const raw_ostream *OS); }; /// A raw_ostream that writes to a vector. This is a diff --git a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/xxhash.h b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/xxhash.h index e0284bc523f..1a651c27732 100644 --- a/wpiutil/src/main/native/thirdparty/llvm/include/wpi/xxhash.h +++ b/wpiutil/src/main/native/thirdparty/llvm/include/wpi/xxhash.h @@ -44,6 +44,7 @@ #include namespace wpi { + uint64_t xxHash64(std::string_view Data); uint64_t xxHash64(std::span Data); @@ -51,6 +52,30 @@ uint64_t xxh3_64bits(std::span data); inline uint64_t xxh3_64bits(std::string_view data) { return xxh3_64bits(std::span(reinterpret_cast(data.data()), data.size())); } -} + +/*-********************************************************************** + * XXH3 128-bit variant + ************************************************************************/ + +/*! + * @brief The return value from 128-bit hashes. + * + * Stored in little endian order, although the fields themselves are in native + * endianness. + */ +struct XXH128_hash_t { + uint64_t low64; /*!< `value & 0xFFFFFFFFFFFFFFFF` */ + uint64_t high64; /*!< `value >> 64` */ + + /// Convenience equality check operator. + bool operator==(const XXH128_hash_t rhs) const { + return low64 == rhs.low64 && high64 == rhs.high64; + } +}; + +/// XXH3's 128-bit variant. +XXH128_hash_t xxh3_128bits(std::span data); + +} // namespace wpi #endif diff --git a/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.cpp b/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.cpp new file mode 100644 index 00000000000..ee64f57832a --- /dev/null +++ b/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.cpp @@ -0,0 +1,17 @@ +//===- llvm/unittest/ADT/CountCopyAndMove.cpp - Optional unit tests -------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "CountCopyAndMove.h" + +using namespace wpi; + +int CountCopyAndMove::CopyConstructions = 0; +int CountCopyAndMove::CopyAssignments = 0; +int CountCopyAndMove::MoveConstructions = 0; +int CountCopyAndMove::MoveAssignments = 0; +int CountCopyAndMove::Destructions = 0; diff --git a/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.h b/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.h new file mode 100644 index 00000000000..3a8bd22a50e --- /dev/null +++ b/wpiutil/src/test/native/cpp/llvm/CountCopyAndMove.h @@ -0,0 +1,57 @@ +//===- llvm/unittest/ADT/CountCopyAndMove.h - Optional unit tests ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H +#define LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H + +namespace wpi { + +struct CountCopyAndMove { + static int CopyConstructions; + static int CopyAssignments; + static int MoveConstructions; + static int MoveAssignments; + static int Destructions; + int val; + + CountCopyAndMove() = default; + explicit CountCopyAndMove(int val) : val(val) {} + CountCopyAndMove(const CountCopyAndMove &other) : val(other.val) { + ++CopyConstructions; + } + CountCopyAndMove &operator=(const CountCopyAndMove &other) { + val = other.val; + ++CopyAssignments; + return *this; + } + CountCopyAndMove(CountCopyAndMove &&other) : val(other.val) { + ++MoveConstructions; + } + CountCopyAndMove &operator=(CountCopyAndMove &&other) { + val = other.val; + ++MoveAssignments; + return *this; + } + ~CountCopyAndMove() { ++Destructions; } + + static void ResetCounts() { + CopyConstructions = 0; + CopyAssignments = 0; + MoveConstructions = 0; + MoveAssignments = 0; + Destructions = 0; + } + + static int TotalCopies() { return CopyConstructions + CopyAssignments; } + + static int TotalMoves() { return MoveConstructions + MoveAssignments; } +}; + +} // end namespace wpi + +#endif // LLVM_UNITTESTS_ADT_COUNTCOPYANDMOVE_H diff --git a/wpiutil/src/test/native/cpp/llvm/DenseMapTest.cpp b/wpiutil/src/test/native/cpp/llvm/DenseMapTest.cpp index 22e535e837d..2358a38f709 100644 --- a/wpiutil/src/test/native/cpp/llvm/DenseMapTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/DenseMapTest.cpp @@ -11,6 +11,7 @@ #endif #include "wpi/DenseMap.h" +#include "CountCopyAndMove.h" #include "wpi/DenseMapInfo.h" #include "wpi/DenseMapInfoVariant.h" #include "gmock/gmock.h" @@ -24,7 +25,6 @@ using namespace wpi; namespace { - uint32_t getTestKey(int i, uint32_t *) { return i; } uint32_t getTestValue(int i, uint32_t *) { return 42 + i; } @@ -39,6 +39,14 @@ uint32_t *getTestValue(int i, uint32_t **) { return &dummy_arr1[i]; } +enum class EnumClass { Val }; + +EnumClass getTestKey(int i, EnumClass *) { + // We can't possibly support 100 values for the swap test, so just return an + // invalid EnumClass for testing. + return static_cast(i); +} + /// A test class that tries to check that construction and destruction /// occur correctly. class CtorTester { @@ -107,14 +115,19 @@ template typename T::mapped_type *const DenseMapTest::dummy_value_ptr = nullptr; // Register these types for testing. +// clang-format off typedef ::testing::Types, DenseMap, DenseMap, + DenseMap, SmallDenseMap, SmallDenseMap, SmallDenseMap + CtorTesterMapInfo>, + SmallDenseMap > DenseMapTestTypes; +// clang-format on + TYPED_TEST_SUITE(DenseMapTest, DenseMapTestTypes, ); // Empty map tests @@ -350,29 +363,6 @@ TYPED_TEST(DenseMapTest, ConstIteratorTest) { EXPECT_TRUE(cit == cit2); } -namespace { -// Simple class that counts how many moves and copy happens when growing a map -struct CountCopyAndMove { - static int Move; - static int Copy; - CountCopyAndMove() {} - - CountCopyAndMove(const CountCopyAndMove &) { Copy++; } - CountCopyAndMove &operator=(const CountCopyAndMove &) { - Copy++; - return *this; - } - CountCopyAndMove(CountCopyAndMove &&) { Move++; } - CountCopyAndMove &operator=(const CountCopyAndMove &&) { - Move++; - return *this; - } -}; -int CountCopyAndMove::Copy = 0; -int CountCopyAndMove::Move = 0; - -} // anonymous namespace - // Test initializer list construction. TEST(DenseMapCustomTest, InitializerList) { DenseMap M({{0, 0}, {0, 1}, {1, 2}}); @@ -405,8 +395,8 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) { // Will allocate 64 buckets Map.reserve(1); unsigned MemorySize = Map.getMemorySize(); - CountCopyAndMove::Copy = 0; - CountCopyAndMove::Move = 0; + CountCopyAndMove::ResetCounts(); + for (int i = 0; i < ExpectedMaxInitialEntries; ++i) Map.insert(std::pair(std::piecewise_construct, std::forward_as_tuple(i), @@ -414,9 +404,9 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) { // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - EXPECT_EQ(ExpectedMaxInitialEntries, CountCopyAndMove::Move); + EXPECT_EQ(ExpectedMaxInitialEntries, CountCopyAndMove::TotalMoves()); // Check that no copy occurred - EXPECT_EQ(0, CountCopyAndMove::Copy); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); // Adding one extra element should grow the map Map.insert(std::pair( @@ -429,7 +419,7 @@ TEST(DenseMapCustomTest, DefaultMinReservedSizeTest) { // This relies on move-construction elision, and cannot be reliably tested. // EXPECT_EQ(ExpectedMaxInitialEntries + 2, CountCopyAndMove::Move); // Check that no copy occurred - EXPECT_EQ(0, CountCopyAndMove::Copy); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); } // Make sure creating the map with an initial size of N actually gives us enough @@ -443,8 +433,8 @@ TEST(DenseMapCustomTest, InitialSizeTest) { for (auto Size : {1, 2, 48, 66}) { DenseMap Map(Size); unsigned MemorySize = Map.getMemorySize(); - CountCopyAndMove::Copy = 0; - CountCopyAndMove::Move = 0; + CountCopyAndMove::ResetCounts(); + for (int i = 0; i < Size; ++i) Map.insert(std::pair(std::piecewise_construct, std::forward_as_tuple(i), @@ -452,9 +442,9 @@ TEST(DenseMapCustomTest, InitialSizeTest) { // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - EXPECT_EQ(Size, CountCopyAndMove::Move); + EXPECT_EQ(Size, CountCopyAndMove::TotalMoves()); // Check that no copy occurred - EXPECT_EQ(0, CountCopyAndMove::Copy); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); } } @@ -465,15 +455,14 @@ TEST(DenseMapCustomTest, InitFromIterator) { const int Count = 65; Values.reserve(Count); for (int i = 0; i < Count; i++) - Values.emplace_back(i, CountCopyAndMove()); + Values.emplace_back(i, CountCopyAndMove(i)); - CountCopyAndMove::Move = 0; - CountCopyAndMove::Copy = 0; + CountCopyAndMove::ResetCounts(); DenseMap Map(Values.begin(), Values.end()); // Check that no move occurred - EXPECT_EQ(0, CountCopyAndMove::Move); + EXPECT_EQ(0, CountCopyAndMove::TotalMoves()); // Check that copy was called the expected number of times - EXPECT_EQ(Count, CountCopyAndMove::Copy); + EXPECT_EQ(Count, CountCopyAndMove::TotalCopies()); } // Make sure reserve actually gives us enough buckets to insert N items @@ -488,8 +477,7 @@ TEST(DenseMapCustomTest, ReserveTest) { DenseMap Map; Map.reserve(Size); unsigned MemorySize = Map.getMemorySize(); - CountCopyAndMove::Copy = 0; - CountCopyAndMove::Move = 0; + CountCopyAndMove::ResetCounts(); for (int i = 0; i < Size; ++i) Map.insert(std::pair(std::piecewise_construct, std::forward_as_tuple(i), @@ -497,12 +485,48 @@ TEST(DenseMapCustomTest, ReserveTest) { // Check that we didn't grow EXPECT_EQ(MemorySize, Map.getMemorySize()); // Check that move was called the expected number of times - EXPECT_EQ(Size, CountCopyAndMove::Move); + EXPECT_EQ(Size, CountCopyAndMove::TotalMoves()); // Check that no copy occurred - EXPECT_EQ(0, CountCopyAndMove::Copy); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); } } +TEST(DenseMapCustomTest, InsertOrAssignTest) { + DenseMap Map; + + CountCopyAndMove val1(1); + CountCopyAndMove::ResetCounts(); + auto try0 = Map.insert_or_assign(0, val1); + EXPECT_TRUE(try0.second); + EXPECT_EQ(0, CountCopyAndMove::TotalMoves()); + EXPECT_EQ(1, CountCopyAndMove::CopyConstructions); + EXPECT_EQ(0, CountCopyAndMove::CopyAssignments); + + CountCopyAndMove::ResetCounts(); + auto try1 = Map.insert_or_assign(0, val1); + EXPECT_FALSE(try1.second); + EXPECT_EQ(0, CountCopyAndMove::TotalMoves()); + EXPECT_EQ(0, CountCopyAndMove::CopyConstructions); + EXPECT_EQ(1, CountCopyAndMove::CopyAssignments); + + int key2 = 2; + CountCopyAndMove val2(2); + CountCopyAndMove::ResetCounts(); + auto try2 = Map.insert_or_assign(key2, std::move(val2)); + EXPECT_TRUE(try2.second); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(1, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(0, CountCopyAndMove::MoveAssignments); + + CountCopyAndMove val3(3); + CountCopyAndMove::ResetCounts(); + auto try3 = Map.insert_or_assign(key2, std::move(val3)); + EXPECT_FALSE(try3.second); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(0, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(1, CountCopyAndMove::MoveAssignments); +} + // Key traits that allows lookup with either an unsigned or char* key; // In the latter case, "a" == 0, "b" == 1 and so on. struct TestDenseMapInfo { diff --git a/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp b/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp index a8234552f79..6784747c504 100644 --- a/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/EndianTest.cpp @@ -35,6 +35,29 @@ TEST(Endian, Read) { 1))); } +TEST(Endian, WriteNext) { + unsigned char bigval[] = {0x00, 0x00}, *p = bigval; + endian::writeNext(p, short(0xaabb)); + EXPECT_EQ(bigval[0], 0xaa); + EXPECT_EQ(bigval[1], 0xbb); + EXPECT_EQ(p, bigval + 2); + + char littleval[8] = {}, *q = littleval; + endian::writeNext(q, 0x44556677); + EXPECT_EQ(littleval[0], 0x77); + EXPECT_EQ(littleval[1], 0x66); + EXPECT_EQ(littleval[2], 0x55); + EXPECT_EQ(littleval[3], 0x44); + EXPECT_EQ(q, littleval + 4); + + endian::writeNext(q, 0x11223344, wpi::endianness::little); + EXPECT_EQ(littleval[4], 0x44); + EXPECT_EQ(littleval[5], 0x33); + EXPECT_EQ(littleval[6], 0x22); + EXPECT_EQ(littleval[7], 0x11); + EXPECT_EQ(q, littleval + 8); +} + TEST(Endian, ReadBitAligned) { // Simple test to make sure we properly pull out the 0x0 word. unsigned char littleval[] = {0x3f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff}; diff --git a/wpiutil/src/test/native/cpp/llvm/MathExtrasTest.cpp b/wpiutil/src/test/native/cpp/llvm/MathExtrasTest.cpp index eab7ba15d12..83f1ba8c9b7 100644 --- a/wpiutil/src/test/native/cpp/llvm/MathExtrasTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/MathExtrasTest.cpp @@ -8,6 +8,7 @@ #include "wpi/MathExtras.h" #include "gtest/gtest.h" +#include using namespace wpi; @@ -41,6 +42,9 @@ TEST(MathExtras, onesMask) { TEST(MathExtras, isIntN) { EXPECT_TRUE(isIntN(16, 32767)); EXPECT_FALSE(isIntN(16, 32768)); + EXPECT_TRUE(isIntN(0, 0)); + EXPECT_FALSE(isIntN(0, 1)); + EXPECT_FALSE(isIntN(0, -1)); } TEST(MathExtras, isUIntN) { @@ -48,6 +52,8 @@ TEST(MathExtras, isUIntN) { EXPECT_FALSE(isUIntN(16, 65536)); EXPECT_TRUE(isUIntN(1, 0)); EXPECT_TRUE(isUIntN(6, 63)); + EXPECT_TRUE(isUIntN(0, 0)); + EXPECT_FALSE(isUIntN(0, 1)); } TEST(MathExtras, maxIntN) { @@ -55,6 +61,7 @@ TEST(MathExtras, maxIntN) { EXPECT_EQ(2147483647, maxIntN(32)); EXPECT_EQ(std::numeric_limits::max(), maxIntN(32)); EXPECT_EQ(std::numeric_limits::max(), maxIntN(64)); + EXPECT_EQ(0, maxIntN(0)); } TEST(MathExtras, minIntN) { @@ -62,6 +69,7 @@ TEST(MathExtras, minIntN) { EXPECT_EQ(-64LL, minIntN(7)); EXPECT_EQ(std::numeric_limits::min(), minIntN(32)); EXPECT_EQ(std::numeric_limits::min(), minIntN(64)); + EXPECT_EQ(0, minIntN(0)); } TEST(MathExtras, maxUIntN) { @@ -70,6 +78,7 @@ TEST(MathExtras, maxUIntN) { EXPECT_EQ(0xffffffffffffffffULL, maxUIntN(64)); EXPECT_EQ(1ULL, maxUIntN(1)); EXPECT_EQ(0x0fULL, maxUIntN(4)); + EXPECT_EQ(0ULL, maxUIntN(0)); } TEST(MathExtras, reverseBits) { @@ -167,6 +176,7 @@ TEST(MathExtras, MinAlign) { EXPECT_EQ(2u, MinAlign(2, 4)); EXPECT_EQ(1u, MinAlign(17, 64)); EXPECT_EQ(256u, MinAlign(256, 512)); + EXPECT_EQ(2u, MinAlign(0, 2)); } TEST(MathExtras, NextPowerOf2) { @@ -175,15 +185,48 @@ TEST(MathExtras, NextPowerOf2) { EXPECT_EQ(256u, NextPowerOf2(128)); } -TEST(MathExtras, alignTo) { +TEST(MathExtras, AlignTo) { EXPECT_EQ(8u, alignTo(5, 8)); EXPECT_EQ(24u, alignTo(17, 8)); EXPECT_EQ(0u, alignTo(~0LL, 8)); + EXPECT_EQ(8u, alignTo(5ULL, 8ULL)); + + EXPECT_EQ(8u, alignTo<8>(5)); + EXPECT_EQ(24u, alignTo<8>(17)); + EXPECT_EQ(0u, alignTo<8>(~0LL)); + EXPECT_EQ(254u, + alignTo(127)>(static_cast(200))); EXPECT_EQ(7u, alignTo(5, 8, 7)); EXPECT_EQ(17u, alignTo(17, 8, 1)); EXPECT_EQ(3u, alignTo(~0LL, 8, 3)); EXPECT_EQ(552u, alignTo(321, 255, 42)); + EXPECT_EQ(std::numeric_limits::max(), + alignTo(std::numeric_limits::max(), 2, 1)); + + // Overflow. + EXPECT_EQ(0u, alignTo(static_cast(200), static_cast(128))); + EXPECT_EQ(0u, alignTo(128)>(static_cast(200))); + EXPECT_EQ(0u, alignTo(static_cast(200), static_cast(128), + static_cast(0))); + EXPECT_EQ(0u, alignTo(std::numeric_limits::max(), 2)); +} + +TEST(MathExtras, AlignToPowerOf2) { + EXPECT_EQ(0u, alignToPowerOf2(0u, 8)); + EXPECT_EQ(8u, alignToPowerOf2(5, 8)); + EXPECT_EQ(24u, alignToPowerOf2(17, 8)); + EXPECT_EQ(0u, alignToPowerOf2(~0LL, 8)); + EXPECT_EQ(240u, alignToPowerOf2(240, 16)); + EXPECT_EQ(static_cast(std::numeric_limits::max()) + 1, + alignToPowerOf2(std::numeric_limits::max(), 2)); +} + +TEST(MathExtras, AlignDown) { + EXPECT_EQ(0u, alignDown(5, 8)); + EXPECT_EQ(16u, alignDown(17, 8)); + EXPECT_EQ(std::numeric_limits::max() - 1, + alignDown(std::numeric_limits::max(), 2)); } template void SaturatingAddTestHelper() { @@ -426,8 +469,102 @@ TEST(MathExtras, IsShiftedInt) { EXPECT_FALSE((isShiftedInt<6, 10>(int64_t(1) << 15))); } -template -class OverflowTest : public ::testing::Test { }; +TEST(MathExtras, DivideNearest) { + EXPECT_EQ(divideNearest(14, 3), 5u); + EXPECT_EQ(divideNearest(15, 3), 5u); + EXPECT_EQ(divideNearest(0, 3), 0u); + EXPECT_EQ(divideNearest(5, 4), 1u); + EXPECT_EQ(divideNearest(6, 4), 2u); + EXPECT_EQ(divideNearest(3, 1), 3u); + EXPECT_EQ(divideNearest(3, 6), 1u); + EXPECT_EQ(divideNearest(3, 7), 0u); + EXPECT_EQ(divideNearest(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideNearest(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideNearest(std::numeric_limits::max(), 1), + std::numeric_limits::max()); + EXPECT_EQ(divideNearest(std::numeric_limits::max() - 1, + std::numeric_limits::max()), + 1u); +} + +TEST(MathExtras, DivideCeil) { + EXPECT_EQ(divideCeil(14, 3), 5u); + EXPECT_EQ(divideCeil(15, 3), 5u); + EXPECT_EQ(divideCeil(0, 3), 0u); + EXPECT_EQ(divideCeil(5, 4), 2u); + EXPECT_EQ(divideCeil(6, 4), 2u); + EXPECT_EQ(divideCeil(3, 1), 3u); + EXPECT_EQ(divideCeil(3, 6), 1u); + EXPECT_EQ(divideCeil(3, 7), 1u); + EXPECT_EQ(divideCeil(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideCeil(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideCeil(std::numeric_limits::max(), 1), + std::numeric_limits::max()); + + EXPECT_EQ(divideCeilSigned(14, 3), 5); + EXPECT_EQ(divideCeilSigned(15, 3), 5); + EXPECT_EQ(divideCeilSigned(14, -3), -4); + EXPECT_EQ(divideCeilSigned(-14, -3), 5); + EXPECT_EQ(divideCeilSigned(-14, 3), -4); + EXPECT_EQ(divideCeilSigned(-15, 3), -5); + EXPECT_EQ(divideCeilSigned(0, 3), 0); + EXPECT_EQ(divideCeilSigned(0, -3), 0); + EXPECT_EQ(divideCeilSigned(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideCeilSigned(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2 + 1); + EXPECT_EQ(divideCeilSigned(std::numeric_limits::max(), -2), + std::numeric_limits::min() / 2 + 1); + EXPECT_EQ(divideCeilSigned(std::numeric_limits::max(), -2), + std::numeric_limits::min() / 2 + 1); + EXPECT_EQ(divideCeilSigned(std::numeric_limits::min(), 1), + std::numeric_limits::min()); + + // Overflow. + EXPECT_TRUE( + divideSignedWouldOverflow(std::numeric_limits::min(), -1)); + EXPECT_TRUE( + divideSignedWouldOverflow(std::numeric_limits::min(), -1)); +} + +TEST(MathExtras, DivideFloorSigned) { + EXPECT_EQ(divideFloorSigned(14, 3), 4); + EXPECT_EQ(divideFloorSigned(15, 3), 5); + EXPECT_EQ(divideFloorSigned(14, -3), -5); + EXPECT_EQ(divideFloorSigned(-14, -3), 4); + EXPECT_EQ(divideFloorSigned(-14, 3), -5); + EXPECT_EQ(divideFloorSigned(-15, 3), -5); + EXPECT_EQ(divideFloorSigned(0, 3), 0); + EXPECT_EQ(divideFloorSigned(0, -3), 0); + EXPECT_EQ(divideFloorSigned(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2); + EXPECT_EQ(divideFloorSigned(std::numeric_limits::max(), 2), + std::numeric_limits::max() / 2); + EXPECT_EQ(divideFloorSigned(std::numeric_limits::max(), -2), + std::numeric_limits::min() / 2); + EXPECT_EQ(divideFloorSigned(std::numeric_limits::max(), -2), + std::numeric_limits::min() / 2); + EXPECT_EQ(divideFloorSigned(std::numeric_limits::min(), 1), + std::numeric_limits::min()); + + // Same overflow condition, divideSignedWouldOverflow, applies. +} + +TEST(MathExtras, Mod) { + EXPECT_EQ(mod(1, 14), 1); + EXPECT_EQ(mod(-1, 14), 13); + EXPECT_EQ(mod(14, 3), 2); + EXPECT_EQ(mod(15, 3), 0); + EXPECT_EQ(mod(-14, 3), 1); + EXPECT_EQ(mod(-15, 3), 0); + EXPECT_EQ(mod(0, 3), 0); +} + +template class OverflowTest : public ::testing::Test {}; using OverflowTestTypes = ::testing::Types; @@ -552,5 +689,4 @@ TYPED_TEST(OverflowTest, MulResultZero) { EXPECT_FALSE(MulOverflow(0, -5, Result)); EXPECT_EQ(Result, TypeParam(0)); } - } // namespace diff --git a/wpiutil/src/test/native/cpp/llvm/MoveOnly.cpp b/wpiutil/src/test/native/cpp/llvm/MoveOnly.cpp deleted file mode 100644 index efbf2445f86..00000000000 --- a/wpiutil/src/test/native/cpp/llvm/MoveOnly.cpp +++ /dev/null @@ -1,15 +0,0 @@ -//===- llvm/unittest/ADT/MoveOnly.cpp - Optional unit tests ---------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "MoveOnly.h" - -using namespace wpi; - -unsigned MoveOnly::MoveConstructions = 0; -unsigned MoveOnly::Destructions = 0; -unsigned MoveOnly::MoveAssignments = 0; diff --git a/wpiutil/src/test/native/cpp/llvm/MoveOnly.h b/wpiutil/src/test/native/cpp/llvm/MoveOnly.h deleted file mode 100644 index b9923354ec1..00000000000 --- a/wpiutil/src/test/native/cpp/llvm/MoveOnly.h +++ /dev/null @@ -1,42 +0,0 @@ -//===- llvm/unittest/ADT/MoveOnly.h - Optional unit tests -----------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_UNITTESTS_ADT_MOVEONLY_H -#define LLVM_UNITTESTS_ADT_MOVEONLY_H - -namespace wpi { - -struct MoveOnly { - static unsigned MoveConstructions; - static unsigned Destructions; - static unsigned MoveAssignments; - int val; - explicit MoveOnly(int val) : val(val) { - } - MoveOnly(MoveOnly&& other) { - val = other.val; - ++MoveConstructions; - } - MoveOnly &operator=(MoveOnly&& other) { - val = other.val; - ++MoveAssignments; - return *this; - } - ~MoveOnly() { - ++Destructions; - } - static void ResetCounts() { - MoveConstructions = 0; - Destructions = 0; - MoveAssignments = 0; - } -}; - -} // end namespace wpi - -#endif // LLVM_UNITTESTS_ADT_MOVEONLY_H diff --git a/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp b/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp index 0f0af563cfe..24f4d0c6fe3 100644 --- a/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/STLForwardCompatTest.cpp @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// #include "wpi/STLForwardCompat.h" -#include "MoveOnly.h" +#include "CountCopyAndMove.h" #include "gtest/gtest.h" namespace { @@ -58,27 +58,29 @@ TEST(TransformTest, TransformStd) { } TEST(TransformTest, MoveTransformStd) { - using wpi::MoveOnly; + using wpi::CountCopyAndMove; - std::optional A; + std::optional A; - MoveOnly::ResetCounts(); + CountCopyAndMove::ResetCounts(); std::optional B = wpi::transformOptional( - std::move(A), [&](const MoveOnly &M) { return M.val + 2; }); + std::move(A), [&](const CountCopyAndMove &M) { return M.val + 2; }); EXPECT_FALSE(B.has_value()); - EXPECT_EQ(0u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(0u, MoveOnly::Destructions); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(0, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(0, CountCopyAndMove::MoveAssignments); + EXPECT_EQ(0, CountCopyAndMove::Destructions); - A = MoveOnly(5); - MoveOnly::ResetCounts(); + A = CountCopyAndMove(5); + CountCopyAndMove::ResetCounts(); std::optional C = wpi::transformOptional( - std::move(A), [&](const MoveOnly &M) { return M.val + 2; }); + std::move(A), [&](const CountCopyAndMove &M) { return M.val + 2; }); EXPECT_TRUE(C.has_value()); EXPECT_EQ(7, *C); - EXPECT_EQ(0u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(0u, MoveOnly::Destructions); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(0, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(0, CountCopyAndMove::MoveAssignments); + EXPECT_EQ(0, CountCopyAndMove::Destructions); } TEST(TransformTest, TransformLlvm) { @@ -96,27 +98,29 @@ TEST(TransformTest, TransformLlvm) { } TEST(TransformTest, MoveTransformLlvm) { - using wpi::MoveOnly; + using wpi::CountCopyAndMove; - std::optional A; + std::optional A; - MoveOnly::ResetCounts(); + CountCopyAndMove::ResetCounts(); std::optional B = wpi::transformOptional( - std::move(A), [&](const MoveOnly &M) { return M.val + 2; }); + std::move(A), [&](const CountCopyAndMove &M) { return M.val + 2; }); EXPECT_FALSE(B.has_value()); - EXPECT_EQ(0u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(0u, MoveOnly::Destructions); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(0, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(0, CountCopyAndMove::MoveAssignments); + EXPECT_EQ(0, CountCopyAndMove::Destructions); - A = MoveOnly(5); - MoveOnly::ResetCounts(); + A = CountCopyAndMove(5); + CountCopyAndMove::ResetCounts(); std::optional C = wpi::transformOptional( - std::move(A), [&](const MoveOnly &M) { return M.val + 2; }); + std::move(A), [&](const CountCopyAndMove &M) { return M.val + 2; }); EXPECT_TRUE(C.has_value()); EXPECT_EQ(7, *C); - EXPECT_EQ(0u, MoveOnly::MoveConstructions); - EXPECT_EQ(0u, MoveOnly::MoveAssignments); - EXPECT_EQ(0u, MoveOnly::Destructions); + EXPECT_EQ(0, CountCopyAndMove::TotalCopies()); + EXPECT_EQ(0, CountCopyAndMove::MoveConstructions); + EXPECT_EQ(0, CountCopyAndMove::MoveAssignments); + EXPECT_EQ(0, CountCopyAndMove::Destructions); } TEST(TransformTest, ToUnderlying) { diff --git a/wpiutil/src/test/native/cpp/llvm/SmallPtrSetTest.cpp b/wpiutil/src/test/native/cpp/llvm/SmallPtrSetTest.cpp index 1916d509b11..ea65513e57b 100644 --- a/wpiutil/src/test/native/cpp/llvm/SmallPtrSetTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/SmallPtrSetTest.cpp @@ -244,45 +244,6 @@ TEST(SmallPtrSetTest, SwapTest) { EXPECT_TRUE(a.count(&buf[3])); } -void checkEraseAndIterators(SmallPtrSetImpl &S) { - int buf[3]; - - S.insert(&buf[0]); - S.insert(&buf[1]); - S.insert(&buf[2]); - - // Iterators must still be valid after erase() calls; - auto B = S.begin(); - auto M = std::next(B); - auto E = S.end(); - EXPECT_TRUE(*B == &buf[0] || *B == &buf[1] || *B == &buf[2]); - EXPECT_TRUE(*M == &buf[0] || *M == &buf[1] || *M == &buf[2]); - EXPECT_TRUE(*B != *M); - int *Removable = *std::next(M); - // No iterator points to Removable now. - EXPECT_TRUE(Removable == &buf[0] || Removable == &buf[1] || - Removable == &buf[2]); - EXPECT_TRUE(Removable != *B && Removable != *M); - - S.erase(Removable); - - // B,M,E iterators should still be valid - EXPECT_EQ(B, S.begin()); - EXPECT_EQ(M, std::next(B)); - EXPECT_EQ(E, S.end()); - EXPECT_EQ(std::next(M), E); -} - -TEST(SmallPtrSetTest, EraseTest) { - // Test when set stays small. - SmallPtrSet B; - checkEraseAndIterators(B); - - // Test when set grows big. - SmallPtrSet A; - checkEraseAndIterators(A); -} - // Verify that dereferencing and iteration work. TEST(SmallPtrSetTest, dereferenceAndIterate) { int Ints[] = {0, 1, 2, 3, 4, 5, 6, 7}; @@ -410,3 +371,41 @@ TEST(SmallPtrSetTest, InsertIterator) { for (const auto *Ptr : Buf) EXPECT_TRUE(Set.contains(Ptr)); } + +TEST(SmallPtrSetTest, RemoveIf) { + SmallPtrSet Set; + int Vals[6] = {0, 1, 2, 3, 4, 5}; + + // Stay in small regime. + Set.insert(&Vals[0]); + Set.insert(&Vals[1]); + Set.insert(&Vals[2]); + Set.insert(&Vals[3]); + Set.erase(&Vals[0]); // Leave a tombstone. + + // Remove odd elements. + bool Removed = Set.remove_if([](int *Ptr) { return *Ptr % 2 != 0; }); + // We should only have element 2 left now. + EXPECT_TRUE(Removed); + EXPECT_EQ(Set.size(), 1u); + EXPECT_TRUE(Set.contains(&Vals[2])); + + // Switch to big regime. + Set.insert(&Vals[0]); + Set.insert(&Vals[1]); + Set.insert(&Vals[3]); + Set.insert(&Vals[4]); + Set.insert(&Vals[5]); + Set.erase(&Vals[0]); // Leave a tombstone. + + // Remove odd elements. + Removed = Set.remove_if([](int *Ptr) { return *Ptr % 2 != 0; }); + // We should only have elements 2 and 4 left now. + EXPECT_TRUE(Removed); + EXPECT_EQ(Set.size(), 2u); + EXPECT_TRUE(Set.contains(&Vals[2])); + EXPECT_TRUE(Set.contains(&Vals[4])); + + Removed = Set.remove_if([](int *Ptr) { return false; }); + EXPECT_FALSE(Removed); +} diff --git a/wpiutil/src/test/native/cpp/llvm/xxhashTest.cpp b/wpiutil/src/test/native/cpp/llvm/xxhashTest.cpp index 133c5426ff4..bf66db4b5cf 100644 --- a/wpiutil/src/test/native/cpp/llvm/xxhashTest.cpp +++ b/wpiutil/src/test/native/cpp/llvm/xxhashTest.cpp @@ -11,6 +11,26 @@ using namespace wpi; +/* use #define to make them constant, required for initialization */ +#define PRIME32 2654435761U +#define PRIME64 11400714785074694797ULL + +/* + * Fills a test buffer with pseudorandom data. + * + * This is used in the sanity check - its values must not be changed. + */ +static void fillTestBuffer(uint8_t *buffer, size_t len) { + uint64_t byteGen = PRIME32; + + assert(buffer != NULL); + + for (size_t i = 0; i < len; i++) { + buffer[i] = (uint8_t)(byteGen >> 56); + byteGen *= PRIME64; + } +} + TEST(xxhashTest, Basic) { EXPECT_EQ(0xef46db3751d8e999U, xxHash64(std::string_view())); EXPECT_EQ(0x33bf00a859c4ba3fU, xxHash64("foo")); @@ -61,3 +81,52 @@ TEST(xxhashTest, xxh3) { F(2243, 0x0979f786a24edde7); #undef F } + +TEST(xxhashTest, xxh3_128bits) { +#define SANITY_BUFFER_SIZE 2367 + uint8_t sanityBuffer[SANITY_BUFFER_SIZE]; + + fillTestBuffer(sanityBuffer, sizeof(sanityBuffer)); + +#define F(len, expected) \ + EXPECT_EQ(XXH128_hash_t(expected), \ + xxh3_128bits(std::span(sanityBuffer, size_t(len)))) + + F(0, (XXH128_hash_t{0x6001C324468D497FULL, + 0x99AA06D3014798D8ULL})); /* empty string */ + F(1, (XXH128_hash_t{0xC44BDFF4074EECDBULL, + 0xA6CD5E9392000F6AULL})); /* 1 - 3 */ + F(6, (XXH128_hash_t{0x3E7039BDDA43CFC6ULL, + 0x082AFE0B8162D12AULL})); /* 4 - 8 */ + F(12, (XXH128_hash_t{0x061A192713F69AD9ULL, + 0x6E3EFD8FC7802B18ULL})); /* 9 - 16 */ + F(24, (XXH128_hash_t{0x1E7044D28B1B901DULL, + 0x0CE966E4678D3761ULL})); /* 17 - 32 */ + F(48, (XXH128_hash_t{0xF942219AED80F67BULL, + 0xA002AC4E5478227EULL})); /* 33 - 64 */ + F(81, (XXH128_hash_t{0x5E8BAFB9F95FB803ULL, + 0x4952F58181AB0042ULL})); /* 65 - 96 */ + F(222, (XXH128_hash_t{0xF1AEBD597CEC6B3AULL, + 0x337E09641B948717ULL})); /* 129-240 */ + F(403, + (XXH128_hash_t{ + 0xCDEB804D65C6DEA4ULL, + 0x1B6DE21E332DD73DULL})); /* one block, last stripe is overlapping */ + F(512, + (XXH128_hash_t{ + 0x617E49599013CB6BULL, + 0x18D2D110DCC9BCA1ULL})); /* one block, finishing at stripe boundary */ + F(2048, + (XXH128_hash_t{ + 0xDD59E2C3A5F038E0ULL, + 0xF736557FD47073A5ULL})); /* 2 blocks, finishing at block boundary */ + F(2240, + (XXH128_hash_t{ + 0x6E73A90539CF2948ULL, + 0xCCB134FBFA7CE49DULL})); /* 3 blocks, finishing at stripe boundary */ + F(2367, + (XXH128_hash_t{ + 0xCB37AEB9E5D361EDULL, + 0xE89C0F6FF369B427ULL})); /* 3 blocks, last stripe is overlapping */ +#undef F +}