<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64353>64353</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang] arm-none-eabi: __attribute__ ((interrupt ("IRQ"))) generates superfluous code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rgrr
      </td>
    </tr>
</table>

<pre>
    Example code for a Cortex-M0 device:

```C
typedef void (*VECTOR_FUNCTION_Type)(void);

void Interrupt_Handler(void) __attribute__ ((interrupt ("IRQ")));

const VECTOR_FUNCTION_Type test__VECTOR_TABLE[64] __attribute__((used, section(".test_vectors"))) = {
    Interrupt_Handler,
};

void Interrupt_Handler(void)
{
    __asm volatile ("nop\n" : : :);
}
```

gcc generates the following code which is correct:

```ASM
00000000 <Interrupt_Handler>:
   0:   46c0 nop         @ (mov r8, r8)
   2:   4770        bx lr
```


clang does this:

```ASM
00000000 <Interrupt_Handler>:
   0:   b5d0        push    {r4, r6, r7, lr}
   2: af02        add r7, sp, #8
   4:   466c        mov r4, sp
   6: 08e4        lsrs    r4, r4, #3
   8:   00e4        lsls    r4, r4, #3
 a:   46a5        mov sp, r4
   c:   bf00        nop
   e:   1ffc subs    r4, r7, #7
  10:   3c01        subs    r4, #1
  12:   46a5 mov sp, r4
  14:   bdd0        pop {r4, r6, r7, pc}
```

which is actually not wrong but not necessary.  Also it has to be noted, that usage of the interrupt attribute is not very common in Cortex-Mx code (as far as I know).  Nevertheless the above code sequence could be the reason why interrupt handling with gcc is much faster than with clang if you are using the attribute.

Example with more text around is here: https://github.com/rgrr/playground/tree/feature/compiler-attributes-etc/llvm-games/attributes

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vt1u4zYTfRr6ZhCDoiTLvvCFY8f4Any7i27T3hoUNZLYUqLKHzt--4L6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