2023-05-16 09:41:46 -07:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-05-20 18:59:53 -04:00
|
|
|
From: PJ Reiniger <pj.reiniger@gmail.com>
|
|
|
|
|
Date: Sat, 7 May 2022 22:09:18 -0400
|
2026-05-26 21:55:50 -07:00
|
|
|
Subject: [PATCH 01/34] Remove StringRef, ArrayRef, and Optional
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
---
|
2024-03-17 18:39:03 -07:00
|
|
|
llvm/include/llvm/ADT/PointerUnion.h | 1 -
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/include/llvm/ADT/SmallString.h | 101 ++++++++++--------
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/include/llvm/ADT/SmallVector.h | 9 +-
|
|
|
|
|
llvm/include/llvm/Support/Chrono.h | 12 +--
|
2024-03-17 18:39:03 -07:00
|
|
|
llvm/include/llvm/Support/Compiler.h | 2 +-
|
|
|
|
|
llvm/include/llvm/Support/ConvertUTF.h | 31 +++---
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/include/llvm/Support/ErrorHandling.h | 16 +--
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/include/llvm/Support/VersionTuple.h | 6 --
|
2024-03-17 18:39:03 -07:00
|
|
|
.../llvm/Support/Windows/WindowsSupport.h | 4 +-
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/include/llvm/Support/raw_ostream.h | 46 ++++----
|
2025-06-25 01:36:22 -04:00
|
|
|
llvm/lib/Support/ConvertUTFWrapper.cpp | 39 +++----
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/lib/Support/ErrorHandling.cpp | 21 ++--
|
2024-03-17 18:39:03 -07:00
|
|
|
llvm/lib/Support/SmallVector.cpp | 5 +-
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/lib/Support/VersionTuple.cpp | 49 ---------
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/lib/Support/raw_ostream.cpp | 25 +++--
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/unittests/ADT/DenseMapTest.cpp | 33 +-----
|
2024-12-24 17:40:31 -08:00
|
|
|
llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +--
|
2024-03-17 18:39:03 -07:00
|
|
|
llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 -
|
|
|
|
|
llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++-----
|
2026-05-26 16:25:29 -07:00
|
|
|
llvm/unittests/ADT/SmallVectorTest.cpp | 36 ++-----
|
2025-06-25 01:36:22 -04:00
|
|
|
llvm/unittests/Support/ConvertUTFTest.cpp | 42 ++++----
|
2026-05-26 16:25:29 -07:00
|
|
|
21 files changed, 226 insertions(+), 315 deletions(-)
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2022-08-15 05:38:15 -07:00
|
|
|
diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index d9087dd1c516ee265aa00851ca98b1df09936f3e..c3d6458777d186a700c359089c4afcac8db0185a 100644
|
2022-08-15 05:38:15 -07:00
|
|
|
--- a/llvm/include/llvm/ADT/PointerUnion.h
|
|
|
|
|
+++ b/llvm/include/llvm/ADT/PointerUnion.h
|
|
|
|
|
@@ -17,7 +17,6 @@
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
|
|
|
|
#include "llvm/ADT/PointerIntPair.h"
|
|
|
|
|
-#include "llvm/ADT/STLExtras.h"
|
2023-07-12 22:50:13 -07:00
|
|
|
#include "llvm/Support/Casting.h"
|
2022-08-15 05:38:15 -07:00
|
|
|
#include "llvm/Support/PointerLikeTypeTraits.h"
|
|
|
|
|
#include <algorithm>
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h
|
2024-12-24 17:40:31 -08:00
|
|
|
index be3193c6ef9beba622f39e3e76cd0f0c6dd422b0..9fab1a7726bc6745296f5ebb24aee4055408e5f5 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/ADT/SmallString.h
|
|
|
|
|
+++ b/llvm/include/llvm/ADT/SmallString.h
|
2022-08-15 05:38:15 -07:00
|
|
|
@@ -15,8 +15,9 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
#define LLVM_ADT_SMALLSTRING_H
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
-#include "llvm/ADT/StringRef.h"
|
|
|
|
|
#include <cstddef>
|
2022-08-15 05:38:15 -07:00
|
|
|
+#include <string>
|
2022-05-20 18:59:53 -04:00
|
|
|
+#include <string_view>
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
2022-08-15 05:38:15 -07:00
|
|
|
@@ -28,11 +29,11 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// Default ctor - Initialize to empty.
|
|
|
|
|
SmallString() = default;
|
|
|
|
|
|
|
|
|
|
- /// Initialize from a StringRef.
|
|
|
|
|
- SmallString(StringRef S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {}
|
|
|
|
|
+ /// Initialize from a std::string_view.
|
|
|
|
|
+ SmallString(std::string_view S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {}
|
|
|
|
|
|
|
|
|
|
- /// Initialize by concatenating a list of StringRefs.
|
|
|
|
|
- SmallString(std::initializer_list<StringRef> Refs)
|
|
|
|
|
+ /// Initialize by concatenating a list of std::string_views.
|
|
|
|
|
+ SmallString(std::initializer_list<std::string_view> Refs)
|
|
|
|
|
: SmallVector<char, InternalLen>() {
|
|
|
|
|
this->append(Refs);
|
|
|
|
|
}
|
2022-08-15 05:38:15 -07:00
|
|
|
@@ -47,13 +48,13 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
using SmallVector<char, InternalLen>::assign;
|
|
|
|
|
|
|
|
|
|
- /// Assign from a StringRef.
|
|
|
|
|
- void assign(StringRef RHS) {
|
|
|
|
|
+ /// Assign from a std::string_view.
|
|
|
|
|
+ void assign(std::string_view RHS) {
|
|
|
|
|
SmallVectorImpl<char>::assign(RHS.begin(), RHS.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- /// Assign from a list of StringRefs.
|
|
|
|
|
- void assign(std::initializer_list<StringRef> Refs) {
|
|
|
|
|
+ /// Assign from a list of std::string_views.
|
|
|
|
|
+ void assign(std::initializer_list<std::string_view> Refs) {
|
|
|
|
|
this->clear();
|
|
|
|
|
append(Refs);
|
|
|
|
|
}
|
2022-08-15 05:38:15 -07:00
|
|
|
@@ -64,19 +65,19 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
using SmallVector<char, InternalLen>::append;
|
|
|
|
|
|
|
|
|
|
- /// Append from a StringRef.
|
|
|
|
|
- void append(StringRef RHS) {
|
|
|
|
|
+ /// Append from a std::string_view.
|
|
|
|
|
+ void append(std::string_view RHS) {
|
|
|
|
|
SmallVectorImpl<char>::append(RHS.begin(), RHS.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- /// Append from a list of StringRefs.
|
|
|
|
|
- void append(std::initializer_list<StringRef> Refs) {
|
|
|
|
|
+ /// Append from a list of std::string_views.
|
|
|
|
|
+ void append(std::initializer_list<std::string_view> Refs) {
|
2022-08-15 05:38:15 -07:00
|
|
|
size_t CurrentSize = this->size();
|
|
|
|
|
size_t SizeNeeded = CurrentSize;
|
2022-05-20 18:59:53 -04:00
|
|
|
- for (const StringRef &Ref : Refs)
|
|
|
|
|
+ for (const std::string_view &Ref : Refs)
|
|
|
|
|
SizeNeeded += Ref.size();
|
2022-08-15 05:38:15 -07:00
|
|
|
this->resize_for_overwrite(SizeNeeded);
|
2022-05-20 18:59:53 -04:00
|
|
|
- for (const StringRef &Ref : Refs) {
|
|
|
|
|
+ for (const std::string_view &Ref : Refs) {
|
2022-08-15 05:38:15 -07:00
|
|
|
std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize);
|
|
|
|
|
CurrentSize += Ref.size();
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -89,26 +90,28 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Check for string equality. This is more efficient than compare() when
|
|
|
|
|
/// the relative ordering of inequal strings isn't needed.
|
2024-12-24 17:40:31 -08:00
|
|
|
- [[nodiscard]] bool equals(StringRef RHS) const { return str() == RHS; }
|
|
|
|
|
+ [[nodiscard]] bool equals(std::string_view RHS) const { return str() == RHS; }
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Check for string equality, ignoring case.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] bool equals_insensitive(StringRef RHS) const {
|
|
|
|
|
+ [[nodiscard]] bool equals_insensitive(std::string_view RHS) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().equals_insensitive(RHS);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:50:13 -07:00
|
|
|
/// 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.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] int compare(StringRef RHS) const { return str().compare(RHS); }
|
|
|
|
|
+ [[nodiscard]] int compare(std::string_view RHS) const {
|
|
|
|
|
+ return str().compare(RHS);
|
|
|
|
|
+ }
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// compare_insensitive - Compare two strings, ignoring case.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] int compare_insensitive(StringRef RHS) const {
|
|
|
|
|
+ [[nodiscard]] int compare_insensitive(std::string_view RHS) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().compare_insensitive(RHS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// compare_numeric - Compare two strings, treating sequences of digits as
|
|
|
|
|
/// numbers.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] int compare_numeric(StringRef RHS) const {
|
|
|
|
|
+ [[nodiscard]] int compare_numeric(std::string_view RHS) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().compare_numeric(RHS);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -116,14 +119,14 @@ public:
|
2024-03-17 18:39:03 -07:00
|
|
|
/// @name String Predicates
|
2022-05-20 18:59:53 -04:00
|
|
|
/// @{
|
|
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
- /// starts_with - Check if this string starts with the given \p Prefix.
|
|
|
|
|
- [[nodiscard]] bool starts_with(StringRef Prefix) const {
|
|
|
|
|
- return str().starts_with(Prefix);
|
|
|
|
|
+ /// startswith - Check if this string starts with the given \p Prefix.
|
|
|
|
|
+ [[nodiscard]] bool startswith(std::string_view Prefix) const {
|
|
|
|
|
+ return str().startswith(Prefix);
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
- /// ends_with - Check if this string ends with the given \p Suffix.
|
|
|
|
|
- [[nodiscard]] bool ends_with(StringRef Suffix) const {
|
|
|
|
|
- return str().ends_with(Suffix);
|
|
|
|
|
+ /// endswith - Check if this string ends with the given \p Suffix.
|
|
|
|
|
+ [[nodiscard]] bool endswith(std::string_view Suffix) const {
|
|
|
|
|
+ return str().endswith(Suffix);
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
/// @}
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -142,7 +145,7 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
///
|
|
|
|
|
/// \returns The index of the first occurrence of \p Str, or npos if not
|
|
|
|
|
/// found.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t find(StringRef Str, size_t From = 0) const {
|
|
|
|
|
+ [[nodiscard]] size_t find(std::string_view Str, size_t From = 0) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().find(Str, From);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -150,7 +153,8 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
///
|
|
|
|
|
/// \returns The index of the last occurrence of \p C, or npos if not
|
|
|
|
|
/// found.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t rfind(char C, size_t From = StringRef::npos) const {
|
|
|
|
|
+ [[nodiscard]] size_t rfind(char C,
|
|
|
|
|
+ size_t From = std::string_view::npos) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().rfind(C, From);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -158,7 +162,9 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
///
|
|
|
|
|
/// \returns The index of the last occurrence of \p Str, or npos if not
|
|
|
|
|
/// found.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t rfind(StringRef Str) const { return str().rfind(Str); }
|
|
|
|
|
+ [[nodiscard]] size_t rfind(std::string_view Str) const {
|
|
|
|
|
+ return str().rfind(Str);
|
|
|
|
|
+ }
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
/// Find the first character in the string that is \p C, or npos if not
|
|
|
|
|
/// found. Same as find.
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -170,7 +176,8 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// not found.
|
|
|
|
|
///
|
|
|
|
|
/// Complexity: O(size() + Chars.size())
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t find_first_of(StringRef Chars, size_t From = 0) const {
|
|
|
|
|
+ [[nodiscard]] size_t find_first_of(std::string_view Chars,
|
|
|
|
|
+ size_t From = 0) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().find_first_of(Chars, From);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -184,15 +191,15 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// \p Chars, or npos if not found.
|
|
|
|
|
///
|
|
|
|
|
/// Complexity: O(size() + Chars.size())
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t find_first_not_of(StringRef Chars,
|
|
|
|
|
+ [[nodiscard]] size_t find_first_not_of(std::string_view Chars,
|
|
|
|
|
size_t From = 0) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().find_first_not_of(Chars, From);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Find the last character in the string that is \p C, or npos if not
|
|
|
|
|
/// found.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t find_last_of(char C,
|
|
|
|
|
- size_t From = StringRef::npos) const {
|
|
|
|
|
+ [[nodiscard]] size_t find_last_of(
|
|
|
|
|
+ char C, size_t From = std::string_view::npos) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().find_last_of(C, From);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -200,8 +207,8 @@ public:
|
2024-03-17 18:39:03 -07:00
|
|
|
/// found.
|
2022-05-20 18:59:53 -04:00
|
|
|
///
|
|
|
|
|
/// Complexity: O(size() + Chars.size())
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t find_last_of(StringRef Chars,
|
|
|
|
|
- size_t From = StringRef::npos) const {
|
|
|
|
|
+ [[nodiscard]] size_t find_last_of(
|
2022-05-20 18:59:53 -04:00
|
|
|
+ std::string_view Chars, size_t From = std::string_view::npos) const {
|
|
|
|
|
return str().find_last_of(Chars, From);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -214,7 +221,9 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Return the number of non-overlapped occurrences of \p Str in the
|
|
|
|
|
/// string.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] size_t count(StringRef Str) const { return str().count(Str); }
|
|
|
|
|
+ [[nodiscard]] size_t count(std::string_view Str) const {
|
|
|
|
|
+ return str().count(Str);
|
|
|
|
|
+ }
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
/// @}
|
|
|
|
|
/// @name Substring Operations
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -229,8 +238,8 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// \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.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] StringRef substr(size_t Start,
|
|
|
|
|
- size_t N = StringRef::npos) const {
|
|
|
|
|
+ [[nodiscard]] std::string_view substr(
|
|
|
|
|
+ size_t Start, size_t N = std::string_view::npos) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().substr(Start, N);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -244,15 +253,15 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// 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.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] StringRef slice(size_t Start, size_t End) const {
|
|
|
|
|
+ [[nodiscard]] std::string_view slice(size_t Start, size_t End) const {
|
2022-05-20 18:59:53 -04:00
|
|
|
return str().slice(Start, End);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extra methods.
|
|
|
|
|
|
|
|
|
|
- /// Explicit conversion to StringRef.
|
2024-03-17 18:39:03 -07:00
|
|
|
- [[nodiscard]] StringRef str() const {
|
|
|
|
|
- return StringRef(this->data(), this->size());
|
2022-05-20 18:59:53 -04:00
|
|
|
+ /// Explicit conversion to std::string_view.
|
2024-03-17 18:39:03 -07:00
|
|
|
+ [[nodiscard]] std::string_view str() const {
|
|
|
|
|
+ return std::string_view(this->begin(), this->size());
|
|
|
|
|
}
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
// TODO: Make this const, if it's safe...
|
2024-12-24 17:40:31 -08:00
|
|
|
@@ -262,20 +271,20 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
return this->data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- /// Implicit conversion to StringRef.
|
|
|
|
|
- operator StringRef() const { return str(); }
|
|
|
|
|
+ /// Implicit conversion to std::string_view.
|
|
|
|
|
+ operator std::string_view() const { return str(); }
|
|
|
|
|
|
|
|
|
|
explicit operator std::string() const {
|
|
|
|
|
return std::string(this->data(), this->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extra operators.
|
|
|
|
|
- SmallString &operator=(StringRef RHS) {
|
|
|
|
|
+ SmallString &operator=(std::string_view RHS) {
|
|
|
|
|
this->assign(RHS);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- SmallString &operator+=(StringRef RHS) {
|
|
|
|
|
+ SmallString &operator+=(std::string_view RHS) {
|
|
|
|
|
this->append(RHS.begin(), RHS.end());
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2023-07-12 22:50:13 -07:00
|
|
|
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index 23d40c3e07675d5c5cb8aa0089920ebd47cd1ccd..4499a51d40da615a3074ece034f7c30a3ddd709e 100644
|
2023-07-12 22:50:13 -07:00
|
|
|
--- a/llvm/include/llvm/ADT/SmallVector.h
|
|
|
|
|
+++ b/llvm/include/llvm/ADT/SmallVector.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -29,13 +29,12 @@
|
2023-07-12 22:50:13 -07:00
|
|
|
#include <limits>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <new>
|
|
|
|
|
+#include <span>
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
|
|
-template <typename T> class ArrayRef;
|
|
|
|
|
-
|
|
|
|
|
template <typename IteratorT> class iterator_range;
|
|
|
|
|
|
|
|
|
|
template <class Iterator>
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -116,7 +115,7 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize {
|
2023-07-12 22:50:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// This is the part of SmallVectorTemplateBase which does not depend on whether
|
|
|
|
|
-/// the type T is a POD. The extra dummy template argument is used by ArrayRef
|
|
|
|
|
+/// the type T is a POD. The extra dummy template argument is used by span
|
|
|
|
|
/// to avoid unnecessarily requiring T to be complete.
|
|
|
|
|
template <typename T, typename = void>
|
|
|
|
|
class SmallVectorTemplateCommon
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -739,7 +738,7 @@ public:
|
2023-07-12 22:50:13 -07:00
|
|
|
|
|
|
|
|
template <typename U,
|
2026-05-26 16:25:29 -07:00
|
|
|
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
|
|
|
|
|
- void assign(ArrayRef<U> AR) {
|
|
|
|
|
+ void assign(span<const U> AR) {
|
|
|
|
|
assign(AR.begin(), AR.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1238,7 +1237,7 @@ public:
|
|
|
|
|
|
|
|
|
|
template <typename U,
|
|
|
|
|
typename = std::enable_if_t<std::is_convertible_v<U, T>>>
|
2023-07-12 22:50:13 -07:00
|
|
|
- explicit SmallVector(ArrayRef<U> A) : SmallVectorImpl<T>(N) {
|
|
|
|
|
+ explicit SmallVector(span<const U> A) : SmallVectorImpl<T>(N) {
|
|
|
|
|
this->append(A.begin(), A.end());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index e5f98249cc07464c4961ce4f86f973556e2d4dfb..dae64305f2b41766bb7bf9cf49b5d672b91f9493 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/Chrono.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/Chrono.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -91,12 +91,12 @@ LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, sys::UtcTime<> TP);
|
2022-05-20 18:59:53 -04:00
|
|
|
template <>
|
|
|
|
|
struct format_provider<sys::TimePoint<>> {
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI static void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS,
|
|
|
|
|
- StringRef Style);
|
|
|
|
|
+ std::string_view Style);
|
2022-05-20 18:59:53 -04:00
|
|
|
};
|
|
|
|
|
|
2024-03-17 18:39:03 -07:00
|
|
|
template <> struct format_provider<sys::UtcTime<std::chrono::seconds>> {
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI static void format(const sys::UtcTime<std::chrono::seconds> &TP,
|
|
|
|
|
- llvm::raw_ostream &OS, StringRef Style);
|
|
|
|
|
+ llvm::raw_ostream &OS, std::string_view Style);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
@@ -160,7 +160,7 @@ private:
|
2022-05-20 18:59:53 -04:00
|
|
|
return duration_cast<duration<InternalRep, AsPeriod>>(D).count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- static std::pair<InternalRep, StringRef> consumeUnit(StringRef &Style,
|
|
|
|
|
+ static std::pair<InternalRep, std::string_view> consumeUnit(std::string_view &Style,
|
|
|
|
|
const Dur &D) {
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
if (Style.consume_front("ns"))
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -178,7 +178,7 @@ private:
|
2022-05-20 18:59:53 -04:00
|
|
|
return {D.count(), detail::unit<Period>::value};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- static bool consumeShowUnit(StringRef &Style) {
|
|
|
|
|
+ static bool consumeShowUnit(std::string_view &Style) {
|
|
|
|
|
if (Style.empty())
|
|
|
|
|
return true;
|
|
|
|
|
if (Style.consume_front("-"))
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -190,9 +190,9 @@ private:
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
- static void format(const Dur &D, llvm::raw_ostream &Stream, StringRef Style) {
|
|
|
|
|
+ static void format(const Dur &D, llvm::raw_ostream &Stream, std::string_view Style) {
|
|
|
|
|
InternalRep count;
|
|
|
|
|
- StringRef unit;
|
|
|
|
|
+ std::string_view unit;
|
|
|
|
|
std::tie(count, unit) = consumeUnit(Style, D);
|
|
|
|
|
bool show_unit = consumeShowUnit(Style);
|
|
|
|
|
|
|
|
|
|
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index 56f498a36ae52455a336c0f77a56fd16d199706b..a160164a33903408d60d6e8a57462a3b8c8623e2 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/Compiler.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/Compiler.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -422,7 +422,7 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/// LLVM_GSL_POINTER - Apply this to non-owning classes like
|
|
|
|
|
-/// StringRef to enable lifetime warnings.
|
|
|
|
|
+/// std::string_view to enable lifetime warnings.
|
|
|
|
|
#if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
|
|
|
|
|
#define LLVM_GSL_POINTER [[gsl::Pointer]]
|
|
|
|
|
#else
|
|
|
|
|
diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index ddf7057bff59d1302ad26dd6da6c11937dd003e5..4049b742683ce5c61202e61c856f33074d2fc586 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/ConvertUTF.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/ConvertUTF.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -108,10 +108,9 @@
|
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2022-05-20 18:59:53 -04:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <string>
|
2022-08-15 05:38:15 -07:00
|
|
|
-
|
|
|
|
|
-#if defined(_WIN32)
|
2023-07-12 22:50:13 -07:00
|
|
|
+#include <span>
|
2022-05-20 18:59:53 -04:00
|
|
|
+#include <string_view>
|
|
|
|
|
#include <system_error>
|
2022-08-15 05:38:15 -07:00
|
|
|
-#endif
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
// Wrap everything in namespace llvm so that programs can link with llvm and
|
2022-08-15 05:38:15 -07:00
|
|
|
// their own version of the unicode libraries.
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -217,12 +216,10 @@ LLVM_ABI unsigned getNumBytesForUTF8(UTF8 firstByte);
|
2022-05-20 18:59:53 -04:00
|
|
|
/*************************************************************************/
|
|
|
|
|
/* Below are LLVM-specific wrappers of the functions above. */
|
|
|
|
|
|
|
|
|
|
-template <typename T> class ArrayRef;
|
|
|
|
|
template <typename T> class SmallVectorImpl;
|
|
|
|
|
-class StringRef;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
- * Convert an UTF8 StringRef to UTF8, UTF16, or UTF32 depending on
|
|
|
|
|
+ * Convert an UTF8 string_view to UTF8, UTF16, or UTF32 depending on
|
|
|
|
|
* WideCharWidth. The converted data is written to ResultPtr, which needs to
|
|
|
|
|
* point to at least WideCharWidth * (Source.Size() + 1) bytes. On success,
|
|
|
|
|
* ResultPtr will point one after the end of the copied string. On failure,
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -230,14 +227,14 @@ class StringRef;
|
2022-05-20 18:59:53 -04:00
|
|
|
* the first character which could not be converted.
|
|
|
|
|
* \return true on success.
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source,
|
|
|
|
|
+LLVM_ABI bool ConvertUTF8toWide(unsigned WideCharWidth, std::string_view Source,
|
|
|
|
|
char *&ResultPtr, const UTF8 *&ErrorPtr);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
-* Converts a UTF-8 StringRef to a std::wstring.
|
|
|
|
|
+* Converts a UTF-8 string_view to a std::wstring.
|
|
|
|
|
* \return true on success.
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result);
|
|
|
|
|
+LLVM_ABI bool ConvertUTF8toWide(std::string_view Source, std::wstring &Result);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a UTF-8 C-string to a std::wstring.
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -295,7 +292,7 @@ inline ConversionResult convertUTF8Sequence(const UTF8 **source,
|
2022-05-20 18:59:53 -04:00
|
|
|
* Returns true if a blob of text starts with a UTF-16 big or little endian byte
|
|
|
|
|
* order mark.
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool hasUTF16ByteOrderMark(ArrayRef<char> SrcBytes);
|
|
|
|
|
+LLVM_ABI bool hasUTF16ByteOrderMark(span<const char> SrcBytes);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -304,7 +301,7 @@ LLVM_ABI bool hasUTF16ByteOrderMark(ArrayRef<char> SrcBytes);
|
2022-05-20 18:59:53 -04:00
|
|
|
* \param [out] Out Converted UTF-8 is stored here on success.
|
|
|
|
|
* \returns true on success
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes,
|
|
|
|
|
+LLVM_ABI bool convertUTF16ToUTF8String(span<const char> SrcBytes,
|
|
|
|
|
std::string &Out);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/**
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -314,7 +311,7 @@ LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes,
|
2022-05-20 18:59:53 -04:00
|
|
|
* \param [out] Out Converted UTF-8 is stored here on success.
|
|
|
|
|
* \returns true on success
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out);
|
|
|
|
|
+LLVM_ABI bool convertUTF16ToUTF8String(span<const UTF16> Src, std::string &Out);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2023-07-12 22:50:13 -07:00
|
|
|
/**
|
|
|
|
|
* Converts a stream of raw bytes assumed to be UTF32 into a UTF8 std::string.
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -323,7 +320,7 @@ LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out);
|
2023-07-12 22:50:13 -07:00
|
|
|
* \param [out] Out Converted UTF-8 is stored here on success.
|
|
|
|
|
* \returns true on success
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes,
|
|
|
|
|
+LLVM_ABI bool convertUTF32ToUTF8String(span<const char> SrcBytes,
|
|
|
|
|
std::string &Out);
|
2023-07-12 22:50:13 -07:00
|
|
|
|
|
|
|
|
/**
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -333,14 +330,14 @@ LLVM_ABI bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes,
|
2023-07-12 22:50:13 -07:00
|
|
|
* \param [out] Out Converted UTF-8 is stored here on success.
|
|
|
|
|
* \returns true on success
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool convertUTF32ToUTF8String(ArrayRef<UTF32> Src, std::string &Out);
|
|
|
|
|
+LLVM_ABI bool convertUTF32ToUTF8String(span<const UTF32> Src, std::string &Out);
|
2023-07-12 22:50:13 -07:00
|
|
|
|
2022-05-20 18:59:53 -04:00
|
|
|
/**
|
|
|
|
|
* Converts a UTF-8 string into a UTF-16 string with native endianness.
|
|
|
|
|
*
|
|
|
|
|
* \returns true on success
|
|
|
|
|
*/
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI bool convertUTF8ToUTF16String(StringRef SrcUTF8,
|
|
|
|
|
+LLVM_ABI bool convertUTF8ToUTF16String(std::string_view SrcUTF8,
|
|
|
|
|
SmallVectorImpl<UTF16> &DstUTF16);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI bool IsSingleCodeUnitUTF8Codepoint(unsigned);
|
|
|
|
|
@@ -350,10 +347,10 @@ LLVM_ABI bool IsSingleCodeUnitUTF32Codepoint(unsigned);
|
2022-05-20 18:59:53 -04:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
namespace sys {
|
|
|
|
|
namespace windows {
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI std::error_code UTF8ToUTF16(StringRef utf8,
|
|
|
|
|
+LLVM_ABI std::error_code UTF8ToUTF16(std::string_view utf8,
|
|
|
|
|
SmallVectorImpl<wchar_t> &utf16);
|
2022-05-20 18:59:53 -04:00
|
|
|
/// Convert to UTF16 from the current code page used in the system
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI std::error_code CurCPToUTF16(StringRef utf8,
|
|
|
|
|
+LLVM_ABI std::error_code CurCPToUTF16(std::string_view utf8,
|
|
|
|
|
SmallVectorImpl<wchar_t> &utf16);
|
|
|
|
|
LLVM_ABI std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
|
|
|
|
|
SmallVectorImpl<char> &utf8);
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index a4fd008a9ff3fc50cbb81e4b8a90ef2284ec6474..aabdfa0ad5e0caf15a72eb95ec9f888fbe608099 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/ErrorHandling.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/ErrorHandling.h
|
2022-08-15 05:38:15 -07:00
|
|
|
@@ -15,10 +15,10 @@
|
|
|
|
|
#define LLVM_SUPPORT_ERRORHANDLING_H
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2022-08-15 05:38:15 -07:00
|
|
|
+#include <string>
|
2022-05-20 18:59:53 -04:00
|
|
|
+#include <string_view>
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
2026-05-26 16:25:29 -07:00
|
|
|
-class StringRef;
|
|
|
|
|
-class Twine;
|
|
|
|
|
|
|
|
|
|
/// An error handler callback.
|
|
|
|
|
using fatal_error_handler_t = void (*)(void *user_data, const char *reason,
|
|
|
|
|
@@ -62,9 +62,9 @@ struct ScopedFatalErrorHandler {
|
|
|
|
|
/// instead.
|
|
|
|
|
[[noreturn]] LLVM_ABI void report_fatal_error(const char *reason,
|
|
|
|
|
bool gen_crash_diag = true);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void report_fatal_error(StringRef reason,
|
|
|
|
|
+[[noreturn]] LLVM_ABI void report_fatal_error(const std::string& reason,
|
|
|
|
|
bool gen_crash_diag = true);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void report_fatal_error(const Twine &reason,
|
|
|
|
|
+[[noreturn]] LLVM_ABI void report_fatal_error(std::string_view reason,
|
|
|
|
|
bool gen_crash_diag = true);
|
|
|
|
|
|
|
|
|
|
/// Report a fatal error that likely indicates a bug in LLVM. It serves a
|
|
|
|
|
@@ -75,8 +75,8 @@ struct ScopedFatalErrorHandler {
|
|
|
|
|
/// and then abort. This will produce a crash trace and *will* ask users to
|
|
|
|
|
/// report an LLVM bug.
|
|
|
|
|
[[noreturn]] LLVM_ABI void reportFatalInternalError(const char *reason);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void reportFatalInternalError(StringRef reason);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void reportFatalInternalError(const Twine &reason);
|
|
|
|
|
+[[noreturn]] LLVM_ABI void reportFatalInternalError(const std::string& reason);
|
|
|
|
|
+[[noreturn]] LLVM_ABI void reportFatalInternalError(std::string_view reason);
|
|
|
|
|
|
|
|
|
|
/// Report a fatal error that does not indicate a bug in LLVM.
|
|
|
|
|
///
|
|
|
|
|
@@ -93,8 +93,8 @@ struct ScopedFatalErrorHandler {
|
|
|
|
|
/// and then exit with code 1. It will not produce a crash trace and will
|
|
|
|
|
/// *not* ask users to report an LLVM bug.
|
|
|
|
|
[[noreturn]] LLVM_ABI void reportFatalUsageError(const char *reason);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void reportFatalUsageError(StringRef reason);
|
|
|
|
|
-[[noreturn]] LLVM_ABI void reportFatalUsageError(const Twine &reason);
|
|
|
|
|
+[[noreturn]] LLVM_ABI void reportFatalUsageError(const std::string& reason);
|
|
|
|
|
+[[noreturn]] LLVM_ABI void reportFatalUsageError(std::string_view reason);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Installs a new bad alloc error handler that should be used whenever a
|
2026-05-26 16:25:29 -07:00
|
|
|
/// bad alloc error, e.g. failing malloc/calloc, is encountered by LLVM.
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index 867f81d74fb4d72a63a8e52ca6599cf4f463ec56..32c3ad9a9fc2c9827dc4afd81c6f9d03ec1b25c2 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/VersionTuple.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/VersionTuple.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -24,7 +24,6 @@
|
2024-03-17 18:39:03 -07:00
|
|
|
namespace llvm {
|
|
|
|
|
template <typename HasherT, llvm::endianness Endianness> class HashBuilder;
|
2022-05-20 18:59:53 -04:00
|
|
|
class raw_ostream;
|
|
|
|
|
-class StringRef;
|
|
|
|
|
|
|
|
|
|
/// Represents a version number in the form major[.minor[.subminor[.build]]].
|
|
|
|
|
class VersionTuple {
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -179,11 +178,6 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Retrieve a string representation of the version number.
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI std::string getAsString() const;
|
2022-05-20 18:59:53 -04:00
|
|
|
-
|
|
|
|
|
- /// Try to parse the given string as a version number.
|
|
|
|
|
- /// \returns \c true if the string does not match the regular expression
|
|
|
|
|
- /// [0-9]+(\.[0-9]+){0,3}
|
2026-05-26 16:25:29 -07:00
|
|
|
- LLVM_ABI bool tryParse(StringRef string);
|
2022-05-20 18:59:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Print a version number.
|
|
|
|
|
diff --git a/llvm/include/llvm/Support/Windows/WindowsSupport.h b/llvm/include/llvm/Support/Windows/WindowsSupport.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index 50a2540dba68795237fa922c2afc972f90873b5c..30644ef7f62cb81a33f2b62068f77f4e7f3f5019 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/Windows/WindowsSupport.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/Windows/WindowsSupport.h
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -33,8 +33,6 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
|
-#include "llvm/ADT/StringRef.h"
|
|
|
|
|
-#include "llvm/ADT/Twine.h"
|
|
|
|
|
#include "llvm/Config/llvm-config.h" // Get build system configuration settings
|
|
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
|
#include "llvm/Support/Chrono.h"
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -72,7 +70,7 @@ LLVM_ABI bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix);
|
2022-08-15 05:38:15 -07:00
|
|
|
[[noreturn]] inline void ReportLastErrorFatal(const char *Msg) {
|
|
|
|
|
std::string ErrMsg;
|
|
|
|
|
MakeErrMsg(&ErrMsg, Msg);
|
|
|
|
|
- llvm::report_fatal_error(Twine(ErrMsg));
|
|
|
|
|
+ llvm::report_fatal_error(ErrMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename HandleTraits>
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
|
2026-05-26 16:25:29 -07:00
|
|
|
index 70916d8e4adb0f98984ff335187a083a3091bc58..19df8739b6013c1b1a1527f5880a040d3cfb478f 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/include/llvm/Support/raw_ostream.h
|
|
|
|
|
+++ b/llvm/include/llvm/Support/raw_ostream.h
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -14,14 +14,13 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
#define LLVM_SUPPORT_RAW_OSTREAM_H
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
-#include "llvm/ADT/StringRef.h"
|
2026-05-26 16:25:29 -07:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2022-05-20 18:59:53 -04:00
|
|
|
-#include "llvm/Support/DataTypes.h"
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstddef>
|
2022-08-15 05:38:15 -07:00
|
|
|
#include <cstdint>
|
2023-07-12 22:50:13 -07:00
|
|
|
#include <cstring>
|
|
|
|
|
#include <optional>
|
|
|
|
|
+#include <span>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
#include <system_error>
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -222,7 +221,22 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- raw_ostream &operator<<(StringRef Str) {
|
|
|
|
|
+ raw_ostream &operator<<(span<const uint8_t> Arr) {
|
|
|
|
|
+ // Inline fast path, particularly for arrays with a known length.
|
|
|
|
|
+ size_t Size = Arr.size();
|
|
|
|
|
+
|
|
|
|
|
+ // Make sure we can use the fast path.
|
|
|
|
|
+ if (Size > (size_t)(OutBufEnd - OutBufCur))
|
|
|
|
|
+ return write(Arr.data(), Size);
|
|
|
|
|
+
|
|
|
|
|
+ if (Size) {
|
|
|
|
|
+ memcpy(OutBufCur, Arr.data(), Size);
|
|
|
|
|
+ OutBufCur += Size;
|
|
|
|
|
+ }
|
|
|
|
|
+ return *this;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ raw_ostream &operator<<(std::string_view Str) {
|
|
|
|
|
// Inline fast path, particularly for strings with a known length.
|
|
|
|
|
size_t Size = Str.size();
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -255,7 +269,7 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
// Inline fast path, particularly for constant strings where a sufficiently
|
|
|
|
|
// smart compiler will simplify strlen.
|
|
|
|
|
|
|
|
|
|
- return this->operator<<(StringRef(Str));
|
|
|
|
|
+ return this->operator<<(std::string_view(Str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
raw_ostream &operator<<(const std::string &Str) {
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -263,10 +277,6 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
return write(Str.data(), Str.length());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- raw_ostream &operator<<(const std::string_view &Str) {
|
|
|
|
|
- return write(Str.data(), Str.length());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
raw_ostream &operator<<(const SmallVectorImpl<char> &Str) {
|
|
|
|
|
return write(Str.data(), Str.size());
|
|
|
|
|
}
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -299,7 +309,7 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
/// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't
|
|
|
|
|
/// satisfy llvm::isPrint into an escape sequence.
|
|
|
|
|
- raw_ostream &write_escaped(StringRef Str, bool UseHexEscapes = false);
|
|
|
|
|
+ raw_ostream &write_escaped(std::string_view Str, bool UseHexEscapes = false);
|
|
|
|
|
|
|
|
|
|
raw_ostream &write(unsigned char C);
|
|
|
|
|
raw_ostream &write(const char *Ptr, size_t Size);
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -512,14 +522,14 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// 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.
|
|
|
|
|
- raw_fd_ostream(StringRef Filename, std::error_code &EC);
|
|
|
|
|
- raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+ raw_fd_ostream(std::string_view Filename, std::error_code &EC);
|
|
|
|
|
+ raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::CreationDisposition Disp);
|
|
|
|
|
- raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+ raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::FileAccess Access);
|
|
|
|
|
- raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+ raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::OpenFlags Flags);
|
|
|
|
|
- raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+ raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access,
|
|
|
|
|
sys::fs::OpenFlags Flags);
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -631,7 +641,7 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
/// 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.
|
2026-05-26 16:25:29 -07:00
|
|
|
- LLVM_ABI raw_fd_stream(StringRef Filename, std::error_code &EC);
|
|
|
|
|
+ LLVM_ABI raw_fd_stream(std::string_view Filename, std::error_code &EC);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI raw_fd_stream(int fd, bool shouldClose);
|
2024-03-17 18:39:03 -07:00
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -717,8 +727,8 @@ public:
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
void flush() = delete;
|
|
|
|
|
|
|
|
|
|
- /// Return a StringRef for the vector contents.
|
|
|
|
|
- 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()); }
|
2024-12-24 17:40:31 -08:00
|
|
|
SmallVectorImpl<char> &buffer() { return OS; }
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
void reserveExtraSpace(uint64_t ExtraSize) override {
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -836,7 +846,7 @@ class Error;
|
2022-05-20 18:59:53 -04:00
|
|
|
/// 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.
|
2026-05-26 16:25:29 -07:00
|
|
|
-LLVM_ABI Error writeToOutput(StringRef OutputFileName,
|
|
|
|
|
+LLVM_ABI Error writeToOutput(std::string_view OutputFileName,
|
|
|
|
|
std::function<Error(raw_ostream &)> Write);
|
2022-05-20 18:59:53 -04:00
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t);
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index 76ead00c977bd37147048d321b425a9a9e76497a..39f151c716dacfef07038551add0f84a09b0cb62 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/lib/Support/ConvertUTFWrapper.cpp
|
|
|
|
|
+++ b/llvm/lib/Support/ConvertUTFWrapper.cpp
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -6,23 +6,24 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
-#include "llvm/ADT/ArrayRef.h"
|
|
|
|
|
-#include "llvm/ADT/StringRef.h"
|
|
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2025-06-25 01:36:22 -04:00
|
|
|
+#include "llvm/Support/SwapByteOrder.h"
|
2023-07-12 22:50:13 -07:00
|
|
|
+#include <span>
|
2022-05-20 18:59:53 -04:00
|
|
|
#include <string>
|
|
|
|
|
+#include <string_view>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
|
|
-bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source,
|
|
|
|
|
+bool ConvertUTF8toWide(unsigned WideCharWidth, std::string_view Source,
|
|
|
|
|
char *&ResultPtr, const UTF8 *&ErrorPtr) {
|
|
|
|
|
assert(WideCharWidth == 1 || WideCharWidth == 2 || WideCharWidth == 4);
|
|
|
|
|
ConversionResult result = conversionOK;
|
|
|
|
|
// Copy the character span over.
|
|
|
|
|
if (WideCharWidth == 1) {
|
|
|
|
|
- const UTF8 *Pos = reinterpret_cast<const UTF8*>(Source.begin());
|
|
|
|
|
- if (!isLegalUTF8String(&Pos, reinterpret_cast<const UTF8*>(Source.end()))) {
|
|
|
|
|
+ const UTF8 *Pos = reinterpret_cast<const UTF8*>(Source.data());
|
|
|
|
|
+ if (!isLegalUTF8String(&Pos, reinterpret_cast<const UTF8*>(Source.data() + Source.size()))) {
|
|
|
|
|
result = sourceIllegal;
|
|
|
|
|
ErrorPtr = Pos;
|
|
|
|
|
} else {
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -75,12 +76,12 @@ bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr) {
|
2022-05-20 18:59:53 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool hasUTF16ByteOrderMark(ArrayRef<char> S) {
|
|
|
|
|
+bool hasUTF16ByteOrderMark(span<const char> S) {
|
2023-07-12 22:50:13 -07:00
|
|
|
return (S.size() >= 2 && ((S[0] == '\xff' && S[1] == '\xfe') ||
|
|
|
|
|
(S[0] == '\xfe' && S[1] == '\xff')));
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
|
|
|
|
|
+bool convertUTF16ToUTF8String(span<const char> SrcBytes, std::string &Out) {
|
|
|
|
|
assert(Out.empty());
|
|
|
|
|
|
|
|
|
|
// Error out on an uneven byte count.
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -131,14 +132,14 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
|
2022-05-20 18:59:53 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 22:50:13 -07:00
|
|
|
-bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out) {
|
|
|
|
|
+bool convertUTF16ToUTF8String(span<const UTF16> Src, std::string &Out) {
|
2022-05-20 18:59:53 -04:00
|
|
|
return convertUTF16ToUTF8String(
|
|
|
|
|
- llvm::ArrayRef<char>(reinterpret_cast<const char *>(Src.data()),
|
|
|
|
|
+ span<const char>(reinterpret_cast<const char *>(Src.data()),
|
2023-07-12 22:50:13 -07:00
|
|
|
Src.size() * sizeof(UTF16)),
|
|
|
|
|
Out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
|
|
|
|
|
+bool convertUTF32ToUTF8String(span<const char> SrcBytes, std::string &Out) {
|
|
|
|
|
assert(Out.empty());
|
|
|
|
|
|
|
|
|
|
// Error out on an uneven byte count.
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -189,14 +190,14 @@ bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) {
|
2023-07-12 22:50:13 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool convertUTF32ToUTF8String(ArrayRef<UTF32> Src, std::string &Out) {
|
|
|
|
|
+bool convertUTF32ToUTF8String(span<const UTF32> Src, std::string &Out) {
|
|
|
|
|
return convertUTF32ToUTF8String(
|
|
|
|
|
- llvm::ArrayRef<char>(reinterpret_cast<const char *>(Src.data()),
|
|
|
|
|
+ span<const char>(reinterpret_cast<const char *>(Src.data()),
|
|
|
|
|
Src.size() * sizeof(UTF32)),
|
|
|
|
|
Out);
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool convertUTF8ToUTF16String(StringRef SrcUTF8,
|
|
|
|
|
+bool convertUTF8ToUTF16String(std::string_view SrcUTF8,
|
|
|
|
|
SmallVectorImpl<UTF16> &DstUTF16) {
|
|
|
|
|
assert(DstUTF16.empty());
|
|
|
|
|
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -207,8 +208,8 @@ bool convertUTF8ToUTF16String(StringRef SrcUTF8,
|
2022-05-20 18:59:53 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- const UTF8 *Src = reinterpret_cast<const UTF8 *>(SrcUTF8.begin());
|
|
|
|
|
- const UTF8 *SrcEnd = reinterpret_cast<const UTF8 *>(SrcUTF8.end());
|
|
|
|
|
+ const UTF8 *Src = reinterpret_cast<const UTF8 *>(SrcUTF8.data());
|
|
|
|
|
+ const UTF8 *SrcEnd = reinterpret_cast<const UTF8 *>(SrcUTF8.data() + SrcUTF8.size());
|
|
|
|
|
|
|
|
|
|
// Allocate the same number of UTF-16 code units as UTF-8 code units. Encoding
|
|
|
|
|
// as UTF-16 should always require the same amount or less code units than the
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -239,7 +240,7 @@ static_assert(sizeof(wchar_t) == 1 || sizeof(wchar_t) == 2 ||
|
2022-05-20 18:59:53 -04:00
|
|
|
"Expected wchar_t to be 1, 2, or 4 bytes");
|
|
|
|
|
|
|
|
|
|
template <typename TResult>
|
|
|
|
|
-static inline bool ConvertUTF8toWideInternal(llvm::StringRef Source,
|
|
|
|
|
+static inline bool ConvertUTF8toWideInternal(std::string_view Source,
|
|
|
|
|
TResult &Result) {
|
|
|
|
|
// Even in the case of UTF-16, the number of bytes in a UTF-8 string is
|
|
|
|
|
// at least as large as the number of elements in the resulting wide
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -255,7 +256,7 @@ static inline bool ConvertUTF8toWideInternal(llvm::StringRef Source,
|
2022-05-20 18:59:53 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result) {
|
|
|
|
|
+bool ConvertUTF8toWide(std::string_view Source, std::wstring &Result) {
|
|
|
|
|
return ConvertUTF8toWideInternal(Source, Result);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -264,7 +265,7 @@ bool ConvertUTF8toWide(const char *Source, std::wstring &Result) {
|
2022-05-20 18:59:53 -04:00
|
|
|
Result.clear();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
- return ConvertUTF8toWide(llvm::StringRef(Source), Result);
|
|
|
|
|
+ return ConvertUTF8toWide(std::string_view(Source), Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool convertWideToUTF8(const std::wstring &Source, std::string &Result) {
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -279,7 +280,7 @@ bool convertWideToUTF8(const std::wstring &Source, std::string &Result) {
|
2022-05-20 18:59:53 -04:00
|
|
|
return true;
|
|
|
|
|
} else if (sizeof(wchar_t) == 2) {
|
|
|
|
|
return convertUTF16ToUTF8String(
|
|
|
|
|
- llvm::ArrayRef<UTF16>(reinterpret_cast<const UTF16 *>(Source.data()),
|
|
|
|
|
+ span<const UTF16>(reinterpret_cast<const UTF16 *>(Source.data()),
|
|
|
|
|
Source.size()),
|
|
|
|
|
Result);
|
|
|
|
|
} else if (sizeof(wchar_t) == 4) {
|
|
|
|
|
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index 097041f1ae282a0387da8f839e5e37fe350d5d51..fc9d118e85508cdf86553bb63cce4a1c567045b7 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/lib/Support/ErrorHandling.cpp
|
|
|
|
|
+++ b/llvm/lib/Support/ErrorHandling.cpp
|
|
|
|
|
@@ -14,7 +14,6 @@
|
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
|
#include "llvm-c/ErrorHandling.h"
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
-#include "llvm/ADT/Twine.h"
|
|
|
|
|
#include "llvm/Config/config.h"
|
2025-06-25 01:36:22 -04:00
|
|
|
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
|
2022-05-20 18:59:53 -04:00
|
|
|
#include "llvm/Support/Debug.h"
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -93,14 +92,14 @@ void llvm::remove_fatal_error_handler() {
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void llvm::report_fatal_error(const char *Reason, bool GenCrashDiag) {
|
|
|
|
|
- report_fatal_error(Twine(Reason), GenCrashDiag);
|
|
|
|
|
+ report_fatal_error(std::string_view(Reason), GenCrashDiag);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 05:38:15 -07:00
|
|
|
-void llvm::report_fatal_error(StringRef Reason, bool GenCrashDiag) {
|
2022-05-20 18:59:53 -04:00
|
|
|
- report_fatal_error(Twine(Reason), GenCrashDiag);
|
2022-08-15 05:38:15 -07:00
|
|
|
+void llvm::report_fatal_error(const std::string &Reason, bool GenCrashDiag) {
|
2022-05-20 18:59:53 -04:00
|
|
|
+ report_fatal_error(std::string_view(Reason), GenCrashDiag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
|
|
|
|
+void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
|
|
|
|
|
llvm::fatal_error_handler_t handler = nullptr;
|
|
|
|
|
void* handlerData = nullptr;
|
|
|
|
|
{
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -114,7 +113,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handler) {
|
2022-08-15 05:38:15 -07:00
|
|
|
- handler(handlerData, Reason.str().c_str(), GenCrashDiag);
|
|
|
|
|
+ handler(handlerData, std::string{Reason}.c_str(), GenCrashDiag);
|
2022-05-20 18:59:53 -04:00
|
|
|
} else {
|
|
|
|
|
// Blast the result out to stderr. We don't try hard to make sure this
|
|
|
|
|
// succeeds (e.g. handling EINTR) and we can't use errs() here because
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -122,7 +121,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
2022-05-20 18:59:53 -04:00
|
|
|
SmallVector<char, 64> Buffer;
|
|
|
|
|
raw_svector_ostream OS(Buffer);
|
|
|
|
|
OS << "LLVM ERROR: " << Reason << "\n";
|
|
|
|
|
- StringRef MessageStr = OS.str();
|
|
|
|
|
+ std::string_view MessageStr = OS.str();
|
2026-05-26 16:25:29 -07:00
|
|
|
write_retry(2, MessageStr.data(), MessageStr.size());
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
2026-05-26 16:25:29 -07:00
|
|
|
|
|
|
|
|
@@ -140,19 +139,19 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
|
|
|
|
|
void llvm::reportFatalInternalError(const char *reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/true);
|
|
|
|
|
}
|
|
|
|
|
-void llvm::reportFatalInternalError(StringRef reason) {
|
|
|
|
|
+void llvm::reportFatalInternalError(const std::string& reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/true);
|
|
|
|
|
}
|
|
|
|
|
-void llvm::reportFatalInternalError(const Twine &reason) {
|
|
|
|
|
+void llvm::reportFatalInternalError(std::string_view reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/true);
|
|
|
|
|
}
|
|
|
|
|
void llvm::reportFatalUsageError(const char *reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/false);
|
|
|
|
|
}
|
|
|
|
|
-void llvm::reportFatalUsageError(StringRef reason) {
|
|
|
|
|
+void llvm::reportFatalUsageError(const std::string& reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/false);
|
|
|
|
|
}
|
|
|
|
|
-void llvm::reportFatalUsageError(const Twine &reason) {
|
|
|
|
|
+void llvm::reportFatalUsageError(std::string_view reason) {
|
|
|
|
|
report_fatal_error(reason, /*GenCrashDiag=*/false);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 05:38:15 -07:00
|
|
|
diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
|
2025-06-25 01:36:22 -04:00
|
|
|
index dceea4fbc630e85a869458af8b35ee1066c5866d..fba8fcb7cf56f4914e6ab6ede78eb8d8c8bf3424 100644
|
2022-08-15 05:38:15 -07:00
|
|
|
--- a/llvm/lib/Support/SmallVector.cpp
|
|
|
|
|
+++ b/llvm/lib/Support/SmallVector.cpp
|
|
|
|
|
@@ -11,7 +11,6 @@
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
-#include "llvm/ADT/Twine.h"
|
|
|
|
|
#include "llvm/Support/MemAlloc.h"
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#ifdef LLVM_ENABLE_EXCEPTIONS
|
|
|
|
|
@@ -67,7 +66,7 @@ static void report_size_overflow(size_t MinSize, size_t MaxSize) {
|
|
|
|
|
#ifdef LLVM_ENABLE_EXCEPTIONS
|
|
|
|
|
throw std::length_error(Reason);
|
|
|
|
|
#else
|
|
|
|
|
- report_fatal_error(Twine(Reason));
|
|
|
|
|
+ report_fatal_error(Reason);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -81,7 +80,7 @@ static void report_at_maximum_capacity(size_t MaxSize) {
|
|
|
|
|
#ifdef LLVM_ENABLE_EXCEPTIONS
|
|
|
|
|
throw std::length_error(Reason);
|
|
|
|
|
#else
|
|
|
|
|
- report_fatal_error(Twine(Reason));
|
|
|
|
|
+ report_fatal_error(Reason);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
diff --git a/llvm/lib/Support/VersionTuple.cpp b/llvm/lib/Support/VersionTuple.cpp
|
|
|
|
|
index c6e20f1bd3ef4df881e9f7b02c04af88c8342d66..9526f17bba696cc4ad00d04f7cd0a3b1d7b56981 100644
|
|
|
|
|
--- a/llvm/lib/Support/VersionTuple.cpp
|
|
|
|
|
+++ b/llvm/lib/Support/VersionTuple.cpp
|
|
|
|
|
@@ -60,55 +60,6 @@ static bool parseInt(StringRef &input, unsigned &value) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-bool VersionTuple::tryParse(StringRef input) {
|
|
|
|
|
- unsigned major = 0, minor = 0, micro = 0, build = 0;
|
|
|
|
|
-
|
|
|
|
|
- // Parse the major version, [0-9]+
|
|
|
|
|
- if (parseInt(input, major))
|
|
|
|
|
- return true;
|
|
|
|
|
-
|
|
|
|
|
- if (input.empty()) {
|
|
|
|
|
- *this = VersionTuple(major);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If we're not done, parse the minor version, \.[0-9]+
|
|
|
|
|
- if (input[0] != '.')
|
|
|
|
|
- return true;
|
|
|
|
|
- input = input.substr(1);
|
|
|
|
|
- if (parseInt(input, minor))
|
|
|
|
|
- return true;
|
|
|
|
|
-
|
|
|
|
|
- if (input.empty()) {
|
|
|
|
|
- *this = VersionTuple(major, minor);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If we're not done, parse the micro version, \.[0-9]+
|
|
|
|
|
- if (!input.consume_front("."))
|
|
|
|
|
- return true;
|
|
|
|
|
- if (parseInt(input, micro))
|
|
|
|
|
- return true;
|
|
|
|
|
-
|
|
|
|
|
- if (input.empty()) {
|
|
|
|
|
- *this = VersionTuple(major, minor, micro);
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If we're not done, parse the micro version, \.[0-9]+
|
|
|
|
|
- if (!input.consume_front("."))
|
|
|
|
|
- return true;
|
|
|
|
|
- if (parseInt(input, build))
|
|
|
|
|
- return true;
|
|
|
|
|
-
|
|
|
|
|
- // If we have characters left over, it's an error.
|
|
|
|
|
- if (!input.empty())
|
|
|
|
|
- return true;
|
|
|
|
|
-
|
|
|
|
|
- *this = VersionTuple(major, minor, micro, build);
|
|
|
|
|
- return false;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
VersionTuple VersionTuple::withMajorReplaced(unsigned NewMajor) const {
|
|
|
|
|
if (HasBuild)
|
|
|
|
|
return VersionTuple(NewMajor, Minor, Subminor, Build);
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index fe07aed335f7e49fd59488cdd4876e23e5b898b8..bf5d06018979474cf6166fed61be93eede0dece1 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/lib/Support/raw_ostream.cpp
|
|
|
|
|
+++ b/llvm/lib/Support/raw_ostream.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -155,7 +155,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) {
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-raw_ostream &raw_ostream::write_escaped(StringRef Str,
|
|
|
|
|
+raw_ostream &raw_ostream::write_escaped(std::string_view Str,
|
|
|
|
|
bool UseHexEscapes) {
|
|
|
|
|
for (unsigned char c : Str) {
|
|
|
|
|
switch (c) {
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -552,7 +552,7 @@ void format_object_base::home() {
|
2022-05-20 18:59:53 -04:00
|
|
|
// raw_fd_ostream
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
-static int getFD(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+static int getFD(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access,
|
|
|
|
|
sys::fs::OpenFlags Flags) {
|
2026-05-26 16:25:29 -07:00
|
|
|
// FIXME(sandboxing): Remove this by adopting `llvm::vfs::OutputBackend`.
|
|
|
|
|
@@ -581,25 +581,25 @@ static int getFD(StringRef Filename, std::error_code &EC,
|
2022-05-20 18:59:53 -04:00
|
|
|
return FD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC)
|
|
|
|
|
+raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC)
|
|
|
|
|
: raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write,
|
|
|
|
|
sys::fs::OF_None) {}
|
|
|
|
|
|
|
|
|
|
-raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::CreationDisposition Disp)
|
|
|
|
|
: raw_fd_ostream(Filename, EC, Disp, sys::fs::FA_Write, sys::fs::OF_None) {}
|
|
|
|
|
|
|
|
|
|
-raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::FileAccess Access)
|
|
|
|
|
: raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, Access,
|
|
|
|
|
sys::fs::OF_None) {}
|
|
|
|
|
|
|
|
|
|
-raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::OpenFlags Flags)
|
|
|
|
|
: raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write,
|
|
|
|
|
Flags) {}
|
|
|
|
|
|
|
|
|
|
-raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
|
|
|
|
|
+raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC,
|
|
|
|
|
sys::fs::CreationDisposition Disp,
|
|
|
|
|
sys::fs::FileAccess Access,
|
|
|
|
|
sys::fs::OpenFlags Flags)
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -674,8 +674,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
2022-08-15 05:38:15 -07:00
|
|
|
// has_error() and clear the error flag with clear_error() before
|
|
|
|
|
// destructing raw_ostream objects which may have errors.
|
|
|
|
|
if (has_error())
|
2026-05-26 16:25:29 -07:00
|
|
|
- reportFatalUsageError(Twine("IO failure on output stream: ") +
|
|
|
|
|
- error().message());
|
|
|
|
|
+ reportFatalUsageError("IO failure on output stream: " + error().message());
|
2022-08-15 05:38:15 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
@@ -693,7 +692,7 @@ raw_fd_ostream::~raw_fd_ostream() {
|
2022-05-20 18:59:53 -04:00
|
|
|
// 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.
|
|
|
|
|
-static bool write_console_impl(int FD, StringRef Data) {
|
|
|
|
|
+static bool write_console_impl(int FD, std::string_view Data) {
|
|
|
|
|
SmallVector<wchar_t, 256> WideText;
|
|
|
|
|
|
|
|
|
|
// Fall back to ::write if it wasn't valid UTF-8.
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -739,7 +738,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) {
|
2022-05-20 18:59:53 -04:00
|
|
|
// 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)
|
|
|
|
|
- if (write_console_impl(FD, StringRef(Ptr, Size)))
|
|
|
|
|
+ if (write_console_impl(FD, std::string_view(Ptr, Size)))
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -922,7 +921,7 @@ raw_ostream &llvm::nulls() {
|
2022-05-20 18:59:53 -04:00
|
|
|
// File Streams
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
-raw_fd_stream::raw_fd_stream(StringRef Filename, std::error_code &EC)
|
|
|
|
|
+raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC)
|
|
|
|
|
: raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways,
|
|
|
|
|
sys::fs::FA_Write | sys::fs::FA_Read,
|
|
|
|
|
sys::fs::OF_None),
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -1007,7 +1006,7 @@ void buffer_ostream::anchor() {}
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
void buffer_unique_ostream::anchor() {}
|
|
|
|
|
|
|
|
|
|
-Error llvm::writeToOutput(StringRef OutputFileName,
|
|
|
|
|
+Error llvm::writeToOutput(std::string_view OutputFileName,
|
|
|
|
|
std::function<Error(raw_ostream &)> Write) {
|
|
|
|
|
if (OutputFileName == "-")
|
|
|
|
|
return Write(outs());
|
|
|
|
|
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index 553d159d33b1a55178a5e67e3669db48474cc40d..fffa07e1978bb3b8c2013073bdd58556d145ff23 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/unittests/ADT/DenseMapTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/ADT/DenseMapTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -12,12 +12,12 @@
|
2023-09-21 19:54:33 -07:00
|
|
|
#include "llvm/ADT/DenseMapInfoVariant.h"
|
2026-05-26 16:25:29 -07:00
|
|
|
#include "llvm/ADT/STLForwardCompat.h"
|
|
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2023-09-21 19:54:33 -07:00
|
|
|
-#include "llvm/ADT/StringRef.h"
|
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <map>
|
2026-05-26 16:25:29 -07:00
|
|
|
#include <optional>
|
2023-09-21 19:54:33 -07:00
|
|
|
#include <set>
|
|
|
|
|
+#include <string_view>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <variant>
|
|
|
|
|
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -677,31 +677,6 @@ TEST(DenseMapCustomTest, EmplaceOrAssign) {
|
2024-12-24 17:40:31 -08:00
|
|
|
EXPECT_EQ(1, CountCopyAndMove::MoveAssignments);
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-// Make sure DenseMap works with StringRef keys.
|
|
|
|
|
-TEST(DenseMapCustomTest, StringRefTest) {
|
|
|
|
|
- DenseMap<StringRef, int> M;
|
|
|
|
|
-
|
|
|
|
|
- M["a"] = 1;
|
|
|
|
|
- M["b"] = 2;
|
|
|
|
|
- M["c"] = 3;
|
|
|
|
|
-
|
|
|
|
|
- EXPECT_EQ(3u, M.size());
|
|
|
|
|
- EXPECT_EQ(1, M.lookup("a"));
|
|
|
|
|
- EXPECT_EQ(2, M.lookup("b"));
|
|
|
|
|
- EXPECT_EQ(3, M.lookup("c"));
|
|
|
|
|
-
|
|
|
|
|
- EXPECT_EQ(0, M.lookup("q"));
|
|
|
|
|
-
|
|
|
|
|
- // Test the empty string, spelled various ways.
|
|
|
|
|
- EXPECT_EQ(0, M.lookup(""));
|
|
|
|
|
- EXPECT_EQ(0, M.lookup(StringRef()));
|
|
|
|
|
- EXPECT_EQ(0, M.lookup(StringRef("a", 0)));
|
|
|
|
|
- M[""] = 42;
|
|
|
|
|
- EXPECT_EQ(42, M.lookup(""));
|
|
|
|
|
- EXPECT_EQ(42, M.lookup(StringRef()));
|
|
|
|
|
- EXPECT_EQ(42, M.lookup(StringRef("a", 0)));
|
|
|
|
|
-}
|
|
|
|
|
-
|
2026-05-26 16:25:29 -07:00
|
|
|
struct NonDefaultConstructible {
|
|
|
|
|
unsigned V;
|
|
|
|
|
NonDefaultConstructible(unsigned V) : V(V) {};
|
|
|
|
|
@@ -771,8 +746,8 @@ TEST(DenseMapCustomTest, FindAsTest) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(DenseMapCustomTest, SmallDenseMapFromRange) {
|
|
|
|
|
- std::pair<int, StringRef> PlainArray[] = {{0, "0"}, {1, "1"}, {2, "2"}};
|
|
|
|
|
- SmallDenseMap<int, StringRef> M(llvm::from_range, PlainArray);
|
|
|
|
|
+ std::pair<int, std::string_view> PlainArray[] = {{0, "0"}, {1, "1"}, {2, "2"}};
|
|
|
|
|
+ SmallDenseMap<int, std::string_view> M(llvm::from_range, PlainArray);
|
|
|
|
|
EXPECT_EQ(3u, M.size());
|
|
|
|
|
using testing::Pair;
|
|
|
|
|
EXPECT_THAT(M, testing::UnorderedElementsAre(Pair(0, "0"), Pair(1, "1"),
|
|
|
|
|
@@ -975,7 +950,7 @@ TEST(DenseMapCustomTest, VariantSupport) {
|
2023-09-21 19:54:33 -07:00
|
|
|
// 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) {
|
|
|
|
|
- DenseMap<int, StringRef> Map = {{1, "one"}, {2, "two"}};
|
|
|
|
|
+ DenseMap<int, std::string_view> Map = {{1, "one"}, {2, "two"}};
|
|
|
|
|
EXPECT_EQ(R"({ (1, "one"), (2, "two") })", ::testing::PrintToString(Map));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/unittests/ADT/FunctionExtrasTest.cpp b/llvm/unittests/ADT/FunctionExtrasTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index fdabdca269da2e2be6a7a0e11b0f7f82afca0b5a..e92f5fcdfce0175eea843e81ef89604e0c2297f6 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/unittests/ADT/FunctionExtrasTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/ADT/FunctionExtrasTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -249,23 +249,23 @@ TEST(UniqueFunctionTest, Const) {
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
// Overloaded call operator correctly resolved.
|
|
|
|
|
struct ChooseCorrectOverload {
|
|
|
|
|
- StringRef operator()() { return "non-const"; }
|
|
|
|
|
- StringRef operator()() const { return "const"; }
|
|
|
|
|
+ std::string_view operator()() { return "non-const"; }
|
|
|
|
|
+ std::string_view operator()() const { return "const"; }
|
|
|
|
|
};
|
|
|
|
|
- unique_function<StringRef()> ChooseMutable = ChooseCorrectOverload();
|
|
|
|
|
+ unique_function<std::string_view()> ChooseMutable = ChooseCorrectOverload();
|
|
|
|
|
ChooseCorrectOverload A;
|
|
|
|
|
EXPECT_EQ("non-const", ChooseMutable());
|
|
|
|
|
EXPECT_EQ("non-const", A());
|
|
|
|
|
- unique_function<StringRef() const> ChooseConst = ChooseCorrectOverload();
|
|
|
|
|
+ unique_function<std::string_view() const> ChooseConst = ChooseCorrectOverload();
|
|
|
|
|
const ChooseCorrectOverload &X = A;
|
|
|
|
|
EXPECT_EQ("const", ChooseConst());
|
|
|
|
|
EXPECT_EQ("const", X());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that overloads on unique_functions are resolved as expected.
|
|
|
|
|
-std::string returns(StringRef) { return "not a function"; }
|
|
|
|
|
+std::string returns(std::string_view) { return "not a function"; }
|
|
|
|
|
std::string returns(unique_function<double()> F) { return "number"; }
|
|
|
|
|
-std::string returns(unique_function<StringRef()> F) { return "string"; }
|
|
|
|
|
+std::string returns(unique_function<std::string_view()> F) { return "string"; }
|
|
|
|
|
|
|
|
|
|
TEST(UniqueFunctionTest, SFINAE) {
|
|
|
|
|
EXPECT_EQ("not a function", returns("boo!"));
|
2022-08-15 05:38:15 -07:00
|
|
|
diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index fe7a8279d06b10ccc5a2028ddf9e1708eb76dd9b..a25c07c08bbbba7b9edaa36adc5f9eaec14ea98d 100644
|
2022-08-15 05:38:15 -07:00
|
|
|
--- a/llvm/unittests/ADT/SmallPtrSetTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp
|
|
|
|
|
@@ -12,7 +12,6 @@
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
|
#include "llvm/ADT/PointerIntPair.h"
|
|
|
|
|
-#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
#include "llvm/Support/PointerLikeTypeTraits.h"
|
2025-06-25 01:36:22 -04:00
|
|
|
#include "gmock/gmock.h"
|
2022-08-15 05:38:15 -07:00
|
|
|
#include "gtest/gtest.h"
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index db858246c9bbf7d298dff21d73c0dbd96e9b5f7e..20b0585e00e87b91c1486f045646a872cc99d208 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/unittests/ADT/SmallStringTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/ADT/SmallStringTest.cpp
|
|
|
|
|
@@ -50,43 +50,43 @@ TEST_F(SmallStringTest, AssignRepeated) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SmallStringTest, AssignIterPair) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.assign(abc.begin(), abc.end());
|
|
|
|
|
EXPECT_EQ(3u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abc", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(SmallStringTest, AssignStringRef) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+TEST_F(SmallStringTest, AssignStringView) {
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.assign(abc);
|
|
|
|
|
EXPECT_EQ(3u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abc", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SmallStringTest, AssignSmallVector) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
SmallVector<char, 10> abcVec(abc.begin(), abc.end());
|
|
|
|
|
theString.assign(abcVec);
|
|
|
|
|
EXPECT_EQ(3u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abc", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(SmallStringTest, AssignStringRefs) {
|
|
|
|
|
+TEST_F(SmallStringTest, AssignStringViews) {
|
|
|
|
|
theString.assign({"abc", "def", "ghi"});
|
|
|
|
|
EXPECT_EQ(9u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abcdefghi", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SmallStringTest, AppendIterPair) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.append(abc.begin(), abc.end());
|
|
|
|
|
theString.append(abc.begin(), abc.end());
|
|
|
|
|
EXPECT_EQ(6u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abcabc", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(SmallStringTest, AppendStringRef) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+TEST_F(SmallStringTest, AppendStringView) {
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.append(abc);
|
|
|
|
|
theString.append(abc);
|
|
|
|
|
EXPECT_EQ(6u, theString.size());
|
|
|
|
|
@@ -94,7 +94,7 @@ TEST_F(SmallStringTest, AppendStringRef) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SmallStringTest, AppendSmallVector) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
SmallVector<char, 10> abcVec(abc.begin(), abc.end());
|
|
|
|
|
theString.append(abcVec);
|
|
|
|
|
theString.append(abcVec);
|
|
|
|
|
@@ -102,11 +102,11 @@ TEST_F(SmallStringTest, AppendSmallVector) {
|
|
|
|
|
EXPECT_STREQ("abcabc", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(SmallStringTest, AppendStringRefs) {
|
|
|
|
|
+TEST_F(SmallStringTest, AppendStringViews) {
|
|
|
|
|
theString.append({"abc", "def", "ghi"});
|
|
|
|
|
EXPECT_EQ(9u, theString.size());
|
|
|
|
|
EXPECT_STREQ("abcdefghi", theString.c_str());
|
|
|
|
|
- StringRef Jkl = "jkl";
|
|
|
|
|
+ std::string_view Jkl = "jkl";
|
|
|
|
|
std::string Mno = "mno";
|
|
|
|
|
SmallString<4> Pqr("pqr");
|
|
|
|
|
const char *Stu = "stu";
|
|
|
|
|
@@ -115,15 +115,15 @@ TEST_F(SmallStringTest, AppendStringRefs) {
|
|
|
|
|
EXPECT_STREQ("abcdefghijklmnopqrstu", theString.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST_F(SmallStringTest, StringRefConversion) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+TEST_F(SmallStringTest, StringViewConversion) {
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.assign(abc.begin(), abc.end());
|
|
|
|
|
- StringRef theStringRef = theString;
|
|
|
|
|
- EXPECT_EQ("abc", theStringRef);
|
|
|
|
|
+ std::string_view theStringView = theString;
|
|
|
|
|
+ EXPECT_EQ("abc", theStringView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SmallStringTest, StdStringConversion) {
|
|
|
|
|
- StringRef abc = "abc";
|
|
|
|
|
+ std::string_view abc = "abc";
|
|
|
|
|
theString.assign(abc.begin(), abc.end());
|
|
|
|
|
std::string theStdString = std::string(theString);
|
|
|
|
|
EXPECT_EQ("abc", theStdString);
|
|
|
|
|
@@ -149,29 +149,29 @@ TEST_F(SmallStringTest, Slice) {
|
|
|
|
|
TEST_F(SmallStringTest, Find) {
|
|
|
|
|
theString = "hello";
|
|
|
|
|
EXPECT_EQ(2U, theString.find('l'));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find('z'));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find("helloworld"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find('z'));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find("helloworld"));
|
|
|
|
|
EXPECT_EQ(0U, theString.find("hello"));
|
|
|
|
|
EXPECT_EQ(1U, theString.find("ello"));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find("zz"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find("zz"));
|
|
|
|
|
EXPECT_EQ(2U, theString.find("ll", 2));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find("ll", 3));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find("ll", 3));
|
|
|
|
|
EXPECT_EQ(0U, theString.find(""));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(3U, theString.rfind('l'));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.rfind('z'));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.rfind("helloworld"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.rfind('z'));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.rfind("helloworld"));
|
|
|
|
|
EXPECT_EQ(0U, theString.rfind("hello"));
|
|
|
|
|
EXPECT_EQ(1U, theString.rfind("ello"));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.rfind("zz"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.rfind("zz"));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(2U, theString.find_first_of('l'));
|
|
|
|
|
EXPECT_EQ(1U, theString.find_first_of("el"));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find_first_of("xyz"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find_first_of("xyz"));
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(1U, theString.find_first_not_of('h'));
|
|
|
|
|
EXPECT_EQ(4U, theString.find_first_not_of("hel"));
|
|
|
|
|
- EXPECT_EQ(StringRef::npos, theString.find_first_not_of("hello"));
|
|
|
|
|
+ EXPECT_EQ(std::string_view::npos, theString.find_first_not_of("hello"));
|
|
|
|
|
|
|
|
|
|
theString = "hellx xello hell ello world foo bar hello";
|
|
|
|
|
EXPECT_EQ(36U, theString.find("hello"));
|
|
|
|
|
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
index dbc626db54482634415599b00697283f293bfdc7..f83bc116e4851f39fd6e496ee25ae1fb9acd96ca 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/unittests/ADT/SmallVectorTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/ADT/SmallVectorTest.cpp
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -11,11 +11,11 @@
|
2022-05-20 18:59:53 -04:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
|
-#include "llvm/ADT/ArrayRef.h"
|
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2026-05-26 16:25:29 -07:00
|
|
|
#include "gmock/gmock.h"
|
2022-05-20 18:59:53 -04:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <list>
|
2023-07-12 22:50:13 -07:00
|
|
|
+#include <span>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
using namespace llvm;
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -250,11 +250,11 @@ TYPED_TEST(SmallVectorTest, ConstructorIterTest) {
|
2023-07-12 22:50:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Constructor test.
|
|
|
|
|
-TYPED_TEST(SmallVectorTest, ConstructorFromArrayRefSimpleTest) {
|
|
|
|
|
- SCOPED_TRACE("ConstructorFromArrayRefSimpleTest");
|
|
|
|
|
+TYPED_TEST(SmallVectorTest, ConstructorFromSpanSimpleTest) {
|
|
|
|
|
+ SCOPED_TRACE("ConstructorFromSpanSimpleTest");
|
|
|
|
|
std::array<Constructable, 3> StdArray = {Constructable(1), Constructable(2),
|
|
|
|
|
Constructable(3)};
|
|
|
|
|
- ArrayRef<Constructable> Array = StdArray;
|
|
|
|
|
+ span<const Constructable> Array = StdArray;
|
|
|
|
|
auto &V = this->theVector;
|
|
|
|
|
V = SmallVector<Constructable, 4>(Array);
|
|
|
|
|
assertValuesInOrder(V, 3u, 1, 2, 3);
|
2026-05-26 16:25:29 -07:00
|
|
|
@@ -597,12 +597,12 @@ TYPED_TEST(SmallVectorTest, AssignSmallVector) {
|
|
|
|
|
assertValuesInOrder(V, 2u, 7, 7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TYPED_TEST(SmallVectorTest, AssignArrayRef) {
|
|
|
|
|
- SCOPED_TRACE("AssignArrayRef");
|
|
|
|
|
+TYPED_TEST(SmallVectorTest, AssignSpan) {
|
|
|
|
|
+ SCOPED_TRACE("AssignSpan");
|
|
|
|
|
auto &V = this->theVector;
|
|
|
|
|
Constructable Other[] = {7, 8, 9};
|
|
|
|
|
V.push_back(Constructable(1));
|
|
|
|
|
- V.assign(ArrayRef(Other));
|
|
|
|
|
+ V.assign(span<const Constructable>(Other));
|
|
|
|
|
assertValuesInOrder(V, 3u, 7, 8, 9);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1135,24 +1135,6 @@ TEST(SmallVectorTest, DefaultInlinedElements) {
|
2022-05-20 18:59:53 -04:00
|
|
|
EXPECT_EQ(NestedV[0][0][0], 42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-TEST(SmallVectorTest, InitializerList) {
|
|
|
|
|
- SmallVector<int, 2> V1 = {};
|
|
|
|
|
- EXPECT_TRUE(V1.empty());
|
|
|
|
|
- V1 = {0, 0};
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V1).equals({0, 0}));
|
2022-05-20 18:59:53 -04:00
|
|
|
- V1 = {-1, -1};
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V1).equals({-1, -1}));
|
2022-05-20 18:59:53 -04:00
|
|
|
-
|
|
|
|
|
- SmallVector<int, 2> V2 = {1, 2, 3, 4};
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V2).equals({1, 2, 3, 4}));
|
2022-05-20 18:59:53 -04:00
|
|
|
- V2.assign({4});
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V2).equals({4}));
|
2022-05-20 18:59:53 -04:00
|
|
|
- V2.append({3, 2});
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V2).equals({4, 3, 2}));
|
2022-05-20 18:59:53 -04:00
|
|
|
- V2.insert(V2.begin() + 1, 5);
|
2023-07-12 22:50:13 -07:00
|
|
|
- EXPECT_TRUE(ArrayRef(V2).equals({4, 5, 3, 2}));
|
2022-05-20 18:59:53 -04:00
|
|
|
-}
|
|
|
|
|
-
|
2026-05-26 16:25:29 -07:00
|
|
|
namespace namespace_with_adl {
|
|
|
|
|
struct MyVector {
|
|
|
|
|
std::vector<int> data;
|
|
|
|
|
@@ -1209,10 +1191,10 @@ private:
|
2023-07-12 22:50:13 -07:00
|
|
|
To T;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
-TEST(SmallVectorTest, ConstructFromArrayRefOfConvertibleType) {
|
|
|
|
|
+TEST(SmallVectorTest, ConstructFromSpanOfConvertibleType) {
|
|
|
|
|
To to1{1}, to2{2}, to3{3};
|
|
|
|
|
std::vector<From> StdVector = {From(to1), From(to2), From(to3)};
|
|
|
|
|
- ArrayRef<From> Array = StdVector;
|
|
|
|
|
+ span<const From> Array = StdVector;
|
|
|
|
|
{
|
|
|
|
|
llvm::SmallVector<To> Vector(Array);
|
|
|
|
|
|
2022-05-20 18:59:53 -04:00
|
|
|
diff --git a/llvm/unittests/Support/ConvertUTFTest.cpp b/llvm/unittests/Support/ConvertUTFTest.cpp
|
2025-06-25 01:36:22 -04:00
|
|
|
index 4c35a7e06df142cab79636df7769e556a42e1646..3b07d344f15a555f11ad5f8177a0a65b8a4fa472 100644
|
2022-05-20 18:59:53 -04:00
|
|
|
--- a/llvm/unittests/Support/ConvertUTFTest.cpp
|
|
|
|
|
+++ b/llvm/unittests/Support/ConvertUTFTest.cpp
|
|
|
|
|
@@ -7,7 +7,6 @@
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "llvm/Support/ConvertUTF.h"
|
|
|
|
|
-#include "llvm/ADT/ArrayRef.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
@@ -17,7 +16,7 @@ using namespace llvm;
|
|
|
|
|
TEST(ConvertUTFTest, ConvertUTF16LittleEndianToUTF8String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
|
|
|
|
|
- ArrayRef<char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
+ span<const char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
std::string Result;
|
|
|
|
|
bool Success = convertUTF16ToUTF8String(Ref, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
2023-07-12 22:50:13 -07:00
|
|
|
@@ -29,7 +28,7 @@ TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
alignas(UTF32) static const char Src[] =
|
|
|
|
|
"\xFF\xFE\x00\x00\xA0\x0C\x00\x00\x5F\x00\x00\x00\xA0\x0C\x00\x00";
|
|
|
|
|
- ArrayRef<char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
+ span<const char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
std::string Result;
|
|
|
|
|
bool Success = convertUTF32ToUTF8String(Ref, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
|
|
|
|
@@ -40,7 +39,7 @@ TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) {
|
2022-05-20 18:59:53 -04:00
|
|
|
TEST(ConvertUTFTest, ConvertUTF16BigEndianToUTF8String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
alignas(UTF16) static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0";
|
|
|
|
|
- ArrayRef<char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
+ span<const char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
std::string Result;
|
|
|
|
|
bool Success = convertUTF16ToUTF8String(Ref, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
2023-07-12 22:50:13 -07:00
|
|
|
@@ -52,7 +51,7 @@ TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
alignas(UTF32) static const char Src[] =
|
|
|
|
|
"\x00\x00\xFE\xFF\x00\x00\x0C\xA0\x00\x00\x00\x5F\x00\x00\x0C\xA0";
|
|
|
|
|
- ArrayRef<char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
+ span<const char> Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
std::string Result;
|
|
|
|
|
bool Success = convertUTF32ToUTF8String(Ref, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
|
|
|
|
@@ -63,7 +62,7 @@ TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) {
|
2022-05-20 18:59:53 -04:00
|
|
|
TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0";
|
|
|
|
|
- StringRef Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
+ std::string_view Ref(Src, sizeof(Src) - 1);
|
|
|
|
|
SmallVector<UTF16, 5> Result;
|
|
|
|
|
bool Success = convertUTF8ToUTF16String(Ref, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -75,37 +74,38 @@ TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) {
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
TEST(ConvertUTFTest, OddLengthInput) {
|
|
|
|
|
std::string Result;
|
2023-07-12 22:50:13 -07:00
|
|
|
- bool Success = convertUTF16ToUTF8String(ArrayRef("xxxxx", 5), Result);
|
2022-05-20 18:59:53 -04:00
|
|
|
+ bool Success = convertUTF16ToUTF8String(span<const char>("xxxxx", 5), Result);
|
|
|
|
|
EXPECT_FALSE(Success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertUTFTest, Empty) {
|
|
|
|
|
std::string Result;
|
2025-06-25 01:36:22 -04:00
|
|
|
- bool Success = convertUTF16ToUTF8String(llvm::ArrayRef<char>(), Result);
|
|
|
|
|
+ bool Success =
|
2023-07-12 22:50:13 -07:00
|
|
|
+ convertUTF16ToUTF8String(span<const char>(), Result);
|
2022-05-20 18:59:53 -04:00
|
|
|
EXPECT_TRUE(Success);
|
|
|
|
|
EXPECT_TRUE(Result.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertUTFTest, HasUTF16BOM) {
|
2023-07-12 22:50:13 -07:00
|
|
|
- bool HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xff\xfe", 2));
|
2022-05-20 18:59:53 -04:00
|
|
|
+ bool HasBOM = hasUTF16ByteOrderMark("\xff\xfe");
|
|
|
|
|
EXPECT_TRUE(HasBOM);
|
2023-07-12 22:50:13 -07:00
|
|
|
- HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff", 2));
|
2022-05-20 18:59:53 -04:00
|
|
|
+ HasBOM = hasUTF16ByteOrderMark("\xfe\xff");
|
|
|
|
|
EXPECT_TRUE(HasBOM);
|
2023-07-12 22:50:13 -07:00
|
|
|
- HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff ", 3));
|
2022-05-20 18:59:53 -04:00
|
|
|
+ HasBOM = hasUTF16ByteOrderMark("\xfe\xff ");
|
|
|
|
|
EXPECT_TRUE(HasBOM); // Don't care about odd lengths.
|
2023-07-12 22:50:13 -07:00
|
|
|
- HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff\x00asdf", 6));
|
2022-05-20 18:59:53 -04:00
|
|
|
+ HasBOM = hasUTF16ByteOrderMark("\xfe\xff\x00asdf");
|
|
|
|
|
EXPECT_TRUE(HasBOM);
|
|
|
|
|
|
2025-06-25 01:36:22 -04:00
|
|
|
- HasBOM = hasUTF16ByteOrderMark({});
|
2022-05-20 18:59:53 -04:00
|
|
|
+ HasBOM = hasUTF16ByteOrderMark("");
|
|
|
|
|
EXPECT_FALSE(HasBOM);
|
2023-07-12 22:50:13 -07:00
|
|
|
- HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe", 1));
|
2022-05-20 18:59:53 -04:00
|
|
|
+ HasBOM = hasUTF16ByteOrderMark("\xfe");
|
|
|
|
|
EXPECT_FALSE(HasBOM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) {
|
|
|
|
|
// Src is the look of disapproval.
|
|
|
|
|
alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c";
|
2023-07-12 22:50:13 -07:00
|
|
|
- ArrayRef<UTF16> SrcRef = ArrayRef((const UTF16 *)Src, 4);
|
2022-05-20 18:59:53 -04:00
|
|
|
+ span<const UTF16> SrcRef((const UTF16 *)Src, 4);
|
|
|
|
|
std::string Result;
|
|
|
|
|
bool Success = convertUTF16ToUTF8String(SrcRef, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -122,7 +122,7 @@ TEST(ConvertUTFTest, ConvertUTF8toWide) {
|
2022-05-20 18:59:53 -04:00
|
|
|
std::wstring Expected(L"\x0ca0_\x0ca0");
|
|
|
|
|
EXPECT_EQ(Expected, Result);
|
|
|
|
|
Result.clear();
|
|
|
|
|
- Success = ConvertUTF8toWide(StringRef(Src, 7), Result);
|
|
|
|
|
+ Success = ConvertUTF8toWide(Src, Result);
|
|
|
|
|
EXPECT_TRUE(Success);
|
|
|
|
|
EXPECT_EQ(Expected, Result);
|
|
|
|
|
}
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -171,7 +171,7 @@ struct ConvertUTFResultContainer {
|
2022-05-20 18:59:53 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::pair<ConversionResult, std::vector<unsigned>>
|
|
|
|
|
-ConvertUTF8ToUnicodeScalarsLenient(StringRef S) {
|
|
|
|
|
+ConvertUTF8ToUnicodeScalarsLenient(std::string_view S) {
|
|
|
|
|
const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data());
|
|
|
|
|
|
|
|
|
|
const UTF8 *SourceNext = SourceStart;
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -188,7 +188,7 @@ ConvertUTF8ToUnicodeScalarsLenient(StringRef S) {
|
2022-05-20 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<ConversionResult, std::vector<unsigned>>
|
|
|
|
|
-ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) {
|
|
|
|
|
+ConvertUTF8ToUnicodeScalarsPartialLenient(std::string_view S) {
|
|
|
|
|
const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data());
|
|
|
|
|
|
|
|
|
|
const UTF8 *SourceNext = SourceStart;
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -206,7 +206,7 @@ ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) {
|
2022-05-20 18:59:53 -04:00
|
|
|
|
|
|
|
|
::testing::AssertionResult
|
|
|
|
|
CheckConvertUTF8ToUnicodeScalars(ConvertUTFResultContainer Expected,
|
|
|
|
|
- StringRef S, bool Partial = false) {
|
|
|
|
|
+ std::string_view S, bool Partial = false) {
|
|
|
|
|
ConversionResult ErrorCode;
|
|
|
|
|
std::vector<unsigned> Decoded;
|
|
|
|
|
if (!Partial)
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -301,7 +301,7 @@ TEST(ConvertUTFTest, UTF8ToUTF32Lenient) {
|
2022-05-20 18:59:53 -04:00
|
|
|
// U+0000 NULL
|
|
|
|
|
EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
|
|
|
|
|
ConvertUTFResultContainer(conversionOK).withScalars(0x0000),
|
|
|
|
|
- StringRef("\x00", 1)));
|
|
|
|
|
+ std::string_view("\x00", 1)));
|
|
|
|
|
|
|
|
|
|
// U+0080 PADDING CHARACTER
|
|
|
|
|
EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
|
2025-06-25 01:36:22 -04:00
|
|
|
@@ -1075,7 +1075,7 @@ TEST(ConvertUTFTest, UTF8ToUTF32Lenient) {
|
2022-05-20 18:59:53 -04:00
|
|
|
// U+0000 NULL
|
|
|
|
|
EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
|
|
|
|
|
ConvertUTFResultContainer(conversionOK).withScalars(0x0000),
|
|
|
|
|
- StringRef("\x00", 1)));
|
|
|
|
|
+ std::string_view("\x00", 1)));
|
|
|
|
|
|
|
|
|
|
// Overlong sequences of the above.
|
|
|
|
|
EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars(
|