Issue 243051
Summary [ARM] long long register variable in r12 silently overwrites r13 (stack pointer)
Labels new issue
Assignees
Reporter mu-mu-mu
    On ARM, clang accepts a `long long` local register variable in r12 without any diagnostic. The value is placed in the pair r12:r13, and r13 is the stack pointer, so the generated code overwrites SP with the high half of the value.

### Reproducer

```c
long long f(long long v)
{
    register long long x __asm__("r12") = v;
 __asm__ volatile("" : "+r"(x));
    return x;
}
```

```console
$ clang --target=arm-linux-gnueabihf -march=armv7-a -O2 -S test.c
```

### Actual behavior

```
f:
        mov     sp, r1          @ sp = high half of v
        mov     r12, r0
        @APP
        @NO_APP
        mov r0, r12
        mov     r1, sp
        bx      lr              @ returns with the corrupted sp
```

Calling `f(0x100000002)` crashes under qemu-arm (SIGBUS at -O2, SIGSEGV at -O0).

### Expected behavior

An error, since the pair r12:r13 includes the stack pointer.

clang (trunk): https://godbolt.org/z/cYPjc7GE6
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to