[compiler-rt] [compiler-rt] Simplify definition of uptr (PR #106155)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 15:41:55 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Alexander Richardson (arichardson)
<details>
<summary>Changes</summary>
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).
Fixes: https://github.com/llvm/llvm-project/issues/101998
---
Full diff: https://github.com/llvm/llvm-project/pull/106155.diff
1 Files Affected:
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h (+8-8)
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index 3af47c2e2ff7a7..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 || SANITIZER_WINDOWS
-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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/106155
More information about the llvm-commits
mailing list