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

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 08:15:52 PDT 2024


Author: ChiaHungDuan
Date: 2024-03-20T08:15:47-07:00
New Revision: aa8cffb9583afb583b7a329a56cbd1c7b743f6a3

URL: https://github.com/llvm/llvm-project/commit/aa8cffb9583afb583b7a329a56cbd1c7b743f6a3
DIFF: https://github.com/llvm/llvm-project/commit/aa8cffb9583afb583b7a329a56cbd1c7b743f6a3.diff

LOG: [scudo] Fix type mismatch on DefaultMaxEntrySize (#85897)

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/allocator_config.def
    compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h

Removed: 
    


################################################################################
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