[LLVMdev] setjmp / longjmp does not work on X86

Paweł Bylica chfast at gmail.com
Mon Feb 9 05:59:09 PST 2015


I create simple IR code that uses llvm.eh.sjlj.setjmp and
llvm.eh.sjlj.longjmp

define i32 @main() {
  %buf = alloca i8, i32 40, align 16
  %r = call i32 @llvm.eh.sjlj.setjmp(i8* %buf)

  %normal = icmp eq i32 %r, 0
  br i1 %normal, label %Normal, label %Jump

Normal:
  call void @llvm.eh.sjlj.longjmp(i8* %buf)
  ret i32 2

Jump:
  ret i32 0
}

declare i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf) returns_twice nounwind
declare void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf) noreturn nounwind


On Windows 64bit and Linux 64bit this code crashes. setjmp lowering pushes
only jump address to buffer, but longjmp expects also stack pointer (rsp)
and bsp register values to be in the buffer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150209/05e92403/attachment.html>


More information about the llvm-dev mailing list