- Notifications
You must be signed in to change notification settings - Fork 15.3k
[scudo] Add -Wconversion for tests and clean-up warnings. #66147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Fix all the places where the tests are doing implicit conversions.
Member
| @llvm/pr-subscribers-compiler-rt-sanitizer ChangesFix all the places where the tests are doing implicit conversions. -- Full diff: https://github.com//pull/66147.diff3 Files Affected:
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 |
hctim reviewed Sep 12, 2023
Collaborator
hctim left a comment
There was a problem hiding this 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.
Contributor Author
| Any further comments? |
hctim approved these changes Sep 13, 2023
ChiaHungDuan approved these changes Sep 13, 2023
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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Fix all the places where the tests are doing implicit conversions.