Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

math-emu: Use statement expressions to fix Wshift-count-overflow warning

To avoid "shift count >= width of type" warning, using statement
expressions to implement the conditional controlling before constant shift

The modification in op-2.h is taken from the glibc
commit 'sysdeps/unix/sysv/lin ("fe0b1e854ad32")'.

Signed-off-by: Vincent Chen <vincentc@andestech.com>
Acked-by: Greentime Hu <greentime@andestech.com>
Signed-off-by: Greentime Hu <greentime@andestech.com>

authored by

Vincent Chen and committed by
Greentime Hu
8183db10 a188339c

+13 -15
+7 -10
include/math-emu/op-2.h
··· 567 567 */ 568 568 569 569 #define _FP_FRAC_ASSEMBLE_2(r, X, rsize) \ 570 - do { \ 571 - if (rsize <= _FP_W_TYPE_SIZE) \ 572 - r = X##_f0; \ 573 - else \ 574 - { \ 575 - r = X##_f1; \ 576 - r <<= _FP_W_TYPE_SIZE; \ 577 - r += X##_f0; \ 578 - } \ 579 - } while (0) 570 + (void) (((rsize) <= _FP_W_TYPE_SIZE) \ 571 + ? ({ (r) = X##_f0; }) \ 572 + : ({ \ 573 + (r) = X##_f1; \ 574 + (r) <<= _FP_W_TYPE_SIZE; \ 575 + (r) += X##_f0; \ 576 + })) 580 577 581 578 #define _FP_FRAC_DISASSEMBLE_2(X, r, rsize) \ 582 579 do { \
+6 -5
include/math-emu/op-common.h
··· 795 795 ur_ = (unsigned rtype) -r; \ 796 796 else \ 797 797 ur_ = (unsigned rtype) r; \ 798 - if (rsize <= _FP_W_TYPE_SIZE) \ 799 - __FP_CLZ(X##_e, ur_); \ 800 - else \ 801 - __FP_CLZ_2(X##_e, (_FP_W_TYPE)(ur_ >> _FP_W_TYPE_SIZE), \ 802 - (_FP_W_TYPE)ur_); \ 798 + (void) (((rsize) <= _FP_W_TYPE_SIZE) \ 799 + ? ({ __FP_CLZ(X##_e, ur_); }) \ 800 + : ({ \ 801 + __FP_CLZ_2(X##_e, (_FP_W_TYPE)(ur_ >> _FP_W_TYPE_SIZE), \ 802 + (_FP_W_TYPE)ur_); \ 803 + })); \ 803 804 if (rsize < _FP_W_TYPE_SIZE) \ 804 805 X##_e -= (_FP_W_TYPE_SIZE - rsize); \ 805 806 X##_e = rsize - X##_e - 1; \