summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-12-27 22:24:53 -0500
committerWormHeamer2025-12-27 22:25:03 -0500
commit51781c481efc56dd06cbfe75c356b3aae600f0bc (patch)
treeee76e0bb0a567ab07111cce14a758566d902660e
parente3aa8a3cd8a277fd6d9fb9bcc6a9b4bf2d94e9d3 (diff)
better TRAP() implementation
-rw-r--r--wrmr.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/wrmr.h b/wrmr.h
index 2a86040..67523ec 100644
--- a/wrmr.h
+++ b/wrmr.h
@@ -31,9 +31,12 @@ typedef uintptr_t uptr;
#define HAS_BUILTIN(x) 0
#endif
-#if HAS_BUILTIN(__builtin_debugtrap)
+#if defined(__i368__) || defined(__x86_64__)
+/* nop so gdb will break on the trap, not the line after */
+# define TRAP() __asm__ volatile ("int3; nop")
+#elif HAS_BUILTIN(__builtin_debugtrap)
# define TRAP() __builtin_debugtrap()
-#elif HAS_BUILTIN(__builtin_trap)
+#elif HAS_BUILTIN(__builtin_trap) && defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0)
# define TRAP() __builtin_trap()
#elif defined(_MSC_VER)
# define TRAP() __debugbreak()
@@ -62,7 +65,7 @@ typedef uintptr_t uptr;
#else
# if __STDC_VERSION__ >= 202311L
# define UNREACHABLE_MSG(msg) (unreachable())
-# elif HAVE_BUILTIN(__builtin_unreachable)
+# elif HAS_BUILTIN(__builtin_unreachable)
# define UNREACHABLE_MSG(msg) (__builtin_unreachable())
# elif defined(_MSC_VER)
# define UNREACHABLE_MSG(msg) (__assume(0))
@@ -76,7 +79,7 @@ typedef uintptr_t uptr;
#ifdef NDEBUG
# if defined(_MSC_VER)
# define ASSUME(...) (__assume(__VA_ARGS__))
-# elif HAVE_BUILTIN(__builtin_assume)
+# elif HAS_BUILTIN(__builtin_assume)
# define ASSUME(...) (__builtin_assume(__VA_ARGS__))
# endif
#else