X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lib%2Fbitfield.h;h=42521f2e3f6741826ea9a74cc5d49a89786559fc;hb=5daaccef9d7dc530b9cb31993192255ee7c72926;hp=f748696ada911163014ec9cad4f4f0abf33ff6c1;hpb=b81caadf2d255e8e9f83aa3fa3652bdd013d7c6a;p=lttng-modules.git diff --git a/lib/bitfield.h b/lib/bitfield.h index f748696a..42521f2e 100644 --- a/lib/bitfield.h +++ b/lib/bitfield.h @@ -26,6 +26,26 @@ #error "bitfield.h requires the compiler representation of signed integers to be two's complement." #endif +/* + * _bt_is_signed_type() willingly generates comparison of unsigned + * expression < 0, which is always false. Silence compiler warnings. + */ +#ifdef __GNUC__ +# define _BT_DIAG_PUSH _Pragma("GCC diagnostic push") +# define _BT_DIAG_POP _Pragma("GCC diagnostic pop") + +# define _BT_DIAG_STRINGIFY_1(x) #x +# define _BT_DIAG_STRINGIFY(x) _BT_DIAG_STRINGIFY_1(x) + +# define _BT_DIAG_IGNORE(option) \ + _Pragma(_BT_DIAG_STRINGIFY(GCC diagnostic ignored option)) +# define _BT_DIAG_IGNORE_TYPE_LIMITS _BT_DIAG_IGNORE("-Wtype-limits") +#else +# define _BT_DIAG_PUSH +# define _BT_DIAG_POP +# define _BT_DIAG_IGNORE +#endif + #define _bt_is_signed_type(type) ((type) -1 < (type) 0) /* @@ -345,6 +365,7 @@ do { \ unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ unsigned long start_unit, end_unit, this_unit; \ unsigned long end, cshift; /* cshift is "complement shift" */ \ + bool is_signed_type; \ \ if (!__length) { \ *__vptr = 0; \ @@ -356,7 +377,11 @@ do { \ end_unit = (end + (ts - 1)) / ts; \ \ this_unit = end_unit - 1; \ - if (_bt_is_signed_type(__typeof__(__v)) \ + _BT_DIAG_PUSH \ + _BT_DIAG_IGNORE_TYPE_LIMITS \ + is_signed_type = _bt_is_signed_type(__typeof__(__v)); \ + _BT_DIAG_POP \ + if (is_signed_type \ && (__ptr[this_unit] & _bt_lshift((type) 1, (end % ts ? end % ts : ts) - 1))) \ __v = ~(__typeof__(__v)) 0; \ else \ @@ -412,6 +437,7 @@ do { \ unsigned long ts = sizeof(type) * CHAR_BIT; /* type size */ \ unsigned long start_unit, end_unit, this_unit; \ unsigned long end, cshift; /* cshift is "complement shift" */ \ + bool is_signed_type; \ \ if (!__length) { \ *__vptr = 0; \ @@ -423,7 +449,11 @@ do { \ end_unit = (end + (ts - 1)) / ts; \ \ this_unit = start_unit; \ - if (_bt_is_signed_type(__typeof__(__v)) \ + _BT_DIAG_PUSH \ + _BT_DIAG_IGNORE_TYPE_LIMITS \ + is_signed_type = _bt_is_signed_type(__typeof__(__v)); \ + _BT_DIAG_POP \ + if (is_signed_type \ && (__ptr[this_unit] & _bt_lshift((type) 1, ts - (__start % ts) - 1))) \ __v = ~(__typeof__(__v)) 0; \ else \