<div dir="ltr"><div>Hello,</div><div><br></div><div>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. <br></div><div><br></div><div>An example:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span style="font-family:monospace">define ghccc void @f(i64 %0) {<br>  %2 = alloca i8, i64 %0, align 16<br>  call ghccc void @g(i8* nonnull %2)<br>  ret void<br>}<br>declare ghccc void @g(i8*) </span><br></div></blockquote><div><br></div><div>The generated assembly is  (llc test.bc -O3 -o test.o -filetype=obj):</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><span style="font-family:monospace">0000000000000000 <f>:<br>   0:       55                     push   %rbp<br>   1:   48 89 e5                  mov    %rsp,%rbp<br>   4:     48 89 e0                  mov    %rsp,%rax<br>   7:     49 83 c5 0f          add    $0xf,%r13<br>   b:   49 83 e5 f0          and    $0xfffffffffffffff0,%r13<br>   f:    4c 29 e8                  sub    %r13,%rax<br>  12:      48 89 c4                  mov    %rax,%rsp<br>  15:      49 89 c5                  mov    %rax,%r13<br>  18:      e8 00 00 00 00               callq  1d <f+0x1d><br>                     19: R_X86_64_PLT32      g-0x4<br>  1d:   48 89 ec             <span style="color:rgb(255,0,0)">    <b>mov    %rbp,%rsp</b></span><br>  20:      5d                     pop    %rbp<br>  21:   c3                     retq</span></div></blockquote><div><br></div><div> </div><div>In line '1d', rbp may have been garbaged by the call. <br></div><div><br></div><div>Is this a bug in LLVM?</div><div><br></div><div>Thanks,</div><div>Haoran<br></div></div>