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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Clang vs. GCC Frame Pointer Differences
        </td>
    </tr>

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

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

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

<pre>
    We used Clang 15 to build our kernel and encountered a problem during the process. I'm not sure if this is a bug or an issue with our configuration.

- The kernel code is as follows:
https://github.com/torvalds/linux/blob/2c85ebc57b3e1817b6ce1a6b703928e113a90442/arch/arm/kernel/unwind.c#L68-L77
```
enum regs {
#ifdef CONFIG_THUMB2_KERNEL
        FP = 7,
#else
        FP = 11,
#endif
        SP = 13,
        LR = 14,
        PC = 15
};
```

When using CONFIG_THUMB2_KERNEL, the frame pointer (FP) is set to r7. However, after compiling with Clang 15 and setting the option '-mframe-chain=aapcs+leaf', the frame pointer changes to r11.

- I noticed that this part of the llvm code caused
https://github.com/llvm/llvm-project/blob/cb30169422446b79d99df12b4cf5ab3d9d46d54c/llvm/lib/Target/ARM/ARMSubtarget.h#L374-L379


When the `-mframe-chain=aapcs+leaf` option is set, the createAAPCSFrameChain() function returns true, and the getFramePointerReg() function uses ARM::R11 as the frame pointer. However, when I compile with GCC using the options `-mthumb -mabi=aapcs`, it still uses r7 as the frame pointer.

- This is my demo to illustrate the difference:
 https://godbolt.org/z/GcMGhKvq1

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