aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r--llvm/unittests/ADT/BitTest.cpp38
-rw-r--r--llvm/unittests/ADT/STLForwardCompatTest.cpp22
-rw-r--r--llvm/unittests/ADT/StringSwitchTest.cpp8
3 files changed, 64 insertions, 4 deletions
diff --git a/llvm/unittests/ADT/BitTest.cpp b/llvm/unittests/ADT/BitTest.cpp
index eaed4e1..e8041bb 100644
--- a/llvm/unittests/ADT/BitTest.cpp
+++ b/llvm/unittests/ADT/BitTest.cpp
@@ -270,6 +270,44 @@ TEST(BitTest, BitWidthConstexpr) {
llvm::bit_width_constexpr(std::numeric_limits<uint64_t>::max()) == 64);
}
+TEST(BitTest, BitCeilConstexpr) {
+ static_assert(llvm::bit_ceil_constexpr(0u) == 1);
+ static_assert(llvm::bit_ceil_constexpr(1u) == 1);
+ static_assert(llvm::bit_ceil_constexpr(2u) == 2);
+ static_assert(llvm::bit_ceil_constexpr(3u) == 4);
+ static_assert(llvm::bit_ceil_constexpr(4u) == 4);
+ static_assert(llvm::bit_ceil_constexpr(5u) == 8);
+ static_assert(llvm::bit_ceil_constexpr(6u) == 8);
+ static_assert(llvm::bit_ceil_constexpr(7u) == 8);
+ static_assert(llvm::bit_ceil_constexpr(8u) == 8);
+
+ static_assert(llvm::bit_ceil_constexpr(255u) == 256);
+ static_assert(llvm::bit_ceil_constexpr(256u) == 256);
+ static_assert(llvm::bit_ceil_constexpr(257u) == 512);
+}
+
+TEST(BitTest, CountrZeroConstexpr) {
+ static_assert(llvm::countr_zero_constexpr(0u) == 32);
+ static_assert(llvm::countr_zero_constexpr(1u) == 0);
+ static_assert(llvm::countr_zero_constexpr(2u) == 1);
+ static_assert(llvm::countr_zero_constexpr(3u) == 0);
+ static_assert(llvm::countr_zero_constexpr(4u) == 2);
+ static_assert(llvm::countr_zero_constexpr(8u) == 3);
+ static_assert(llvm::countr_zero_constexpr(0x80000000u) == 31);
+
+ static_assert(llvm::countr_zero_constexpr(0ull) == 64);
+ static_assert(llvm::countr_zero_constexpr(1ull) == 0);
+ static_assert(llvm::countr_zero_constexpr(0x100000000ull) == 32);
+ static_assert(llvm::countr_zero_constexpr(0x8000000000000000ull) == 63);
+
+ static_assert(
+ llvm::countr_zero_constexpr(std::numeric_limits<uint16_t>::max()) == 0);
+ static_assert(
+ llvm::countr_zero_constexpr(std::numeric_limits<uint32_t>::max()) == 0);
+ static_assert(
+ llvm::countr_zero_constexpr(std::numeric_limits<uint64_t>::max()) == 0);
+}
+
TEST(BitTest, CountlZero) {
uint8_t Z8 = 0;
uint16_t Z16 = 0;
diff --git a/llvm/unittests/ADT/STLForwardCompatTest.cpp b/llvm/unittests/ADT/STLForwardCompatTest.cpp
index 4a8f53c..2a97e8d 100644
--- a/llvm/unittests/ADT/STLForwardCompatTest.cpp
+++ b/llvm/unittests/ADT/STLForwardCompatTest.cpp
@@ -184,4 +184,26 @@ TEST(TransformTest, ToUnderlying) {
static_assert(llvm::to_underlying(E3::B3) == 0);
}
+TEST(STLForwardCompatTest, IdentityCxx20) {
+ llvm::identity_cxx20 identity;
+
+ // Test with an lvalue.
+ int X = 42;
+ int &Y = identity(X);
+ EXPECT_EQ(&X, &Y);
+
+ // Test with a const lvalue.
+ const int CX = 10;
+ const int &CY = identity(CX);
+ EXPECT_EQ(&CX, &CY);
+
+ // Test with an rvalue.
+ EXPECT_EQ(identity(123), 123);
+
+ // Test perfect forwarding.
+ static_assert(std::is_same_v<int &, decltype(identity(X))>);
+ static_assert(std::is_same_v<const int &, decltype(identity(CX))>);
+ static_assert(std::is_same_v<int &&, decltype(identity(int(5)))>);
+}
+
} // namespace
diff --git a/llvm/unittests/ADT/StringSwitchTest.cpp b/llvm/unittests/ADT/StringSwitchTest.cpp
index 0fbf371..d88a0ff 100644
--- a/llvm/unittests/ADT/StringSwitchTest.cpp
+++ b/llvm/unittests/ADT/StringSwitchTest.cpp
@@ -159,7 +159,7 @@ TEST(StringSwitchTest, Cases) {
return llvm::StringSwitch<OSType>(S)
.Cases(StringLiteral::withInnerNUL("wind\0ws"), "win32", "winnt",
OSType::Windows)
- .Cases("linux", "unix", "*nix", "posix", OSType::Linux)
+ .Cases({"linux", "unix", "*nix", "posix"}, OSType::Linux)
.Cases({"macos", "osx"}, OSType::MacOS)
.Default(OSType::Unknown);
};
@@ -191,7 +191,7 @@ TEST(StringSwitchTest, CasesLower) {
return llvm::StringSwitch<OSType>(S)
.CasesLower(StringLiteral::withInnerNUL("wind\0ws"), "win32", "winnt",
OSType::Windows)
- .CasesLower("linux", "unix", "*nix", "posix", OSType::Linux)
+ .CasesLower({"linux", "unix", "*nix", "posix"}, OSType::Linux)
.CasesLower({"macos", "osx"}, OSType::MacOS)
.Default(OSType::Unknown);
};
@@ -230,13 +230,13 @@ TEST(StringSwitchTest, CasesCopies) {
// Check that evaluating multiple cases does not cause unnecessary copies.
unsigned NumCopies = 0;
- llvm::StringSwitch<Copyable, void>("baz").Cases("foo", "bar", "baz", "qux",
+ llvm::StringSwitch<Copyable, void>("baz").Cases({"foo", "bar", "baz", "qux"},
Copyable{NumCopies});
EXPECT_EQ(NumCopies, 1u);
NumCopies = 0;
llvm::StringSwitch<Copyable, void>("baz").CasesLower(
- "Foo", "Bar", "Baz", "Qux", Copyable{NumCopies});
+ {"Foo", "Bar", "Baz", "Qux"}, Copyable{NumCopies});
EXPECT_EQ(NumCopies, 1u);
}