[compiler-rt] 4d819da - [compiler-rt] Simplify definition of uptr
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 10:58:42 PDT 2024
Author: Alexander Richardson
Date: 2024-09-05T10:58:37-07:00
New Revision: 4d819daab91f54b90365927ba4b40e5a2eff26a9
URL: https://github.com/llvm/llvm-project/commit/4d819daab91f54b90365927ba4b40e5a2eff26a9
DIFF: https://github.com/llvm/llvm-project/commit/4d819daab91f54b90365927ba4b40e5a2eff26a9.diff
LOG: [compiler-rt] Simplify definition of uptr
We can rely on the compiler-provided macro __UINTPTR_TYPE__ for all
non-MSVC compilers. 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
all supported compilers.
This means we no longer need to explicitly handle new architectures
and as an added bonus also adds support for architectures where
`unsigned long long` cannot be used to hold pointers (e.g. CHERI).
Reviewed By: mstorsjo, vitalybuka
Pull Request: https://github.com/llvm/llvm-project/pull/106155
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index fefe28e811767d..f8f03454ea169a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -138,19 +138,19 @@
// in a portable way by the language itself.
namespace __sanitizer {
-#if defined(_WIN64)
+#if defined(__UINTPTR_TYPE__)
+typedef __UINTPTR_TYPE__ uptr;
+typedef __INTPTR_TYPE__ sptr;
+#elif defined(_WIN64)
// 64-bit Windows uses LLP64 data model.
typedef unsigned long long uptr;
typedef signed long long sptr;
-#else
-# if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE
-typedef unsigned long uptr;
-typedef signed long sptr;
-# else
+#elif defined(_WIN32)
typedef unsigned int uptr;
typedef signed int sptr;
-# endif
-#endif // defined(_WIN64)
+#else
+# error Unsupported compiler, missing __UINTPTR_TYPE__
+#endif // defined(__UINTPTR_TYPE__)
#if defined(__x86_64__)
// Since x32 uses ILP32 data model in 64-bit hardware mode, we must use
// 64-bit pointer to unwind stack frame.
More information about the llvm-commits
mailing list