diff mbox series

[4/9] extrawarn: don't turn off -Wshift-negative-value for gcc-9

Message ID 20230811140327.3754597-5-arnd@kernel.org (mailing list archive)
State New, archived
Headers show
Series Kbuild: warning options cleanup and more warnings | expand

Commit Message

Arnd Bergmann Aug. 11, 2023, 2:03 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de>

The warning does nothing for newer versions of gcc since -fno-strict-overflow
is used, on old versions it warns about lines that would be undefined
otherwise:

fs/isofs/util.c: In function 'iso_date':
fs/isofs/util.c:40:14: error: left shift of negative value [-Werror=shift-negative-value]
    tz |= (-1 << 8);
              ^~
drivers/video/fbdev/tdfxfb.c: In function 'tdfxfb_probe':
drivers/video/fbdev/tdfxfb.c:1482:17: error: left shift of negative value [-Werror=shift-negative-value]
      (PAGE_MASK << 1);
                 ^~
drivers/tty/serial/8250/8250_core.c: In function 'serial8250_request_rsa_resource':
drivers/tty/serial/8250/8250_core.c:350:38: error: left shift of negative value [-Werror=shift-negative-value]
  unsigned long start = UART_RSA_BASE << up->port.regshift;
                                      ^~
drivers/tty/serial/8250/8250_core.c: In function 'serial8250_release_rsa_resource':
drivers/tty/serial/8250/8250_core.c:371:39: error: left shift of negative value [-Werror=shift-negative-value]
  unsigned long offset = UART_RSA_BASE << up->port.regshift;
                                       ^~
drivers/clk/mvebu/dove-divider.c: In function 'dove_set_clock':
drivers/clk/mvebu/dove-divider.c:145:14: error: left shift of negative value [-Werror=shift-negative-value]
  mask = ~(~0 << dc->div_bit_size) << dc->div_bit_start;
              ^~
drivers/block/drbd/drbd_main.c: In function 'dcbp_set_pad_bits':
drivers/block/drbd/drbd_main.c:1098:37: error: left shift of negative value [-Werror=shift-negative-value]
  p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4);

Disable these conditionally to keep the command line a little shorter.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 scripts/Makefile.extrawarn | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Masahiro Yamada Aug. 12, 2023, 12:04 p.m. UTC | #1
On Sat, Aug 12, 2023 at 5:00 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> The warning does nothing for newer versions of gcc since -fno-strict-overflow
> is used, on old versions it warns about lines that would be undefined
> otherwise:
>
> fs/isofs/util.c: In function 'iso_date':
> fs/isofs/util.c:40:14: error: left shift of negative value [-Werror=shift-negative-value]
>     tz |= (-1 << 8);
>               ^~
> drivers/video/fbdev/tdfxfb.c: In function 'tdfxfb_probe':
> drivers/video/fbdev/tdfxfb.c:1482:17: error: left shift of negative value [-Werror=shift-negative-value]
>       (PAGE_MASK << 1);
>                  ^~
> drivers/tty/serial/8250/8250_core.c: In function 'serial8250_request_rsa_resource':
> drivers/tty/serial/8250/8250_core.c:350:38: error: left shift of negative value [-Werror=shift-negative-value]
>   unsigned long start = UART_RSA_BASE << up->port.regshift;
>                                       ^~
> drivers/tty/serial/8250/8250_core.c: In function 'serial8250_release_rsa_resource':
> drivers/tty/serial/8250/8250_core.c:371:39: error: left shift of negative value [-Werror=shift-negative-value]
>   unsigned long offset = UART_RSA_BASE << up->port.regshift;
>                                        ^~
> drivers/clk/mvebu/dove-divider.c: In function 'dove_set_clock':
> drivers/clk/mvebu/dove-divider.c:145:14: error: left shift of negative value [-Werror=shift-negative-value]
>   mask = ~(~0 << dc->div_bit_size) << dc->div_bit_start;
>               ^~
> drivers/block/drbd/drbd_main.c: In function 'dcbp_set_pad_bits':
> drivers/block/drbd/drbd_main.c:1098:37: error: left shift of negative value [-Werror=shift-negative-value]
>   p->encoding = (p->encoding & (~0x7 << 4)) | (n << 4);
>
> Disable these conditionally to keep the command line a little shorter.



Just a nit for the commit subject and description.

It mentions only gcc, but also affects clang.




Is the following a better subject?

  extrawarn: don't turn off -Wshift-negative-value for gcc-9+ or clang

or

  extrawarn: turn off -Wshift-negative-value only for gcc < 9
diff mbox series

Patch

diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn
index 8afbe4706ff11..87bfe153198f1 100644
--- a/scripts/Makefile.extrawarn
+++ b/scripts/Makefile.extrawarn
@@ -171,12 +171,14 @@  else
 # The following turn off the warnings enabled by -Wextra
 KBUILD_CFLAGS += -Wno-missing-field-initializers
 KBUILD_CFLAGS += -Wno-type-limits
-KBUILD_CFLAGS += -Wno-shift-negative-value
 
 ifdef CONFIG_CC_IS_CLANG
 KBUILD_CFLAGS += -Wno-initializer-overrides
 else
 KBUILD_CFLAGS += -Wno-maybe-uninitialized
+ifneq ($(call gcc-min-version, 90100),y)
+KBUILD_CFLAGS += $(call cc-disable-warning, shift-negative-value)
+endif
 endif
 
 endif