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

            Bug ID: 117362
           Summary: target() attribute applied to wrong function, or wrong
                    check order in conjunction with interrupt() attribute
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cs at aibiot dot de
  Target Milestone: ---

This bug exists both in 14.2.1 20240921 and 15.0.0 20241006.

The source code (simplified):

static __attribute__ ((used,target("general-regs-only"),interrupt("IRQ"))) void
irqa (void) {}
static __attribute__ ((used,interrupt("IRQ"))) void irqb (void) {}
static __attribute__ ((used,interrupt("IRQ"))) void irqc (void) {}
static void irqd
[[gnu::used,gnu::interrupt("IRQ"),gnu::target("general-regs-only")]] (void) {}

The command line:

arm-none-eabi-gcc -std=gnu23 -g -O2 -Wall -Werror -Wextra -Wpedantic -Wshadow
-pipe -mcpu=cortex-a5 -mfpu=vfpv4-d16 -mfloat-abi=hard -o t.o -c t.c
t.c:1:1: error: FP registers might be clobbered despite 'interrupt' attribute:
compile with '-mgeneral-regs-only' [-Werror=attributes]
    1 | static __attribute__
((used,target("general-regs-only"),interrupt("IRQ"))) void irqa (void) {}
      | ^~~~~~
t.c:3:1: error: FP registers might be clobbered despite 'interrupt' attribute:
compile with '-mgeneral-regs-only' [-Werror=attributes]
    3 | static __attribute__ ((used,interrupt("IRQ"))) void irqc (void) {}
      | ^~~~~~
t.c:4:1: error: FP registers might be clobbered despite 'interrupt' attribute:
compile with '-mgeneral-regs-only' [-Werror=attributes]
    4 | static void irqd
[[gnu::used,gnu::interrupt("IRQ"),gnu::target("general-regs-only")]] (void) {}
      | ^~~~~~
cc1: all warnings being treated as errors

The error is only reported on the first and third function, although the first
should be correct and the second and third should report the error. It is as
though the target attribute is applied to the wrong (second) function, or
processing of checks for the interrupt() attribute checks the wrong state. This
happens for both C23 and classic attribute syntax. Ordering of the target and
interrupt attributes seems to not matter.

Reply via email to