-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
add @trap builtin
#14782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add @trap builtin
#14782
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -180,10 +180,16 @@ typedef char bool; | |||||
| #define zig_export(sig, symbol, name) __asm(name " = " symbol) | ||||||
| #endif | ||||||
|
|
||||||
| #if zig_has_builtin(trap) | ||||||
| #define zig_trap() __builtin_trap() | ||||||
| #elif defined(__i386__) || defined(__x86_64__) | ||||||
| #define zig_trap() __asm__ volatile("ud2"); | ||||||
| #else | ||||||
| #define zig_trap() raise(SIGILL) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The references I quoted and linked in this comment might be of interest.
(they talk about debuggers in SIGTRAP so this is used for and then SIGILL (used for
I know the signal names themselves make this seem like an odd choice but that's why I did it this way. |
||||||
| #endif | ||||||
|
|
||||||
| #if zig_has_builtin(debugtrap) | ||||||
| #define zig_breakpoint() __builtin_debugtrap() | ||||||
| #elif zig_has_builtin(trap) || defined(zig_gnuc) | ||||||
| #define zig_breakpoint() __builtin_trap() | ||||||
| #elif defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) | ||||||
| #define zig_breakpoint() __debugbreak() | ||||||
| #elif defined(__i386__) || defined(__x86_64__) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't think it does? I didn't check for that but I'm guessing it has or should have the same behavior as
@breakpointin that regard:So I don't know if that should be a compile error, but maybe because it returns
noreturninstead ofvoid. So, should it not be valid withintestscope either? Not sure.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my suggested docs are correct; the compiler is wrong :-)