[ASAN] [Regression] Stack pointer corruption on ARMv7


I discovered a stack pointer corruption regression in LLVM 13 causing stack leak with ASAN enabled when targeting cortex-a9.

The issue is reproducible with the file in the attachment. Also published online[1]. The arguments to compile are as follows:

clang -o error.o -c -target arm-gnu-linux-eabi -mcpu=cortex-a9 -fsanitize=address error.c

The problematic part is the loop in the `test` function. When `func` is called, LLVM does not adjust the stack back, causing fast stack overflow:

.LBB2_5: @ %for.cond
        sub sp, sp, #8
        str r12, [sp]
        bl func
.LBB2_7: @ %if.end
        b .LBB2_5

LLVM 12.0.1 does not have this issue. I will post the issue to the bugtracker when GitHub Issues land or bugzilla returns. Can anyone confirm that the issue is still present in main?

Best regards,

[1] Compiler Explorer

error.c (360 Bytes)

The issue is present in main and is caused by d88f96dff3f192fc0c1bf57f7810b95a709b3591.
Added Tim and Jessica to CC.

Differential: https://reviews.llvm.org/D102613

Best regards,