[libc-commits] [libc] 2a6ef2a - [libc] Use cpp::Array instead of cpp::ArrayRef in memory/utils_test.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Fri Jan 31 11:45:20 PST 2020
Author: Siva Chandra Reddy
Date: 2020-01-31T11:45:09-08:00
New Revision: 2a6ef2aecf2d75f410195cef14846348f33a24de
URL: https://github.com/llvm/llvm-project/commit/2a6ef2aecf2d75f410195cef14846348f33a24de
DIFF: https://github.com/llvm/llvm-project/commit/2a6ef2aecf2d75f410195cef14846348f33a24de.diff
LOG: [libc] Use cpp::Array instead of cpp::ArrayRef in memory/utils_test.
Building with address-sanitizer shows that using ArrayRef ends up
accessing a temporary outside its scope.
Added:
Modified:
libc/test/src/string/memory_utils/utils_test.cpp
Removed:
################################################################################
diff --git a/libc/test/src/string/memory_utils/utils_test.cpp b/libc/test/src/string/memory_utils/utils_test.cpp
index d3ae3ff2f3b4..c54209213772 100644
--- a/libc/test/src/string/memory_utils/utils_test.cpp
+++ b/libc/test/src/string/memory_utils/utils_test.cpp
@@ -7,67 +7,67 @@
//===----------------------------------------------------------------------===//
#include "src/string/memory_utils/utils.h"
-#include "utils/CPP/ArrayRef.h"
+#include "utils/CPP/Array.h"
#include "utils/UnitTest/Test.h"
namespace __llvm_libc {
TEST(UtilsTest, IsPowerOfTwoOrZero) {
- static const cpp::ArrayRef<bool> kExpectedValues({
+ static const cpp::Array<bool, 65> kExpectedValues{
1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 0-15
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32-47
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 48-63
1 // 64
- });
+ };
for (size_t i = 0; i < kExpectedValues.size(); ++i)
EXPECT_EQ(is_power2_or_zero(i), kExpectedValues[i]);
}
TEST(UtilsTest, IsPowerOfTwo) {
- static const cpp::ArrayRef<bool> kExpectedValues({
+ static const cpp::Array<bool, 65> kExpectedValues{
0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 0-15
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32-47
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 48-63
1 // 64
- });
+ };
for (size_t i = 0; i < kExpectedValues.size(); ++i)
EXPECT_EQ(is_power2(i), kExpectedValues[i]);
}
TEST(UtilsTest, Log2) {
- static const cpp::ArrayRef<size_t> kExpectedValues({
+ static const cpp::Array<size_t, 65> kExpectedValues{
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 0-15
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 16-31
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 32-47
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, // 48-63
6 // 64
- });
+ };
for (size_t i = 0; i < kExpectedValues.size(); ++i)
EXPECT_EQ(log2(i), kExpectedValues[i]);
}
TEST(UtilsTest, LEPowerOf2) {
- static const cpp::ArrayRef<size_t> kExpectedValues({
+ static const cpp::Array<size_t, 65> kExpectedValues{
0, 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, // 0-15
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, // 16-31
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 32-47
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 48-63
64 // 64
- });
+ };
for (size_t i = 0; i < kExpectedValues.size(); ++i)
EXPECT_EQ(le_power2(i), kExpectedValues[i]);
}
TEST(UtilsTest, GEPowerOf2) {
- static const cpp::ArrayRef<size_t> kExpectedValues({
+ static const cpp::Array<size_t, 66> kExpectedValues{
0, 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, // 0-15
16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, // 16-31
32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, // 32-47
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, // 48-63
64, 128 // 64-65
- });
+ };
for (size_t i = 0; i < kExpectedValues.size(); ++i)
EXPECT_EQ(ge_power2(i), kExpectedValues[i]);
}
More information about the libc-commits
mailing list