-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add builtin_unreachable to the FW_ASSERT macros #5228
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
base: devel
Are you sure you want to change the base?
Changes from all commits
d04aae0
2ec0abb
469d891
f293c95
1468516
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,35 @@ | |||||||||||||||||||||||||||||||||||||||||||
| // Return all the arguments of the macro, but the first one | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT_NO_FIRST_ARG(ARG_0, ...) __VA_ARGS__ | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // Define FW_UNREACHABLE to hint to the compiler that a code path is unreachable. | ||||||||||||||||||||||||||||||||||||||||||||
| // Falls back to a no-op on compilers that do not support __builtin_unreachable. | ||||||||||||||||||||||||||||||||||||||||||||
| // (1) __has_builtin — the modern check, available in Clang and GCC >= 10. | ||||||||||||||||||||||||||||||||||||||||||||
| // (2) defined(__GNUC__) — catches older GCC (4.5–9) which lack __has_builtin | ||||||||||||||||||||||||||||||||||||||||||||
| #ifndef FW_UNREACHABLE | ||||||||||||||||||||||||||||||||||||||||||||
| #ifdef __has_builtin | ||||||||||||||||||||||||||||||||||||||||||||
| #if __has_builtin(__builtin_unreachable) | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_UNREACHABLE() __builtin_unreachable() | ||||||||||||||||||||||||||||||||||||||||||||
|
thomas-bc marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+19
Collaborator
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 Copilot review correctly identified that this branch can redefine a user-provided
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
| #ifndef FW_UNREACHABLE | ||||||||||||||||||||||||||||||||||||||||||||
| #if defined(__GNUC__) | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_UNREACHABLE() __builtin_unreachable() | ||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_UNREACHABLE() ((void)0) // no-op fallback for unknown compilers | ||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| // FW_ASSERT_UNREACHABLE is the hint used inside FW_ASSERT macros. | ||||||||||||||||||||||||||||||||||||||||||||
| // Only active when FW_ASSERTIONS_ALWAYS_ABORT is enabled, because SwAssert | ||||||||||||||||||||||||||||||||||||||||||||
| // can legally return when it is disabled (the default). Using __builtin_unreachable | ||||||||||||||||||||||||||||||||||||||||||||
| // after a call that returns is undefined behavior. | ||||||||||||||||||||||||||||||||||||||||||||
| #if FW_ASSERTIONS_ALWAYS_ABORT | ||||||||||||||||||||||||||||||||||||||||||||
|
thomas-bc marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT_UNREACHABLE() FW_UNREACHABLE() | ||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT_UNREACHABLE() ((void)0) | ||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| #if FW_ASSERT_LEVEL == FW_NO_ASSERT | ||||||||||||||||||||||||||||||||||||||||||||
| // Users may override the NO_ASSERT case should they choose | ||||||||||||||||||||||||||||||||||||||||||||
| #ifndef FW_ASSERT | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,24 +52,27 @@ | |||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(ASSERT_FILE_ID, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))) | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(ASSERT_FILE_ID, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)), FW_ASSERT_UNREACHABLE())) | ||||||||||||||||||||||||||||||||||||||||||||
| #elif FW_ASSERT_LEVEL == FW_FILEID_ASSERT && !defined ASSERT_FILE_ID | ||||||||||||||||||||||||||||||||||||||||||||
| #define FILE_NAME_ARG U32 | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(static_cast<U32>(0), FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))) | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(static_cast<U32>(0), FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)), \ | ||||||||||||||||||||||||||||||||||||||||||||
| FW_ASSERT_UNREACHABLE())) | ||||||||||||||||||||||||||||||||||||||||||||
| #elif FW_ASSERT_LEVEL == FW_RELATIVE_PATH_ASSERT && defined ASSERT_RELATIVE_PATH | ||||||||||||||||||||||||||||||||||||||||||||
| #define FILE_NAME_ARG const CHAR* | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(ASSERT_RELATIVE_PATH, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)), \ | ||||||||||||||||||||||||||||||||||||||||||||
| FW_ASSERT_UNREACHABLE())) | ||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||
| #define FILE_NAME_ARG const CHAR* | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(ASSERT_RELATIVE_PATH, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))) | ||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||
| #define FILE_NAME_ARG const CHAR* | ||||||||||||||||||||||||||||||||||||||||||||
| #define FW_ASSERT(...) \ | ||||||||||||||||||||||||||||||||||||||||||||
| ((FW_ASSERT_FIRST_ARG(__VA_ARGS__, 0)) ? ((void)0) \ | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(__FILE__, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)))) | ||||||||||||||||||||||||||||||||||||||||||||
| : (Fw::SwAssert(__FILE__, FW_ASSERT_NO_FIRST_ARG(__VA_ARGS__, __LINE__)), FW_ASSERT_UNREACHABLE())) | ||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||
| #endif // if ASSERT is defined | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.