You use defined(__APPLE__) to decide whether to use __builtin_debugtrap but that's wrong, because only Clang supports that built-in, but GCC defines __APPLE__ too.
The minimal fix would be to just check defined(__clang__) instead of defined(__APPLE__).
I don't see any reason to restrict the use of __builtin_debugtrap() to aarch64 on macOS, you could use it on all platforms when compiling with Clang. For x86 it expands to int 3 which is what your own code does. For ARM it expands to .inst 0xe7f001f0 which is the same as your code again.
To use __builtin_debugtrap() whenever the compiler supports it, you can do something like:
#ifdef __has_builtin
# if __has_builtin(__builtin_debugtrap)
# define DEBUG_BREAK_IMPL DEBUG_BREAK_USE_BUILTIN_DEBUGTRAP
# endif
#endif
#ifndef DEBUG_BREAK_IMPL
// ... existing code ...
#endif
You use
defined(__APPLE__)to decide whether to use__builtin_debugtrapbut that's wrong, because only Clang supports that built-in, but GCC defines__APPLE__too.The minimal fix would be to just check
defined(__clang__)instead ofdefined(__APPLE__).I don't see any reason to restrict the use of
__builtin_debugtrap()to aarch64 on macOS, you could use it on all platforms when compiling with Clang. For x86 it expands toint 3which is what your own code does. For ARM it expands to.inst 0xe7f001f0which is the same as your code again.To use
__builtin_debugtrap()whenever the compiler supports it, you can do something like: