mdbx: add and use MDBX_NOSANITIZE_ENUM macro.

This commit is contained in:
Leonid Yuriev 2021-08-14 16:02:33 +03:00
parent e20664fe55
commit 68273acc2a
2 changed files with 28 additions and 9 deletions

View File

@ -1115,6 +1115,7 @@ nordahead
NOREPLACE NOREPLACE
NORESERVE NORESERVE
noreturn noreturn
NOSANITIZE
nospill nospill
nosubdir nosubdir
nosync nosync

36
mdbx.h
View File

@ -473,6 +473,12 @@ typedef mode_t mdbx_mode_t;
#define MDBX_MAYBE_UNUSED #define MDBX_MAYBE_UNUSED
#endif /* MDBX_MAYBE_UNUSED */ #endif /* MDBX_MAYBE_UNUSED */
#if __has_attribute(no_sanitize)
#define MDBX_NOSANITIZE_ENUM __attribute((__no_sanitize__("enum")))
#else
#define MDBX_NOSANITIZE_ENUM
#endif /* MDBX_NOSANITIZE_ENUM */
/* Oh, below are some songs and dances since: /* Oh, below are some songs and dances since:
* - C++ requires explicit definition of the necessary operators. * - C++ requires explicit definition of the necessary operators.
* - the proper implementation of DEFINE_ENUM_FLAG_OPERATORS for C++ required * - the proper implementation of DEFINE_ENUM_FLAG_OPERATORS for C++ required
@ -498,28 +504,40 @@ typedef mode_t mdbx_mode_t;
/// used to define flags (based on Microsoft's DEFINE_ENUM_FLAG_OPERATORS). /// used to define flags (based on Microsoft's DEFINE_ENUM_FLAG_OPERATORS).
#define DEFINE_ENUM_FLAG_OPERATORS(ENUM) \ #define DEFINE_ENUM_FLAG_OPERATORS(ENUM) \
extern "C++" { \ extern "C++" { \
MDBX_CXX01_CONSTEXPR ENUM operator|(ENUM a, ENUM b) { \ MDBX_NOSANITIZE_ENUM MDBX_CXX01_CONSTEXPR ENUM operator|(ENUM a, ENUM b) { \
return ENUM(unsigned(a) | unsigned(b)); \ return ENUM(unsigned(a) | unsigned(b)); \
} \ } \
MDBX_CXX14_CONSTEXPR ENUM &operator|=(ENUM &a, ENUM b) { return a = a | b; } \ MDBX_NOSANITIZE_ENUM MDBX_CXX14_CONSTEXPR ENUM &operator|=(ENUM &a, \
MDBX_CXX01_CONSTEXPR ENUM operator&(ENUM a, ENUM b) { \ ENUM b) { \
return a = a | b; \
} \
MDBX_NOSANITIZE_ENUM MDBX_CXX01_CONSTEXPR ENUM operator&(ENUM a, ENUM b) { \
return ENUM(unsigned(a) & unsigned(b)); \ return ENUM(unsigned(a) & unsigned(b)); \
} \ } \
MDBX_CXX01_CONSTEXPR ENUM operator&(ENUM a, unsigned b) { \ MDBX_NOSANITIZE_ENUM MDBX_CXX01_CONSTEXPR ENUM operator&(ENUM a, \
unsigned b) { \
return ENUM(unsigned(a) & b); \ return ENUM(unsigned(a) & b); \
} \ } \
MDBX_CXX01_CONSTEXPR ENUM operator&(unsigned a, ENUM b) { \ MDBX_NOSANITIZE_ENUM MDBX_CXX01_CONSTEXPR ENUM operator&(unsigned a, \
ENUM b) { \
return ENUM(a & unsigned(b)); \ return ENUM(a & unsigned(b)); \
} \ } \
MDBX_CXX14_CONSTEXPR ENUM &operator&=(ENUM &a, ENUM b) { return a = a & b; } \ MDBX_NOSANITIZE_ENUM MDBX_CXX14_CONSTEXPR ENUM &operator&=(ENUM &a, \
MDBX_CXX14_CONSTEXPR ENUM &operator&=(ENUM &a, unsigned b) { \ ENUM b) { \
return a = a & b; \
} \
MDBX_NOSANITIZE_ENUM MDBX_CXX14_CONSTEXPR ENUM &operator&=(ENUM &a, \
unsigned b) { \
return a = a & b; \ return a = a & b; \
} \ } \
MDBX_CXX01_CONSTEXPR unsigned operator~(ENUM a) { return ~unsigned(a); } \ MDBX_CXX01_CONSTEXPR unsigned operator~(ENUM a) { return ~unsigned(a); } \
MDBX_CXX01_CONSTEXPR ENUM operator^(ENUM a, ENUM b) { \ MDBX_NOSANITIZE_ENUM MDBX_CXX01_CONSTEXPR ENUM operator^(ENUM a, ENUM b) { \
return ENUM(unsigned(a) ^ unsigned(b)); \ return ENUM(unsigned(a) ^ unsigned(b)); \
} \ } \
MDBX_CXX14_CONSTEXPR ENUM &operator^=(ENUM &a, ENUM b) { return a = a ^ b; } \ MDBX_NOSANITIZE_ENUM MDBX_CXX14_CONSTEXPR ENUM &operator^=(ENUM &a, \
ENUM b) { \
return a = a ^ b; \
} \
} }
#else /* __cplusplus */ #else /* __cplusplus */
/* nope for C since it always allows these operators for enums */ /* nope for C since it always allows these operators for enums */