Skip to content

Commit

Permalink
[compiler-rt] Simplify and rename of operator_new_size_type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
arichardson committed Mar 9, 2024
1 parent 0b9ce71 commit c58c827
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ inline u32 GetNumberOfCPUsCached() {

} // namespace __sanitizer

inline void *operator new(__sanitizer::operator_new_size_type size,
inline void *operator new(__sanitizer::usize size,
__sanitizer::LowLevelAllocator &alloc) {
return alloc.Allocate(size);
}
Expand Down
11 changes: 3 additions & 8 deletions compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,10 @@ typedef uptr OFF_T;
#endif
typedef u64 OFF64_T;

#if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE
typedef uptr operator_new_size_type;
#ifdef __SIZE_TYPE__
typedef __SIZE_TYPE__ usize;
#else
# if defined(__s390__) && !defined(__s390x__)
// Special case: 31-bit s390 has unsigned long as size_t.
typedef unsigned long operator_new_size_type;
# else
typedef u32 operator_new_size_type;
# endif
typedef uptr usize;
#endif

typedef u64 tid_t;
Expand Down
4 changes: 1 addition & 3 deletions compiler-rt/lib/sanitizer_common/sanitizer_placement_new.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#include "sanitizer_internal_defs.h"

inline void *operator new(__sanitizer::operator_new_size_type sz, void *p) {
return p;
}
inline void *operator new(__sanitizer::usize sz, void *p) { return p; }

#endif // SANITIZER_PLACEMENT_NEW_H

0 comments on commit c58c827

Please sign in to comment.