[compiler-rt] 867f2d9 - [scudo] Make Options a reference for functions.
Christopher Ferris via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 18:21:52 PDT 2023
Author: Christopher Ferris
Date: 2023-07-26T18:21:39-07:00
New Revision: 867f2d9e5c9a736eb97fe5a51aa2850abfd02a96
URL: https://github.com/llvm/llvm-project/commit/867f2d9e5c9a736eb97fe5a51aa2850abfd02a96
DIFF: https://github.com/llvm/llvm-project/commit/867f2d9e5c9a736eb97fe5a51aa2850abfd02a96.diff
LOG: [scudo] Make Options a reference for functions.
Modify all places that use the Options structure to be a const
reference. The underlying structure is a u32 so making it a
reference doesn't really do anything. However, if the structure
changes in the future it already works and avoids future coders
wondering why a structure is being passed by value. This also
makes it clear that the Options should not be modified in those functions.
Reviewed By: Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D156372
Added:
Modified:
compiler-rt/lib/scudo/standalone/combined.h
compiler-rt/lib/scudo/standalone/options.h
compiler-rt/lib/scudo/standalone/secondary.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index b17acc71f89205..b97bcc9fdbc8c7 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -299,7 +299,7 @@ class Allocator {
#endif
}
- uptr computeOddEvenMaskForPointerMaybe(Options Options, uptr Ptr,
+ uptr computeOddEvenMaskForPointerMaybe(const Options &Options, uptr Ptr,
uptr ClassId) {
if (!Options.get(OptionBit::UseOddEvenTags))
return 0;
@@ -1134,7 +1134,7 @@ class Allocator {
reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
}
- void quarantineOrDeallocateChunk(Options Options, void *TaggedPtr,
+ void quarantineOrDeallocateChunk(const Options &Options, void *TaggedPtr,
Chunk::UnpackedHeader *Header,
uptr Size) NO_THREAD_SAFETY_ANALYSIS {
void *Ptr = getHeaderTaggedPointer(TaggedPtr);
@@ -1273,7 +1273,7 @@ class Allocator {
storeEndMarker(RoundNewPtr, NewSize, BlockEnd);
}
- void storePrimaryAllocationStackMaybe(Options Options, void *Ptr) {
+ void storePrimaryAllocationStackMaybe(const Options &Options, void *Ptr) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;
auto *Ptr32 = reinterpret_cast<u32 *>(Ptr);
@@ -1305,7 +1305,7 @@ class Allocator {
atomic_store_relaxed(&Entry->Ptr, reinterpret_cast<uptr>(Ptr));
}
- void storeSecondaryAllocationStackMaybe(Options Options, void *Ptr,
+ void storeSecondaryAllocationStackMaybe(const Options &Options, void *Ptr,
uptr Size) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;
@@ -1320,8 +1320,8 @@ class Allocator {
storeRingBufferEntry(untagPointer(Ptr), Trace, Tid, Size, 0, 0);
}
- void storeDeallocationStackMaybe(Options Options, void *Ptr, u8 PrevTag,
- uptr Size) {
+ void storeDeallocationStackMaybe(const Options &Options, void *Ptr,
+ u8 PrevTag, uptr Size) {
if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
return;
diff --git a/compiler-rt/lib/scudo/standalone/options.h b/compiler-rt/lib/scudo/standalone/options.h
index 4e678651333467..b20142a415903d 100644
--- a/compiler-rt/lib/scudo/standalone/options.h
+++ b/compiler-rt/lib/scudo/standalone/options.h
@@ -38,7 +38,7 @@ struct Options {
}
};
-template <typename Config> bool useMemoryTagging(Options Options) {
+template <typename Config> bool useMemoryTagging(const Options &Options) {
return allocatorSupportsMemoryTagging<Config>() &&
Options.get(OptionBit::UseMemoryTagging);
}
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index 99b486c16b036b..407ee2726b2b50 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -90,7 +90,7 @@ template <typename Config> class MapAllocatorNoCache {
public:
void init(UNUSED s32 ReleaseToOsInterval) {}
bool retrieve(UNUSED uptr Size, UNUSED CachedBlock &Entry) { return false; }
- void store(UNUSED Options Options, LargeBlock::Header *H) { unmap(H); }
+ void store(UNUSED const Options &Options, LargeBlock::Header *H) { unmap(H); }
bool canCache(UNUSED uptr Size) { return false; }
void disable() {}
void enable() {}
@@ -113,7 +113,7 @@ template <typename Config> class MapAllocatorNoCache {
static const uptr MaxUnusedCachePages = 4U;
template <typename Config>
-bool mapSecondary(Options Options, uptr CommitBase, uptr CommitSize,
+bool mapSecondary(const Options &Options, uptr CommitBase, uptr CommitSize,
uptr AllocPos, uptr Flags, MemMapT &MemMap) {
Flags |= MAP_RESIZABLE;
Flags |= MAP_ALLOWNOMEM;
@@ -179,7 +179,7 @@ template <typename Config> class MapAllocatorCache {
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
}
- void store(Options Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
+ void store(const Options &Options, LargeBlock::Header *H) EXCLUDES(Mutex) {
if (!canCache(H->CommitSize))
return unmap(H);
@@ -407,11 +407,11 @@ template <typename Config> class MapAllocator {
S->link(&Stats);
}
- void *allocate(Options Options, uptr Size, uptr AlignmentHint = 0,
+ void *allocate(const Options &Options, uptr Size, uptr AlignmentHint = 0,
uptr *BlockEnd = nullptr,
FillContentsMode FillContents = NoFill);
- void deallocate(Options Options, void *Ptr);
+ void deallocate(const Options &Options, void *Ptr);
static uptr getBlockEnd(void *Ptr) {
auto *B = LargeBlock::getHeader<Config>(Ptr);
@@ -443,7 +443,7 @@ template <typename Config> class MapAllocator {
}
}
- inline void setHeader(Options Options, CachedBlock &Entry,
+ inline void setHeader(const Options &Options, CachedBlock &Entry,
LargeBlock::Header *H, bool &Zeroed) {
Zeroed = Entry.Time == 0;
if (useMemoryTagging<Config>(Options)) {
@@ -501,8 +501,8 @@ template <typename Config> class MapAllocator {
// the committed memory will amount to something close to Size - AlignmentHint
// (pending rounding and headers).
template <typename Config>
-void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
- uptr *BlockEndPtr,
+void *MapAllocator<Config>::allocate(const Options &Options, uptr Size,
+ uptr Alignment, uptr *BlockEndPtr,
FillContentsMode FillContents) {
if (Options.get(OptionBit::AddLargeAllocationSlack))
Size += 1UL << SCUDO_MIN_ALIGNMENT_LOG;
@@ -620,7 +620,7 @@ void *MapAllocator<Config>::allocate(Options Options, uptr Size, uptr Alignment,
}
template <typename Config>
-void MapAllocator<Config>::deallocate(Options Options, void *Ptr)
+void MapAllocator<Config>::deallocate(const Options &Options, void *Ptr)
EXCLUDES(Mutex) {
LargeBlock::Header *H = LargeBlock::getHeader<Config>(Ptr);
const uptr CommitSize = H->CommitSize;
More information about the llvm-commits
mailing list