From: Siva Chandra Reddy Date: Fri, 31 Jan 2020 19:39:06 +0000 (-0800) Subject: [libc] Use cpp::Array instead of cpp::ArrayRef in memory/utils_test. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a6ef2aecf2d75f410195cef14846348f33a24de;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/libc/test/src/string/memory_utils/utils_test.cpp b/libc/test/src/string/memory_utils/utils_test.cpp index d3ae3ff..c542092 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 kExpectedValues({ + static const cpp::Array 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 kExpectedValues({ + static const cpp::Array 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 kExpectedValues({ + static const cpp::Array 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 kExpectedValues({ + static const cpp::Array 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 kExpectedValues({ + static const cpp::Array 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]); }