Skip to content

Commit 4d819da

Browse files
authored
[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: #106155
1 parent 797f011 commit 4d819da

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@
138138
// in a portable way by the language itself.
139139
namespace __sanitizer {
140140

141-
#if defined(_WIN64)
141+
#if defined(__UINTPTR_TYPE__)
142+
typedef __UINTPTR_TYPE__ uptr;
143+
typedef __INTPTR_TYPE__ sptr;
144+
#elif defined(_WIN64)
142145
// 64-bit Windows uses LLP64 data model.
143146
typedef unsigned long long uptr;
144147
typedef signed long long sptr;
145-
#else
146-
# if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE
147-
typedef unsigned long uptr;
148-
typedef signed long sptr;
149-
# else
148+
#elif defined(_WIN32)
150149
typedef unsigned int uptr;
151150
typedef signed int sptr;
152-
# endif
153-
#endif // defined(_WIN64)
151+
#else
152+
# error Unsupported compiler, missing __UINTPTR_TYPE__
153+
#endif // defined(__UINTPTR_TYPE__)
154154
#if defined(__x86_64__)
155155
// Since x32 uses ILP32 data model in 64-bit hardware mode, we must use
156156
// 64-bit pointer to unwind stack frame.

0 commit comments

Comments
 (0)