https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107405

            Bug ID: 107405
           Summary: enums can be long in gcc-13
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirislaby at gmail dot com
  Target Milestone: ---

While compiling the kernel (next/master -- 89bf6e28373beef9) with gcc-13, I
see:
drivers/block/mtip32xx/mtip32xx.c:722:25: error: format '%x' expects argument
of type 'unsigned int', but argument 3 has type 'long in' [-Werror=format=]

That is:
enum {
Many members, see:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/ata.h?id=4dc12f37a8e98e1dca5521c14625c869537b50b6#n25
};
...
#define PORT_IRQ_HANDLED \      
        (PORT_IRQ_SDB_FIS | PORT_IRQ_LEGACY | \
         PORT_IRQ_TF_ERR | PORT_IRQ_IF_ERR | \
         PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)


...
u32 port_stat;
...
        dev_warn(&dd->pdev->dev,
              "Port stat errors %x unhandled\n",
              (port_stat & ~PORT_IRQ_HANDLED));

So port_stat is uint, ~PORT_IRQ_HANDLED is derived from enum, which should be
int from standard.

Reduced testcase:
#include <stdio.h>
enum { A = 0xffffffff, B = 1 << 31, };
int main() { printf("%lx %x %zu\n", A, B, sizeof(B)); }

$ gcc-13 -std=gnu99 x.c -Wall -O2 && ./a.out
x.c: In function ‘main’:
x.c:3:27: warning: format ‘%x’ expects argument of type ‘unsigned int’, but
argument 3 has type ‘long int’ [-Wformat=]
    3 | int main() { printf("%lx %x %zu\n", A, B, sizeof(B)); }
      |                          ~^            ~
      |                           |            |
      |                           unsigned int long int
      |                          %lx
ffffffff 80000000 8
$ gcc-12 -std=gnu11 x.c -Wall -O2 && ./a.out
ffffffff 80000000 4

Reply via email to