Skip to content

Commit c58c827

Browse files
authored
[compiler-rt] Simplify and rename of operator_new_size_type
We can rely on the compiler-provided macro __SIZE_TYPE__ for all non-MSVC compilers and fall back to `uptr` otherwise. I verified via https://godbolt.org/z/MW9KMjv5f that this works for MSVC as well as GCC 4.5 Clang 3.0, so that should cover supported compilers. While touching this also rename operator_new_size_type to usize which makes it more obvious that this is the equivalent to size_t within the sanitizers runtime (which I plan to use in follow-up changes). Reviewed By: vitalybuka Pull Request: #83912
1 parent 0b9ce71 commit c58c827

File tree

3 files changed

+5
-12
lines changed

3 files changed

+5
-12
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ inline u32 GetNumberOfCPUsCached() {
10981098

10991099
} // namespace __sanitizer
11001100

1101-
inline void *operator new(__sanitizer::operator_new_size_type size,
1101+
inline void *operator new(__sanitizer::usize size,
11021102
__sanitizer::LowLevelAllocator &alloc) {
11031103
return alloc.Allocate(size);
11041104
}

compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,10 @@ typedef uptr OFF_T;
191191
#endif
192192
typedef u64 OFF64_T;
193193

194-
#if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE
195-
typedef uptr operator_new_size_type;
194+
#ifdef __SIZE_TYPE__
195+
typedef __SIZE_TYPE__ usize;
196196
#else
197-
# if defined(__s390__) && !defined(__s390x__)
198-
// Special case: 31-bit s390 has unsigned long as size_t.
199-
typedef unsigned long operator_new_size_type;
200-
# else
201-
typedef u32 operator_new_size_type;
202-
# endif
197+
typedef uptr usize;
203198
#endif
204199

205200
typedef u64 tid_t;

compiler-rt/lib/sanitizer_common/sanitizer_placement_new.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
#include "sanitizer_internal_defs.h"
1919

20-
inline void *operator new(__sanitizer::operator_new_size_type sz, void *p) {
21-
return p;
22-
}
20+
inline void *operator new(__sanitizer::usize sz, void *p) { return p; }
2321

2422
#endif // SANITIZER_PLACEMENT_NEW_H

0 commit comments

Comments
 (0)