osdep/compiler: add MP_CKD_MUL
Add a new MP_CKD_MUL macro which does a multiplication with overflow checking, backed by either the C23 ckd_mul standard function, or the GCC/Clang __builtin_mul_overflow otherwise.
This commit is contained in:
1 parent
ae99e39239
commit
8c6ad1b002
1 file changed
+7
@@ -7,6 +7,7 @@
|
||||
#define MP_EXPAND_ARGS(...) __VA_ARGS__
|
||||
|
||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
|
||||
#include <stdckdint.h>
|
||||
#define MP_NORETURN [[noreturn]]
|
||||
#define MP_FALLTHROUGH [[fallthrough]]
|
||||
#define MP_WARN_UNUSED_RESULT [[nodiscard]]
|
||||
@@ -84,4 +85,10 @@
|
||||
#define MP_SCANF_ATTRIBUTE(a1, a2)
|
||||
#endif
|
||||
|
||||
#if defined(__STDC_VERSION_STDCKDINT_H__) && __STDC_VERSION_STDCKDINT_H__ >= 202311L
|
||||
#define MP_CKD_MUL(result, a, b) ckd_mul(result, a, b)
|
||||
#elif __has_builtin(__builtin_mul_overflow)
|
||||
#define MP_CKD_MUL(result, a, b) __builtin_mul_overflow(a, b, result)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user