[compiler-rt] [scudo] Fix type mismatch on DefaultMaxEntrySize (PR #85897)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 23:11:24 PDT 2024


https://github.com/ChiaHungDuan created https://github.com/llvm/llvm-project/pull/85897

None

>From c654646d5afa953305cd683e45bd6161d5189f65 Mon Sep 17 00:00:00 2001
From: Chia-hung Duan <chiahungduan at google.com>
Date: Wed, 20 Mar 2024 06:05:42 +0000
Subject: [PATCH] [scudo] Fix type mismatch on DefaultMaxEntrySize

---
 .../lib/scudo/standalone/allocator_config.def    |  2 +-
 .../scudo/standalone/allocator_config_wrapper.h  | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.def b/compiler-rt/lib/scudo/standalone/allocator_config.def
index 92f4e39872d4c9..c50aadad2d637a 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config.def
+++ b/compiler-rt/lib/scudo/standalone/allocator_config.def
@@ -110,7 +110,7 @@ SECONDARY_REQUIRED_TEMPLATE_TYPE(CacheT)
 SECONDARY_CACHE_OPTIONAL(const u32, EntriesArraySize, 0)
 SECONDARY_CACHE_OPTIONAL(const u32, QuarantineSize, 0)
 SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntriesCount, 0)
-SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntrySize, 0)
+SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxEntrySize, 0)
 SECONDARY_CACHE_OPTIONAL(const s32, MinReleaseToOsIntervalMs, INT32_MIN)
 SECONDARY_CACHE_OPTIONAL(const s32, MaxReleaseToOsIntervalMs, INT32_MAX)
 
diff --git a/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h b/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
index a51d770b466466..5477236ac1f397 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h
@@ -27,6 +27,19 @@ template <typename T> struct voidAdaptor {
   using type = void;
 };
 
+// This is used for detecting the case that defines the flag with wrong type and
+// it'll be viewed as undefined optional flag.
+template <typename L, typename R> struct assertSameType {
+  template <typename, typename> struct isSame {
+    static constexpr bool value = false;
+  };
+  template <typename T> struct isSame<T, T> {
+    static constexpr bool value = true;
+  };
+  static_assert(isSame<L, R>::value, "Flag type mismatches");
+  using type = R;
+};
+
 } // namespace
 
 namespace scudo {
@@ -36,7 +49,8 @@ namespace scudo {
     static constexpr removeConst<TYPE>::type getValue() { return DEFAULT; }    \
   };                                                                           \
   template <typename Config>                                                   \
-  struct NAME##State<Config, decltype(Config::MEMBER)> {                       \
+  struct NAME##State<                                                          \
+      Config, typename assertSameType<decltype(Config::MEMBER), TYPE>::type> { \
     static constexpr removeConst<TYPE>::type getValue() {                      \
       return Config::MEMBER;                                                   \
     }                                                                          \



More information about the llvm-commits mailing list