Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/gpgmm/utils/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@
#else
# if defined(GPGMM_COMPILER_MSVC)
# define GPGMM_ASSERT_CALLSITE_HELPER(file, func, line, condition) __assume(condition)
# elif defined(GPGMM_COMPILER_CLANG) && defined(__builtin_assume)
# elif defined(GPGMM_COMPILER_CLANG) && GPGMM_HAS_BUILTIN(__builtin_unreachable)
// Avoid using __builtin_assume since it results into clang assuming _every_ function call has a
// side effect. Alternatively, suppress these warnings with -Wno-assume or wrap _builtin_assume in
// pragmas. Since the generated code below is equivelent, replacing with __builtin_unreachable is
// used.
# define GPGMM_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
__builtin_assume(condition)
do { \
if (!(condition)) { \
GPGMM_BUILTIN_UNREACHABLE(); \
} \
} while (GPGMM_ASSERT_LOOP_CONDITION)
# else
# define GPGMM_ASSERT_CALLSITE_HELPER(file, func, line, condition) \
do { \
Expand Down
8 changes: 8 additions & 0 deletions src/gpgmm/utils/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ extern void __cdecl __debugbreak(void);
# error "Unsupported compiler"
#endif

// Non-compiler specific language extensions
#if defined(__has_builtin)
# define GPGMM_HAS_BUILTIN __has_builtin
#endif

// It seems that (void) EXPR works on all compilers to silence the unused variable warning.
#define GPGMM_UNUSED(EXPR) (void)EXPR
// Likewise using static asserting on sizeof(&FUNC) seems to make it tagged as used
Expand All @@ -98,6 +103,9 @@ extern void __cdecl __debugbreak(void);
#if !defined(GPGMM_FORCE_INLINE)
# define GPGMM_FORCE_INLINE inline
#endif
#if !defined(GPGMM_HAS_BUILTIN)
# define GPGMM_HAS_BUILTIN(X) 0
#endif

#if defined(__clang__)
# define GPGMM_FALLTHROUGH [[clang::fallthrough]]
Expand Down