Skip to content

Conversation

@cferris1000
Copy link
Contributor

Fix all the places where the tests are doing implicit conversions.

Fix all the places where the tests are doing implicit conversions.
@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2023

@llvm/pr-subscribers-compiler-rt-sanitizer

Changes Fix all the places where the tests are doing implicit conversions. -- Full diff: https://github.com//pull/66147.diff

3 Files Affected:

  • (modified) compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt (+1)
  • (modified) compiler-rt/lib/scudo/standalone/tests/combined_test.cpp (+13-13)
  • (modified) compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp (+6-6)
diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt index e5d32f33d8cc4a1..a4a031d54d7c3ad 100644 --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -15,6 +15,7 @@ set(SCUDO_UNITTEST_CFLAGS -DGTEST_HAS_RTTI=0 -g # Extra flags for the C++ tests + -Wconversion # TODO(kostyak): find a way to make -fsized-deallocation work -Wno-mismatched-new-delete) diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp index fc118fcadc6b6c7..911ee6187bab37f 100644 --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -54,7 +54,7 @@ void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size, EXPECT_DEATH( { disableDebuggerdMaybe(); - reinterpret_cast<char *>(P)[-1] = 0xaa; + reinterpret_cast<char *>(P)[-1] = '\xaa'; }, ""); if (isPrimaryAllocation<AllocatorT>(Size, Alignment) @@ -63,7 +63,7 @@ void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size, EXPECT_DEATH( { disableDebuggerdMaybe(); - reinterpret_cast<char *>(P)[Size] = 0xaa; + reinterpret_cast<char *>(P)[Size] = '\xaa'; }, ""); } @@ -268,7 +268,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ZeroContents) { void *P = Allocator->allocate(Size, Origin, 1U << MinAlignLog, true); EXPECT_NE(P, nullptr); for (scudo::uptr I = 0; I < Size; I++) - ASSERT_EQ((reinterpret_cast<char *>(P))[I], 0); + ASSERT_EQ((reinterpret_cast<char *>(P))[I], '\0'); memset(P, 0xaa, Size); Allocator->deallocate(P, Origin, Size); } @@ -286,7 +286,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ZeroFill) { void *P = Allocator->allocate(Size, Origin, 1U << MinAlignLog, false); EXPECT_NE(P, nullptr); for (scudo::uptr I = 0; I < Size; I++) - ASSERT_EQ((reinterpret_cast<char *>(P))[I], 0); + ASSERT_EQ((reinterpret_cast<char *>(P))[I], '\0'); memset(P, 0xaa, Size); Allocator->deallocate(P, Origin, Size); } @@ -345,7 +345,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLargeIncreasing) { // we preserve the data in the process. scudo::uptr Size = 16; void *P = Allocator->allocate(Size, Origin); - const char Marker = 0xab; + const char Marker = '\xab'; memset(P, Marker, Size); while (Size < TypeParam::Primary::SizeClassMap::MaxSize * 4) { void *NewP = Allocator->reallocate(P, Size * 2); @@ -367,7 +367,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateLargeDecreasing) { scudo::uptr Size = TypeParam::Primary::SizeClassMap::MaxSize * 2; const scudo::uptr DataSize = 2048U; void *P = Allocator->allocate(Size, Origin); - const char Marker = 0xab; + const char Marker = '\xab'; memset(P, Marker, scudo::Min(Size, DataSize)); while (Size > 1U) { Size /= 2U; @@ -390,7 +390,7 @@ SCUDO_TYPED_TEST(ScudoCombinedDeathTest, ReallocateSame) { constexpr scudo::uptr ReallocSize = TypeParam::Primary::SizeClassMap::MaxSize - 64; void *P = Allocator->allocate(ReallocSize, Origin); - const char Marker = 0xab; + const char Marker = '\xab'; memset(P, Marker, ReallocSize); for (scudo::sptr Delta = -32; Delta < 32; Delta += 8) { const scudo::uptr NewSize = @@ -447,7 +447,7 @@ SCUDO_TYPED_TEST(ScudoCombinedDeathTest, UseAfterFree) { disableDebuggerdMaybe(); void *P = Allocator->allocate(Size, Origin); Allocator->deallocate(P, Origin); - reinterpret_cast<char *>(P)[0] = 0xaa; + reinterpret_cast<char *>(P)[0] = '\xaa'; }, ""); EXPECT_DEATH( @@ -455,7 +455,7 @@ SCUDO_TYPED_TEST(ScudoCombinedDeathTest, UseAfterFree) { disableDebuggerdMaybe(); void *P = Allocator->allocate(Size, Origin); Allocator->deallocate(P, Origin); - reinterpret_cast<char *>(P)[Size - 1] = 0xaa; + reinterpret_cast<char *>(P)[Size - 1] = '\xaa'; }, ""); } @@ -467,15 +467,15 @@ SCUDO_TYPED_TEST(ScudoCombinedDeathTest, DisableMemoryTagging) { if (Allocator->useMemoryTaggingTestOnly()) { // Check that disabling memory tagging works correctly. void *P = Allocator->allocate(2048, Origin); - EXPECT_DEATH(reinterpret_cast<char *>(P)[2048] = 0xaa, ""); + EXPECT_DEATH(reinterpret_cast<char *>(P)[2048] = '\xaa', ""); scudo::ScopedDisableMemoryTagChecks NoTagChecks; Allocator->disableMemoryTagging(); - reinterpret_cast<char *>(P)[2048] = 0xaa; + reinterpret_cast<char *>(P)[2048] = '\xaa'; Allocator->deallocate(P, Origin); P = Allocator->allocate(2048, Origin); EXPECT_EQ(scudo::untagPointer(P), P); - reinterpret_cast<char *>(P)[2048] = 0xaa; + reinterpret_cast<char *>(P)[2048] = '\xaa'; Allocator->deallocate(P, Origin); Allocator->releaseToOS(scudo::ReleaseToOS::Force); @@ -782,7 +782,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, DisableMemInit) { for (unsigned I = 0; I != Ptrs.size(); ++I) { Ptrs[I] = Allocator->allocate(Size, Origin, 1U << MinAlignLog, true); for (scudo::uptr J = 0; J < Size; ++J) - ASSERT_EQ((reinterpret_cast<char *>(Ptrs[I]))[J], 0); + ASSERT_EQ((reinterpret_cast<char *>(Ptrs[I]))[J], '\0'); } } diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp index 0e82813df8c0d5f..de1024d01fe8251 100644 --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp @@ -391,18 +391,18 @@ TEST_F(ScudoWrappersCTest, MallInfo) { // mallinfo is deprecated. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - const size_t BypassQuarantineSize = 1024U; + const int BypassQuarantineSize = 1024; struct mallinfo MI = mallinfo(); - size_t Allocated = MI.uordblks; + int Allocated = MI.uordblks; void *P = malloc(BypassQuarantineSize); EXPECT_NE(P, nullptr); MI = mallinfo(); - EXPECT_GE(static_cast<size_t>(MI.uordblks), Allocated + BypassQuarantineSize); - EXPECT_GT(static_cast<size_t>(MI.hblkhd), 0U); - size_t Free = MI.fordblks; + EXPECT_GE(MI.uordblks, Allocated + BypassQuarantineSize); + EXPECT_GT(MI.hblkhd, 0); + int Free = MI.fordblks; free(P); MI = mallinfo(); - EXPECT_GE(static_cast<size_t>(MI.fordblks), Free + BypassQuarantineSize); + EXPECT_GE(MI.fordblks, Free + BypassQuarantineSize); #pragma clang diagnostic pop } #endif 
Copy link
Collaborator

@hctim hctim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment in a few other places, would you be able to change the char-based magic values to something without the hex prefix (like 'A')?

In addition, update the mallinfo tests for Android.
@cferris1000
Copy link
Contributor Author

Any further comments?

@cferris1000 cferris1000 merged commit fd1721d into llvm:main Sep 14, 2023
@cferris1000 cferris1000 deleted the fix_warnings branch September 14, 2023 19:32
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Fix all the places where the tests are doing implicit conversions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment