[llvm-dev] Codegen bug in variable-sized alloca interaction with calling convention?
Haoran Xu via llvm-dev
llvm-dev at lists.llvm.org
Wed Oct 7 01:00:29 PDT 2020
Hello,
It seems like if rbp register is not callee-saved (e.g. GHC calling
convention), LLVM still assumes that rbp is unchanged after a function
call, resulting in buggy assembly.
An example:
> define ghccc void @f(i64 %0) {
> %2 = alloca i8, i64 %0, align 16
> call ghccc void @g(i8* nonnull %2)
> ret void
> }
> declare ghccc void @g(i8*)
>
The generated assembly is (llc test.bc -O3 -o test.o -filetype=obj):
> 0000000000000000 <f>:
> 0: 55 push %rbp
> 1: 48 89 e5 mov %rsp,%rbp
> 4: 48 89 e0 mov %rsp,%rax
> 7: 49 83 c5 0f add $0xf,%r13
> b: 49 83 e5 f0 and $0xfffffffffffffff0,%r13
> f: 4c 29 e8 sub %r13,%rax
> 12: 48 89 c4 mov %rax,%rsp
> 15: 49 89 c5 mov %rax,%r13
> 18: e8 00 00 00 00 callq 1d <f+0x1d>
> 19: R_X86_64_PLT32 g-0x4
> 1d: 48 89 ec *mov %rbp,%rsp*
> 20: 5d pop %rbp
> 21: c3 retq
>
In line '1d', rbp may have been garbaged by the call.
Is this a bug in LLVM?
Thanks,
Haoran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201007/4b33573d/attachment.html>
More information about the llvm-dev
mailing list