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

    <tr>
        <th>Summary</th>
        <td>
            `rbp` clobber in inline assembly is not respected for functions with a frame pointer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    The `rbp` register can be clobbered by inline assembly, like so:

```c
void simplenop(void) {
    asm volatile("nop" : : : "rbp");
}
```

This results in the following expected assembly:

```asm
simplenop():                          # @simplenop()
        push    rbp
        nop
        pop     rbp
        ret
```

However, when a frame pointer is forced, this clobber constraint is not respected:

```c
void buffernop(int size) {
    char buf[size];
    asm volatile("nop" : : "r"(buf): "rbp");
}
```

```asm
buffernop(int):                          # @buffernop(int)
        push    rbp
        mov     rbp, rsp
        mov     eax, edi
        mov     rcx, rsp
        add     rax, 15
        and     rax, -16
        sub     rcx, rax
        mov     rsp, rcx
        nop
        mov     rsp, rbp
        pop     rbp
        ret
```

As you can see, the generated code clearly expects the `rbp` to not be clobbered after the inline assembly.
Godbolt link: https://godbolt.org/z/osMEb1Kcj

This resulted in an actual bug in https://github.com/tinygo-org/tinygo/pull/3103#issuecomment-1287052017 where I try to call functions with a custom ABI via inline assembly.
Ideally the X86 backend should save the `rbp` register somewhere else (for example, on the stack: `rsp` is not clobbered) or just throw an error. Silently miscompiling results in bugs.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVU1zmzAQ_TVw0cQDwmB84JA0_ch0emoPvUqwGCUCMZKwQ399dyFxYmKnmTK2sdgP7b63ekhTjcWvBliQRVb2-Mss7JTzYFkpOiaBldpICRYqJkemOq06YMI5aKUeA_6JafUAzJkguQ6i2yB6_s2i-VPO671RFXOq7TV0pg94Tg8CvmXB5mb2YHgJ17K90cIrDegT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