diff --git a/compiler-rt/lib/scudo/standalone/checksum.cpp b/compiler-rt/lib/scudo/standalone/checksum.cpp --- a/compiler-rt/lib/scudo/standalone/checksum.cpp +++ b/compiler-rt/lib/scudo/standalone/checksum.cpp @@ -8,6 +8,7 @@ #include "checksum.h" #include "atomic_helpers.h" +#include "chunk.h" #if defined(__x86_64__) || defined(__i386__) #include diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -1271,8 +1271,8 @@ } static const size_t NumErrorReports = - sizeof(((scudo_error_info *)0)->reports) / - sizeof(((scudo_error_info *)0)->reports[0]); + sizeof(((scudo_error_info *)nullptr)->reports) / + sizeof(((scudo_error_info *)nullptr)->reports[0]); static void getInlineErrorInfo(struct scudo_error_info *ErrorInfo, size_t &NextErrorReport, uintptr_t FaultAddr, diff --git a/compiler-rt/lib/scudo/standalone/common.h b/compiler-rt/lib/scudo/standalone/common.h --- a/compiler-rt/lib/scudo/standalone/common.h +++ b/compiler-rt/lib/scudo/standalone/common.h @@ -117,6 +117,7 @@ // Platform specific functions. extern uptr PageSizeCached; +uptr getPageSize(); uptr getPageSizeSlow(); inline uptr getPageSizeCached() { // Bionic uses a hardcoded value. diff --git a/compiler-rt/lib/scudo/standalone/flags_parser.cpp b/compiler-rt/lib/scudo/standalone/flags_parser.cpp --- a/compiler-rt/lib/scudo/standalone/flags_parser.cpp +++ b/compiler-rt/lib/scudo/standalone/flags_parser.cpp @@ -11,7 +11,6 @@ #include "report.h" #include -#include namespace scudo { diff --git a/compiler-rt/lib/scudo/standalone/memtag.h b/compiler-rt/lib/scudo/standalone/memtag.h --- a/compiler-rt/lib/scudo/standalone/memtag.h +++ b/compiler-rt/lib/scudo/standalone/memtag.h @@ -41,6 +41,8 @@ inline constexpr bool archSupportsMemoryTagging() { return false; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-noreturn" inline uptr archMemoryTagGranuleSize() { UNREACHABLE("memory tagging not supported"); } @@ -54,6 +56,7 @@ (void)Ptr; UNREACHABLE("memory tagging not supported"); } +#pragma clang diagnostic pop #endif @@ -109,6 +112,8 @@ inline bool systemSupportsMemoryTagging() { return false; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-noreturn" inline bool systemDetectsMemoryTagFaultsTestOnly() { UNREACHABLE("memory tagging not supported"); } @@ -116,6 +121,7 @@ inline void enableSystemMemoryTaggingTestOnly() { UNREACHABLE("memory tagging not supported"); } +#pragma clang diagnostic pop #endif // SCUDO_LINUX @@ -255,6 +261,8 @@ #else +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmissing-noreturn" inline bool systemSupportsMemoryTagging() { UNREACHABLE("memory tagging not supported"); } @@ -298,6 +306,7 @@ (void)Ptr; UNREACHABLE("memory tagging not supported"); } +#pragma clang diagnostic pop #endif diff --git a/compiler-rt/lib/scudo/standalone/mutex.h b/compiler-rt/lib/scudo/standalone/mutex.h --- a/compiler-rt/lib/scudo/standalone/mutex.h +++ b/compiler-rt/lib/scudo/standalone/mutex.h @@ -12,8 +12,6 @@ #include "atomic_helpers.h" #include "common.h" -#include - #if SCUDO_FUCHSIA #include // for sync_mutex_t #endif diff --git a/compiler-rt/lib/scudo/standalone/platform.h b/compiler-rt/lib/scudo/standalone/platform.h --- a/compiler-rt/lib/scudo/standalone/platform.h +++ b/compiler-rt/lib/scudo/standalone/platform.h @@ -37,7 +37,7 @@ #define SCUDO_TRUSTY 0 #endif -#if __LP64__ +#if defined(__LP64__) #define SCUDO_WORDSIZE 64U #else #define SCUDO_WORDSIZE 32U diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h --- a/compiler-rt/lib/scudo/standalone/primary64.h +++ b/compiler-rt/lib/scudo/standalone/primary64.h @@ -89,7 +89,8 @@ RegionInfo *Region = getRegionInfo(I); *Region = {}; } - unmap(reinterpret_cast(PrimaryBase), PrimarySize, UNMAP_ALL, &Data); + if (PrimaryBase) + unmap(reinterpret_cast(PrimaryBase), PrimarySize, UNMAP_ALL, &Data); PrimaryBase = 0U; } diff --git a/compiler-rt/lib/scudo/standalone/quarantine.h b/compiler-rt/lib/scudo/standalone/quarantine.h --- a/compiler-rt/lib/scudo/standalone/quarantine.h +++ b/compiler-rt/lib/scudo/standalone/quarantine.h @@ -24,19 +24,19 @@ u32 Count; void *Batch[MaxCount]; - void init(void *Ptr, uptr Size) { + void init(void *Ptr, uptr Sz) { Count = 1; Batch[0] = Ptr; - this->Size = Size + sizeof(QuarantineBatch); // Account for the Batch Size. + this->Size = Sz + sizeof(QuarantineBatch); // Account for the Batch Size. } // The total size of quarantined nodes recorded in this batch. uptr getQuarantinedSize() const { return Size - sizeof(QuarantineBatch); } - void push_back(void *Ptr, uptr Size) { + void push_back(void *Ptr, uptr Sz) { DCHECK_LT(Count, MaxCount); Batch[Count++] = Ptr; - this->Size += Size; + this->Size += Sz; } bool canMerge(const QuarantineBatch *const From) const { @@ -71,16 +71,16 @@ // Memory used for internal accounting. uptr getOverheadSize() const { return List.size() * sizeof(QuarantineBatch); } - void enqueue(Callback Cb, void *Ptr, uptr Size) { + void enqueue(Callback Cb, void *Ptr, uptr Sz) { if (List.empty() || List.back()->Count == QuarantineBatch::MaxCount) { QuarantineBatch *B = reinterpret_cast(Cb.allocate(sizeof(*B))); DCHECK(B); - B->init(Ptr, Size); + B->init(Ptr, Sz); enqueueBatch(B); } else { - List.back()->push_back(Ptr, Size); - addToSize(Size); + List.back()->push_back(Ptr, Sz); + addToSize(Sz); } } @@ -242,7 +242,7 @@ atomic_uptr MaxSize = {}; alignas(SCUDO_CACHE_LINE_SIZE) atomic_uptr MaxCacheSize = {}; - void NOINLINE recycle(uptr MinSize, Callback Cb) { + void NOINLINE recycle(uptr MinSz, Callback Cb) { CacheT Tmp; Tmp.init(); { @@ -266,7 +266,7 @@ } // Extract enough chunks from the quarantine to get below the max // quarantine size and leave some leeway for the newly quarantined chunks. - while (Cache.getSize() > MinSize) + while (Cache.getSize() > MinSz) Tmp.enqueueBatch(Cache.dequeueBatch()); } RecycleMutex.unlock(); diff --git a/compiler-rt/lib/scudo/standalone/release.h b/compiler-rt/lib/scudo/standalone/release.h --- a/compiler-rt/lib/scudo/standalone/release.h +++ b/compiler-rt/lib/scudo/standalone/release.h @@ -17,8 +17,8 @@ class ReleaseRecorder { public: - ReleaseRecorder(uptr Base, MapPlatformData *Data = nullptr) - : Base(Base), Data(Data) {} + ReleaseRecorder(uptr _Base, MapPlatformData *_Data = nullptr) + : Base(_Base), Data(_Data) {} uptr getReleasedRangesCount() const { return ReleasedRangesCount; } @@ -145,8 +145,8 @@ template class FreePagesRangeTracker { public: - explicit FreePagesRangeTracker(ReleaseRecorderT *Recorder) - : Recorder(Recorder), PageSizeLog(getLog2(getPageSizeCached())) {} + explicit FreePagesRangeTracker(ReleaseRecorderT *_Recorder) + : Recorder(_Recorder), PageSizeLog(getLog2(getPageSizeCached())) {} void processNextPage(bool Freed) { if (Freed) { diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -245,8 +245,11 @@ } } if (Found) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wconditional-uninitialized" *H = reinterpret_cast( LargeBlock::addHeaderTag(HeaderPos)); +#pragma clang diagnostic pop *Zeroed = Entry.Time == 0; if (useMemoryTagging(Options)) setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0, &Entry.Data); @@ -395,7 +398,10 @@ atomic_s32 ReleaseToOsIntervalMs = {}; CachedBlock Entries[Config::SecondaryCacheEntriesArraySize] = {}; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wzero-length-array" CachedBlock Quarantine[Config::SecondaryCacheQuarantineSize] = {}; +#pragma clang diagnostic pop }; template class MapAllocator { @@ -445,7 +451,7 @@ } } - uptr canCache(uptr Size) { return Cache.canCache(Size); } + bool canCache(uptr Size) { return Cache.canCache(Size); } bool setOption(Option O, sptr Value) { return Cache.setOption(O, Value); } diff --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h --- a/compiler-rt/lib/scudo/standalone/size_class_map.h +++ b/compiler-rt/lib/scudo/standalone/size_class_map.h @@ -345,7 +345,7 @@ Buffer.output(); } -template static void validateMap() { +template static UNUSED void validateMap() { for (uptr C = 0; C < SCMap::NumClasses; C++) { if (C == SCMap::BatchClassId) continue; diff --git a/compiler-rt/lib/scudo/standalone/string_utils.cpp b/compiler-rt/lib/scudo/standalone/string_utils.cpp --- a/compiler-rt/lib/scudo/standalone/string_utils.cpp +++ b/compiler-rt/lib/scudo/standalone/string_utils.cpp @@ -10,7 +10,6 @@ #include "common.h" #include -#include namespace scudo { diff --git a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp @@ -10,9 +10,6 @@ #include "bytemap.h" -#include -#include - template void testMap(T &Map, scudo::uptr Size) { Map.init(); for (scudo::uptr I = 0; I < Size; I += 7) diff --git a/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp b/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/checksum_test.cpp @@ -12,16 +12,16 @@ #include -scudo::u16 computeSoftwareChecksum(scudo::u32 Seed, scudo::uptr *Array, - scudo::uptr ArraySize) { +static scudo::u16 computeSoftwareChecksum(scudo::u32 Seed, scudo::uptr *Array, + scudo::uptr ArraySize) { scudo::u16 Checksum = static_cast(Seed & 0xffff); for (scudo::uptr I = 0; I < ArraySize; I++) Checksum = scudo::computeBSDChecksum(Checksum, Array[I]); return Checksum; } -scudo::u16 computeHardwareChecksum(scudo::u32 Seed, scudo::uptr *Array, - scudo::uptr ArraySize) { +static scudo::u16 computeHardwareChecksum(scudo::u32 Seed, scudo::uptr *Array, + scudo::uptr ArraySize) { scudo::u32 Crc = Seed; for (scudo::uptr I = 0; I < ArraySize; I++) Crc = scudo::computeHardwareCRC32(Crc, Array[I]); @@ -32,7 +32,7 @@ // This verifies that flipping bits in the data being checksummed produces a // different checksum. We do not use random data to avoid flakyness. -template void verifyChecksumFunctionBitFlip() { +template static void verifyChecksumFunctionBitFlip() { scudo::uptr Array[sizeof(scudo::u64) / sizeof(scudo::uptr)]; const scudo::uptr ArraySize = ARRAY_SIZE(Array); memset(Array, 0xaa, sizeof(Array)); diff --git a/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp b/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/chunk_test.cpp @@ -55,7 +55,8 @@ scudo::Chunk::compareExchangeHeader(Cookie, P, &NewHeader, &OldHeader); NewHeader = {}; EXPECT_TRUE(scudo::Chunk::isValid(Cookie, P, &NewHeader)); - EXPECT_EQ(NewHeader.State, scudo::Chunk::State::Quarantined); + EXPECT_EQ(NewHeader.State, + static_cast(scudo::Chunk::State::Quarantined)); EXPECT_FALSE(scudo::Chunk::isValid(InvalidCookie, P, &NewHeader)); free(Block); } diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -118,7 +118,7 @@ #define SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TYPE) \ using FIXTURE##NAME##_##TYPE = FIXTURE##NAME; \ - TEST_F(FIXTURE##NAME##_##TYPE, NAME) { Run(); } + TEST_F(FIXTURE##NAME##_##TYPE, NAME) { FIXTURE##NAME::Run(); } #define SCUDO_TYPED_TEST(FIXTURE, NAME) \ template \ @@ -139,7 +139,7 @@ StackBuffer[I] = 0x42U; EXPECT_FALSE(Allocator->isOwned(&StackBuffer[scudo::Chunk::getHeaderSize()])); for (scudo::uptr I = 0; I < sizeof(StackBuffer); I++) - EXPECT_EQ(StackBuffer[I], 0x42U); + EXPECT_EQ(StackBuffer[I], static_cast(0x42U)); } template @@ -204,7 +204,7 @@ 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(P))[I], 0); + ASSERT_EQ((reinterpret_cast(P))[I], static_cast(0)); memset(P, 0xaa, Size); Allocator->deallocate(P, Origin, Size); } @@ -222,7 +222,7 @@ 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(P))[I], 0); + ASSERT_EQ((reinterpret_cast(P))[I], static_cast(0)); memset(P, 0xaa, Size); Allocator->deallocate(P, Origin, Size); } @@ -592,7 +592,7 @@ V.pop_back(); } } - EXPECT_EQ(FailedAllocationsCount, 0U); + EXPECT_EQ(FailedAllocationsCount, 0UL); } // Ensure that releaseToOS can be called prior to any other allocator @@ -643,7 +643,7 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, DisableMemInit) { auto *Allocator = this->Allocator.get(); - std::vector Ptrs(65536, nullptr); + std::vector Ptrs(65536); Allocator->setOption(scudo::Option::ThreadDisableMemInit, 1); @@ -673,7 +673,7 @@ 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(Ptrs[I]))[J], 0); + ASSERT_EQ((reinterpret_cast(Ptrs[I]))[J], static_cast(0)); } } diff --git a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/common_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/common_test.cpp @@ -61,7 +61,7 @@ EXPECT_EQ(std::count(P, P + N, 0), N); memset(P, 1, Size); - EXPECT_EQ(std::count(P, P + N, 0), 0); + EXPECT_EQ(std::count(P, P + N, 0), 0L); releasePagesToOS((uptr)P, 0, Size, &Data); EXPECT_EQ(std::count(P, P + N, 0), N); diff --git a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/flags_test.cpp @@ -11,8 +11,6 @@ #include "flags.h" #include "flags_parser.h" -#include - static const char FlagName[] = "flag_name"; static const char FlagDesc[] = "flag description"; diff --git a/compiler-rt/lib/scudo/standalone/tests/list_test.cpp b/compiler-rt/lib/scudo/standalone/tests/list_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/list_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/list_test.cpp @@ -73,9 +73,9 @@ ListT L; L.clear(); - EXPECT_EQ(L.size(), 0U); + EXPECT_EQ(L.size(), 0UL); L.push_back(X); - EXPECT_EQ(L.size(), 1U); + EXPECT_EQ(L.size(), 1UL); EXPECT_EQ(L.back(), X); EXPECT_EQ(L.front(), X); L.pop_front(); @@ -83,7 +83,7 @@ L.checkConsistency(); L.push_front(X); - EXPECT_EQ(L.size(), 1U); + EXPECT_EQ(L.size(), 1UL); EXPECT_EQ(L.back(), X); EXPECT_EQ(L.front(), X); L.pop_front(); @@ -93,13 +93,13 @@ L.push_front(X); L.push_front(Y); L.push_front(Z); - EXPECT_EQ(L.size(), 3U); + EXPECT_EQ(L.size(), 3UL); EXPECT_EQ(L.front(), Z); EXPECT_EQ(L.back(), X); L.checkConsistency(); L.pop_front(); - EXPECT_EQ(L.size(), 2U); + EXPECT_EQ(L.size(), 2UL); EXPECT_EQ(L.front(), Y); EXPECT_EQ(L.back(), X); L.pop_front(); @@ -110,13 +110,13 @@ L.push_back(X); L.push_back(Y); L.push_back(Z); - EXPECT_EQ(L.size(), 3U); + EXPECT_EQ(L.size(), 3UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), Z); L.checkConsistency(); L.pop_front(); - EXPECT_EQ(L.size(), 2U); + EXPECT_EQ(L.size(), 2UL); EXPECT_EQ(L.front(), Y); EXPECT_EQ(L.back(), Z); L.pop_front(); @@ -138,12 +138,12 @@ L.push_back(Y); L.push_back(Z); L.extract(X, Y); - EXPECT_EQ(L.size(), 2U); + EXPECT_EQ(L.size(), 2UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), Z); L.checkConsistency(); L.extract(X, Z); - EXPECT_EQ(L.size(), 1U); + EXPECT_EQ(L.size(), 1UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), X); L.checkConsistency(); @@ -173,7 +173,7 @@ L1.append_back(&L2); EXPECT_EQ(L1.back(), X); EXPECT_EQ(L1.front(), X); - EXPECT_EQ(L1.size(), 1U); + EXPECT_EQ(L1.size(), 1UL); } TEST(ScudoListTest, DoublyLinkedList) { @@ -184,12 +184,12 @@ L.push_back(Y); L.push_back(Z); L.remove(Y); - EXPECT_EQ(L.size(), 2U); + EXPECT_EQ(L.size(), 2UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), Z); L.checkConsistency(); L.remove(Z); - EXPECT_EQ(L.size(), 1U); + EXPECT_EQ(L.size(), 1UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), X); L.checkConsistency(); @@ -198,12 +198,12 @@ L.push_back(X); L.insert(Y, X); - EXPECT_EQ(L.size(), 2U); + EXPECT_EQ(L.size(), 2UL); EXPECT_EQ(L.front(), Y); EXPECT_EQ(L.back(), X); L.checkConsistency(); L.remove(Y); - EXPECT_EQ(L.size(), 1U); + EXPECT_EQ(L.size(), 1UL); EXPECT_EQ(L.front(), X); EXPECT_EQ(L.back(), X); L.checkConsistency(); diff --git a/compiler-rt/lib/scudo/standalone/tests/map_test.cpp b/compiler-rt/lib/scudo/standalone/tests/map_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/map_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/map_test.cpp @@ -10,14 +10,13 @@ #include "common.h" -#include #include static const char *MappingName = "scudo:test"; TEST(ScudoMapTest, PageSize) { EXPECT_EQ(scudo::getPageSizeCached(), - static_cast(getpagesize())); + static_cast(sysconf(_SC_PAGESIZE))); } TEST(ScudoMapDeathTest, MapNoAccessUnmap) { diff --git a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/memtag_test.cpp @@ -38,7 +38,7 @@ EXPECT_DEATH(addFixedTag(nullptr, 0), "not supported"); } -class MemtagTest : public ::testing::Test { +class MemtagTest : public Test { protected: void SetUp() override { if (!archSupportsMemoryTagging() || !systemDetectsMemoryTagFaultsTestOnly()) @@ -66,7 +66,7 @@ using MemtagDeathTest = MemtagTest; TEST_F(MemtagTest, ArchMemoryTagGranuleSize) { - EXPECT_GT(archMemoryTagGranuleSize(), 1u); + EXPECT_GT(archMemoryTagGranuleSize(), 1ul); EXPECT_TRUE(isPowerOfTwo(archMemoryTagGranuleSize())); } @@ -76,11 +76,11 @@ // expected range. for (u64 Top = 0; Top < 0x100; ++Top) Tags = Tags | (1u << extractTag(Addr | (Top << 56))); - EXPECT_EQ(0xffffull, Tags); + EXPECT_EQ(0xfffful, Tags); } TEST_F(MemtagDeathTest, AddFixedTag) { - for (uptr Tag = 0; Tag < 0x10; ++Tag) + for (uint8_t Tag = 0; Tag < 0x10; ++Tag) EXPECT_EQ(Tag, extractTag(addFixedTag(Addr, Tag))); if (SCUDO_DEBUG) { EXPECT_DEBUG_DEATH(addFixedTag(Addr, 16), ""); @@ -111,12 +111,12 @@ uptr Tags = 0; for (uptr I = 0; I < 100000; ++I) Tags = Tags | (1u << extractTag(selectRandomTag(Ptr, 0))); - EXPECT_EQ(0xfffeull, Tags); + EXPECT_EQ(0xfffeul, Tags); } } TEST_F(MemtagTest, SelectRandomTagWithMask) { - for (uptr j = 0; j < 32; ++j) { + for (uint8_t j = 0; j < 32; ++j) { for (uptr i = 0; i < 1000; ++i) EXPECT_NE(j, extractTag(selectRandomTag(Addr, 1ull << j))); } diff --git a/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp b/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/mutex_test.cpp @@ -11,7 +11,6 @@ #include "mutex.h" #include -#include class TestData { public: diff --git a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/primary_test.cpp @@ -105,7 +105,7 @@ #define SCUDO_TYPED_TEST_TYPE(FIXTURE, NAME, TYPE) \ using FIXTURE##NAME##_##TYPE = FIXTURE##NAME; \ - TEST_F(FIXTURE##NAME##_##TYPE, NAME) { Run(); } + TEST_F(FIXTURE##NAME##_##TYPE, NAME) { FIXTURE##NAME::Run(); } #define SCUDO_TYPED_TEST(FIXTURE, NAME) \ template \ @@ -207,7 +207,7 @@ V.push_back(std::make_pair(ClassId, P)); } scudo::uptr Found = 0; - auto Lambda = [V, &Found](scudo::uptr Block) { + auto Lambda = [&V, &Found](scudo::uptr Block) { for (const auto &Pair : V) { if (Pair.second == reinterpret_cast(Block)) Found++; @@ -292,5 +292,5 @@ EXPECT_NE(P, nullptr); Cache.deallocate(ClassId, P); Cache.destroy(nullptr); - EXPECT_GT(Allocator->releaseToOS(), 0U); + EXPECT_GT(Allocator->releaseToOS(), 0UL); } diff --git a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/quarantine_test.cpp @@ -42,13 +42,13 @@ Into.merge(&From); - EXPECT_EQ(Into.Count, 2UL); + EXPECT_EQ(Into.Count, 2U); EXPECT_EQ(Into.Batch[0], FakePtr); EXPECT_EQ(Into.Batch[1], FakePtr); EXPECT_EQ(Into.Size, 12UL + sizeof(scudo::QuarantineBatch)); EXPECT_EQ(Into.getQuarantinedSize(), 12UL); - EXPECT_EQ(From.Count, 0UL); + EXPECT_EQ(From.Count, 0U); EXPECT_EQ(From.Size, sizeof(scudo::QuarantineBatch)); EXPECT_EQ(From.getQuarantinedSize(), 0UL); diff --git a/compiler-rt/lib/scudo/standalone/tests/release_test.cpp b/compiler-rt/lib/scudo/standalone/tests/release_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/release_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/release_test.cpp @@ -12,8 +12,6 @@ #include "release.h" #include "size_class_map.h" -#include - #include #include #include diff --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp @@ -153,7 +153,7 @@ const scudo::uptr PageSize = scudo::getPageSizeCached(); for (scudo::uptr I = 0; I < 32U; I++) V.push_back(Allocator->allocate(Options, (std::rand() % 16) * PageSize)); - auto Lambda = [V](scudo::uptr Block) { + auto Lambda = [&V](scudo::uptr Block) { EXPECT_NE(std::find(V.begin(), V.end(), reinterpret_cast(Block)), V.end()); }; diff --git a/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp b/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/stats_test.cpp @@ -14,13 +14,13 @@ scudo::LocalStats LStats; LStats.init(); for (scudo::uptr I = 0; I < scudo::StatCount; I++) - EXPECT_EQ(LStats.get(static_cast(I)), 0U); + EXPECT_EQ(LStats.get(static_cast(I)), 0UL); LStats.add(scudo::StatAllocated, 4096U); - EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096U); + EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096UL); LStats.sub(scudo::StatAllocated, 4096U); - EXPECT_EQ(LStats.get(scudo::StatAllocated), 0U); + EXPECT_EQ(LStats.get(scudo::StatAllocated), 0UL); LStats.set(scudo::StatAllocated, 4096U); - EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096U); + EXPECT_EQ(LStats.get(scudo::StatAllocated), 4096UL); } TEST(ScudoStatsTest, GlobalStats) { @@ -29,18 +29,18 @@ scudo::uptr Counters[scudo::StatCount] = {}; GStats.get(Counters); for (scudo::uptr I = 0; I < scudo::StatCount; I++) - EXPECT_EQ(Counters[I], 0U); + EXPECT_EQ(Counters[I], 0UL); scudo::LocalStats LStats; LStats.init(); GStats.link(&LStats); for (scudo::uptr I = 0; I < scudo::StatCount; I++) - LStats.add(static_cast(I), 4096U); + LStats.add(static_cast(I), 4096UL); GStats.get(Counters); for (scudo::uptr I = 0; I < scudo::StatCount; I++) - EXPECT_EQ(Counters[I], 4096U); + EXPECT_EQ(Counters[I], 4096UL); // Unlinking the local stats move numbers to the global stats. GStats.unlink(&LStats); GStats.get(Counters); for (scudo::uptr I = 0; I < scudo::StatCount; I++) - EXPECT_EQ(Counters[I], 4096U); + EXPECT_EQ(Counters[I], 4096UL); } diff --git a/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp b/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/tsd_test.cpp @@ -230,7 +230,7 @@ T.join(); // The initial number of TSDs we get will be the minimum of the default count // and the number of CPUs. - EXPECT_LE(Pointers.size(), 8U); + EXPECT_LE(Pointers.size(), 8UL); Pointers.clear(); auto Registry = Allocator->getTSDRegistry(); // Increase the number of TSDs to 16. @@ -246,5 +246,5 @@ for (auto &T : Threads) T.join(); // We should get 16 distinct TSDs back. - EXPECT_EQ(Pointers.size(), 16U); + EXPECT_EQ(Pointers.size(), 16UL); } diff --git a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/vector_test.cpp @@ -12,12 +12,12 @@ TEST(ScudoVectorTest, Basic) { scudo::Vector V; - EXPECT_EQ(V.size(), 0U); + EXPECT_EQ(V.size(), 0UL); V.push_back(42); - EXPECT_EQ(V.size(), 1U); + EXPECT_EQ(V.size(), 1UL); EXPECT_EQ(V[0], 42); V.push_back(43); - EXPECT_EQ(V.size(), 2U); + EXPECT_EQ(V.size(), 2UL); EXPECT_EQ(V[0], 42); EXPECT_EQ(V[1], 43); } @@ -26,7 +26,7 @@ scudo::Vector V; for (scudo::uptr I = 0; I < 1000; I++) { V.push_back(I); - EXPECT_EQ(V.size(), I + 1U); + EXPECT_EQ(V.size(), I + 1UL); EXPECT_EQ(V[I], I); } for (scudo::uptr I = 0; I < 1000; I++) @@ -37,7 +37,7 @@ scudo::Vector V; V.push_back(0); V.push_back(0); - EXPECT_EQ(V.size(), 2U); + EXPECT_EQ(V.size(), 2UL); V.resize(1); - EXPECT_EQ(V.size(), 1U); + EXPECT_EQ(V.size(), 1UL); } diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp @@ -46,7 +46,7 @@ void *P = malloc(Size); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); - EXPECT_EQ(reinterpret_cast(P) % FIRST_32_SECOND_64(8U, 16U), 0U); + EXPECT_EQ(reinterpret_cast(P) % FIRST_32_SECOND_64(8U, 16U), 0UL); // An update to this warning in Clang now triggers in this line, but it's ok // because the check is expecting a bad pointer and should fail. @@ -77,7 +77,7 @@ EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); for (size_t I = 0; I < Size; I++) - EXPECT_EQ((reinterpret_cast(P))[I], 0U); + EXPECT_EQ((reinterpret_cast(P))[I], static_cast(0U)); free(P); P = calloc(1U, 0U); @@ -119,14 +119,14 @@ P = memalign(Alignment, Size); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); - EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(reinterpret_cast(P) % Alignment, 0UL); free(P); P = nullptr; EXPECT_EQ(posix_memalign(&P, Alignment, Size), 0); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); - EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(reinterpret_cast(P) % Alignment, 0UL); free(P); } @@ -149,7 +149,7 @@ void *P = aligned_alloc(Alignment, Alignment * 4U); EXPECT_NE(P, nullptr); EXPECT_LE(Alignment * 4U, malloc_usable_size(P)); - EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(reinterpret_cast(P) % Alignment, 0UL); free(P); errno = 0; @@ -178,13 +178,13 @@ EXPECT_NE(P, nullptr); EXPECT_LE(Size * 2U, malloc_usable_size(P)); for (size_t I = 0; I < Size; I++) - EXPECT_EQ(0x42, (reinterpret_cast(P))[I]); + EXPECT_EQ(static_cast(0x42U), (reinterpret_cast(P))[I]); P = realloc(P, Size / 2U); EXPECT_NE(P, nullptr); EXPECT_LE(Size / 2U, malloc_usable_size(P)); for (size_t I = 0; I < Size / 2U; I++) - EXPECT_EQ(0x42, (reinterpret_cast(P))[I]); + EXPECT_EQ(static_cast(0x42U), (reinterpret_cast(P))[I]); free(P); EXPECT_DEATH(P = realloc(P, Size), ""); @@ -205,14 +205,14 @@ P = memalign(Alignment, Size); EXPECT_NE(P, nullptr); EXPECT_LE(Size, malloc_usable_size(P)); - EXPECT_EQ(reinterpret_cast(P) % Alignment, 0U); + EXPECT_EQ(reinterpret_cast(P) % Alignment, 0UL); memset(P, 0x42, Size); P = realloc(P, Size * 2U); EXPECT_NE(P, nullptr); EXPECT_LE(Size * 2U, malloc_usable_size(P)); for (size_t I = 0; I < Size; I++) - EXPECT_EQ(0x42, (reinterpret_cast(P))[I]); + EXPECT_EQ(static_cast(0x42U), (reinterpret_cast(P))[I]); free(P); } } @@ -245,7 +245,7 @@ void *P = pvalloc(Size); EXPECT_NE(P, nullptr); - EXPECT_EQ(reinterpret_cast(P) & (PageSize - 1), 0U); + EXPECT_EQ(reinterpret_cast(P) & (PageSize - 1), 0UL); EXPECT_LE(PageSize, malloc_usable_size(P)); free(P); @@ -253,7 +253,7 @@ P = pvalloc(Size); EXPECT_NE(P, nullptr); - EXPECT_EQ(reinterpret_cast(P) & (PageSize - 1), 0U); + EXPECT_EQ(reinterpret_cast(P) & (PageSize - 1), 0UL); free(P); #endif diff --git a/compiler-rt/lib/scudo/standalone/tsd_exclusive.h b/compiler-rt/lib/scudo/standalone/tsd_exclusive.h --- a/compiler-rt/lib/scudo/standalone/tsd_exclusive.h +++ b/compiler-rt/lib/scudo/standalone/tsd_exclusive.h @@ -15,7 +15,7 @@ struct ThreadState { bool DisableMemInit : 1; - enum { + enum : unsigned { NotInitialized = 0, Initialized, TornDown, @@ -87,7 +87,7 @@ Mutex.unlock(); } - bool setOption(Option O, UNUSED sptr Value) { + bool setOption(Option O, sptr Value) { if (O == Option::ThreadDisableMemInit) State.DisableMemInit = Value; if (O == Option::MaxTSDsCount) diff --git a/compiler-rt/lib/scudo/standalone/vector.h b/compiler-rt/lib/scudo/standalone/vector.h --- a/compiler-rt/lib/scudo/standalone/vector.h +++ b/compiler-rt/lib/scudo/standalone/vector.h @@ -11,8 +11,6 @@ #include "common.h" -#include - namespace scudo { // A low-level vector based on map. May incur a significant memory overhead for diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.h b/compiler-rt/lib/scudo/standalone/wrappers_c.h --- a/compiler-rt/lib/scudo/standalone/wrappers_c.h +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.h @@ -19,6 +19,9 @@ typedef int __scudo_mallinfo_data_t; #endif +extern "C" void malloc_postinit(); +extern scudo::Allocator Allocator; + struct __scudo_mallinfo { __scudo_mallinfo_data_t arena; __scudo_mallinfo_data_t ordblks; diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c_checks.h b/compiler-rt/lib/scudo/standalone/wrappers_c_checks.h --- a/compiler-rt/lib/scudo/standalone/wrappers_c_checks.h +++ b/compiler-rt/lib/scudo/standalone/wrappers_c_checks.h @@ -45,19 +45,32 @@ // Returns true if calloc(Size, N) overflows on Size*N calculation. Use a // builtin supported by recent clang & GCC if it exists, otherwise fallback to a // costly division. -inline bool checkForCallocOverflow(uptr Size, uptr N, uptr *Product) { -#if __has_builtin(__builtin_umull_overflow) && (SCUDO_WORDSIZE == 64U) - return __builtin_umull_overflow(Size, N, Product); -#elif __has_builtin(__builtin_umul_overflow) && (SCUDO_WORDSIZE == 32U) - return __builtin_umul_overflow(Size, N, Product); -#else +template +inline bool checkForCallocOverflow(T Size, T N, T *Product) { *Product = Size * N; if (!Size) return false; return (*Product / Size) != N; -#endif } +#if __has_builtin(__builtin_umull_overflow) +template <> +inline bool checkForCallocOverflow(unsigned long Size, + unsigned long N, + unsigned long *Product) { + return __builtin_umull_overflow(Size, N, Product); +} +#endif + +#if __has_builtin(__builtin_umul_overflow) +template <> +inline bool checkForCallocOverflow(unsigned int Size, + unsigned int N, + unsigned int *Product) { + return __builtin_umul_overflow(Size, N, Product); +} +#endif + // Returns true if the size passed to pvalloc overflows when rounded to the next // multiple of PageSize. inline bool checkForPvallocOverflow(uptr Size, uptr PageSize) {