cglm
cglm copied to clipboard
Avoid warnings (or possibly bugs) with old versions of gcc
include/cglm/types.h contains the following block of code:
#ifdef __GNUC__
#define CGLM_ASSUME_ALIGNED(expr, alignment) __builtin_assume_aligned((expr), (alignment))
#else
#define CGLM_ASSUME_ALIGNED(expr, alignment) (expr)
#endif
but __builtin_assume_aligned appeared only in gcc 4.7. With earlier versions this causes warnings like:
../cglm/simd/x86.h: In function ‘glmm_load3’: ../cglm/simd/x86.h:199: warning: implicit declaration of function ‘__builtin_assume_aligned’ ../cglm/simd/x86.h:199: warning: cast to pointer from integer of different size ../cglm/simd/x86.h: In function ‘glmm_store3’: ../cglm/simd/x86.h:208: warning: cast to pointer from integer of different size
Pre-4.7 gcc are old, but not yet irrelevant (the above example happens on still supported RHEL 6, for instance).
Would it be possible to replace the condition with:
#if defined(__GNUC__) && ( __GNUC__ * 100 + __GNUC_MINOR__ >= 407 )
or something similar ?
@pm4gh thanks for the bug report,
Would it be possible to replace the condition with: #if defined(GNUC) && ( GNUC * 100 + GNUC_MINOR >= 407 ) or something similar ?
Yes it is, instead of multiplication maybe we can specify minimum GNUC version. Alternatively we could use __has_builtin if it is supported:
https://stackoverflow.com/questions/54079257/how-to-check-builtin-function-is-available-on-gcc