Cleanup: quiet unreachable-code-generic-assoc warnings with CLANG

Duplicate types in type checking macros caused many warnings.
This commit is contained in:
Campbell Barton 2023-03-28 12:14:12 +11:00
parent 5379c0aa00
commit 1b0816929f
8 changed files with 19 additions and 30 deletions

@ -56,7 +56,11 @@
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define CHECK_TYPE_INLINE(val, type) \
(void)((void)(((type)0) != (0 ? (val) : ((type)0))), _Generic((val), type : 0, const type : 0))
/* NOTE: The NONCONST version is needed for scalar types on CLANG, to avoid warnings. . */
# define CHECK_TYPE_INLINE_NONCONST(val, type) \
(void)((void)(((type)0) != (0 ? (val) : ((type)0))), _Generic((val), type : 0))
#else
# define CHECK_TYPE_INLINE_NONCONST(val, type) ((void)(((type)0) != (0 ? (val) : ((type)0))))
# define CHECK_TYPE_INLINE(val, type) ((void)(((type)0) != (0 ? (val) : ((type)0))))
#endif

@ -571,7 +571,7 @@ bool BLI_ghashutil_ptrcmp(const void *a, const void *b);
*/
unsigned int BLI_ghashutil_strhash_n(const char *key, size_t n);
#define BLI_ghashutil_strhash(key) \
(CHECK_TYPE_ANY(key, char *, const char *, const char *const), BLI_ghashutil_strhash_p(key))
(CHECK_TYPE_ANY(key, char *, const char *), BLI_ghashutil_strhash_p(key))
unsigned int BLI_ghashutil_strhash_p(const void *ptr);
unsigned int BLI_ghashutil_strhash_p_murmur(const void *ptr);
bool BLI_ghashutil_strcmp(const void *a, const void *b);

@ -38,7 +38,7 @@
/* check for typeof() */
#ifdef __GNUC__
# define BLI_LINKSTACK_PUSH(var, ptr) \
(CHECK_TYPE_INLINE(ptr, typeof(var##_type_)), \
(CHECK_TYPE_INLINE_NONCONST(ptr, typeof(var##_type_)), \
BLI_linklist_prepend_pool(&(var), ptr, var##_pool_))
# define BLI_LINKSTACK_POP(var) \
(var ? (typeof(var##_type_))BLI_linklist_pop_pool(&(var), var##_pool_) : NULL)

@ -297,13 +297,13 @@ extern "C" {
/* Float equality checks. */
#define IS_EQ(a, b) \
(CHECK_TYPE_INLINE(a, double), \
CHECK_TYPE_INLINE(b, double), \
(CHECK_TYPE_INLINE_NONCONST(a, double), \
CHECK_TYPE_INLINE_NONCONST(b, double), \
((fabs((double)((a) - (b))) >= (double)FLT_EPSILON) ? false : true))
#define IS_EQF(a, b) \
(CHECK_TYPE_INLINE(a, float), \
CHECK_TYPE_INLINE(b, float), \
(CHECK_TYPE_INLINE_NONCONST(a, float), \
CHECK_TYPE_INLINE_NONCONST(b, float), \
((fabsf((float)((a) - (b))) >= (float)FLT_EPSILON) ? false : true))
#define IS_EQT(a, b, c) (((a) > (b)) ? ((((a) - (b)) <= (c))) : (((((b) - (a)) <= (c)))))

@ -833,7 +833,7 @@ MINLINE unsigned char unit_float_to_uchar_clamp(float val)
(val <= 0.0f) ? 0 : ((val > (1.0f - 0.5f / 255.0f)) ? 255 : ((255.0f * val) + 0.5f))));
}
#define unit_float_to_uchar_clamp(val) \
((CHECK_TYPE_INLINE(val, float)), unit_float_to_uchar_clamp(val))
((CHECK_TYPE_INLINE_NONCONST((val), float)), unit_float_to_uchar_clamp(val))
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
{
@ -842,14 +842,14 @@ MINLINE unsigned short unit_float_to_ushort_clamp(float val)
(val * 65535.0f + 0.5f));
}
#define unit_float_to_ushort_clamp(val) \
((CHECK_TYPE_INLINE(val, float)), unit_float_to_ushort_clamp(val))
((CHECK_TYPE_INLINE_NONCONST(val, float)), unit_float_to_ushort_clamp(val))
MINLINE unsigned char unit_ushort_to_uchar(unsigned short val)
{
return (unsigned char)(((val) >= 65535 - 128) ? 255 : ((val) + 128) >> 8);
}
#define unit_ushort_to_uchar(val) \
((CHECK_TYPE_INLINE(val, unsigned short)), unit_ushort_to_uchar(val))
((CHECK_TYPE_INLINE_NONCONST(val, unsigned short)), unit_ushort_to_uchar(val))
#define unit_float_to_uchar_clamp_v3(v1, v2) \
{ \

@ -431,8 +431,7 @@ enum {
#define _BM_GENERIC_TYPE_ELEM_CONST \
const void *, const BMVert *, const BMEdge *, const BMLoop *, const BMFace *, \
const BMVert_OFlag *, const BMEdge_OFlag *, const BMFace_OFlag *, const BMElem *, \
const BMElemF *, const BMHeader *, void *const, BMVert *const, BMEdge *const, \
BMLoop *const, BMFace *const, BMElem *const, BMElemF *const, BMHeader *const
const BMElemF *, const BMHeader *
#define BM_CHECK_TYPE_ELEM_CONST(ele) CHECK_TYPE_ANY(ele, _BM_GENERIC_TYPES_CONST)

@ -175,43 +175,31 @@ int GPU_matrix_stack_level_get_projection(void);
(_Generic((x), \
void *: (const float (*)[3])(x), \
float *: (const float (*)[3])(x), \
float [9]: (const float (*)[3])(x), \
float (*)[4]: (const float (*)[3])(x), \
float [4][4]: (const float (*)[3])(x), \
const void *: (const float (*)[3])(x), \
const float *: (const float (*)[3])(x), \
const float [9]: (const float (*)[3])(x), \
const float (*)[3]: (const float (*)[3])(x), \
const float [3][3]: (const float (*)[3])(x)) \
const float (*)[3]: (const float (*)[3])(x)) \
)
# define _GPU_MAT3_CAST(x) \
(_Generic((x), \
void *: (float (*)[3])(x), \
float *: (float (*)[3])(x), \
float [9]: (float (*)[3])(x), \
float (*)[3]: (float (*)[3])(x), \
float [3][3]: (float (*)[3])(x)) \
float (*)[3]: (float (*)[3])(x)) \
)
# define _GPU_MAT4_CONST_CAST(x) \
(_Generic((x), \
void *: (const float (*)[4])(x), \
float *: (const float (*)[4])(x), \
float [16]: (const float (*)[4])(x), \
float (*)[4]: (const float (*)[4])(x), \
float [4][4]: (const float (*)[4])(x), \
const void *: (const float (*)[4])(x), \
const float *: (const float (*)[4])(x), \
const float [16]: (const float (*)[4])(x), \
const float (*)[4]: (const float (*)[4])(x), \
const float [4][4]: (const float (*)[4])(x)) \
const float (*)[4]: (const float (*)[4])(x)) \
)
# define _GPU_MAT4_CAST(x) \
(_Generic((x), \
void *: (float (*)[4])(x), \
float *: (float (*)[4])(x), \
float [16]: (float (*)[4])(x), \
float (*)[4]: (float (*)[4])(x), \
float [4][4]: (float (*)[4])(x)) \
float (*)[4]: (float (*)[4])(x)) \
)
# else
# define _GPU_MAT3_CONST_CAST(x) (const float(*)[3])(x)

@ -655,9 +655,7 @@ typedef struct PreviewImage {
#ifdef GS
# undef GS
#endif
#define GS(a) \
(CHECK_TYPE_ANY(a, char *, const char *, char[66], const char[66]), \
(ID_Type)(*((const short *)(a))))
#define GS(a) (CHECK_TYPE_ANY(a, char *, const char *), (ID_Type)(*((const short *)(a))))
#define ID_NEW_SET(_id, _idn) \
(((ID *)(_id))->newid = (ID *)(_idn), \