1 ; RUN: llc -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s
2 ; RUN: llc -mtriple=armv7-linux -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s -check-prefix CHECK-LINUX
3 ; RUN: llc -mtriple=thumbv7-win32 -exception-model sjlj -simplifycfg-require-and-preserve-domtree=1 %s -o - | FileCheck %s -check-prefix CHECK-WIN32
4 target triple = "armv7-apple-ios"
6 declare i32 @llvm.eh.sjlj.setjmp(ptr)
7 declare void @llvm.eh.sjlj.longjmp(ptr)
8 @g = external global i32
10 declare void @may_throw()
11 declare i32 @__gxx_personality_sj0(...)
12 declare ptr @__cxa_begin_catch(ptr)
13 declare void @__cxa_end_catch()
14 declare i32 @llvm.eh.typeid.for(ptr)
15 declare ptr @llvm.frameaddress(i32)
16 declare ptr @llvm.stacksave()
17 @_ZTIPKc = external constant ptr
22 ; CHECK: add [[PCREG:r[0-9]+]], pc, #8
23 ; CHECK-NEXT: str [[PCREG]], [[[BUFREG:r[0-9]+]], #4]
24 ; CHECK-NEXT: mov r0, #0
25 ; CHECK-NEXT: add pc, pc, #0
26 ; CHECK-NEXT: mov r0, #1
29 ; CHECK: ldr sp, [{{\s*}}[[BUFREG:r[0-9]+]], #8]
30 ; CHECK-NEXT: ldr [[DESTREG:r[0-9]+]], [[[BUFREG]], #4]
31 ; CHECK-NEXT: ldr r7, [[[BUFREG]]]
32 ; CHECK-NEXT: bx [[DESTREG]]
34 ; CHECK-LINUX: ldr sp, [{{\s*}}[[BUFREG:r[0-9]+]], #8]
35 ; CHECK-LINUX-NEXT: ldr [[DESTREG:r[0-9]+]], [[[BUFREG]], #4]
36 ; CHECK-LINUX-NEXT: ldr r7, [[[BUFREG]]]
37 ; CHECK-LINUX-NEXT: ldr r11, [[[BUFREG]]]
38 ; CHECK-LINUX-NEXT: bx [[DESTREG]]
40 ; CHECK-WIN32: ldr.w r11, [{{\s*}}[[BUFREG:r[0-9]+]]]
41 ; CHECK-WIN32-NEXT: ldr.w sp, [[[BUFREG]], #8]
42 ; CHECK-WIN32-NEXT: ldr.w pc, [[[BUFREG]], #4]
43 define void @foobar() {
45 %buf = alloca [5 x ptr], align 4
46 ; Note: This is simplified, in reality you have to store the framepointer +
47 ; stackpointer in the buffer as well for this to be legal!
48 %setjmpres = call i32 @llvm.eh.sjlj.setjmp(ptr %buf)
49 %tobool = icmp ne i32 %setjmpres, 0
50 br i1 %tobool, label %if.then, label %if.else
53 store volatile i32 1, ptr @g, align 4
57 store volatile i32 0, ptr @g, align 4
58 call void @llvm.eh.sjlj.longjmp(ptr %buf)
65 ; CHECK-LABEL: combine_sjlj_eh_and_setjmp_longjmp
66 ; Check that we can mix sjlj exception handling with __builtin_setjmp
67 ; and __builtin_longjmp.
70 ; CHECK: add [[PCREG:r[0-9]+]], pc, #8
71 ; CHECK-NEXT: str [[PCREG]], [[[BUFREG:r[0-9]+]], #4]
72 ; CHECK-NEXT: mov r0, #0
73 ; CHECK-NEXT: add pc, pc, #0
74 ; CHECK-NEXT: mov r0, #1
77 ; CHECK: ldr sp, [{{\s*}}[[BUFREG:r[0-9]+]], #8]
78 ; CHECK-NEXT: ldr [[DESTREG:r[0-9]+]], [[[BUFREG]], #4]
79 ; CHECK-NEXT: ldr r7, [[[BUFREG]]]
80 ; CHECK-NEXT: bx [[DESTREG]]
81 define void @combine_sjlj_eh_and_setjmp_longjmp() personality ptr @__gxx_personality_sj0 {
83 %buf = alloca [5 x ptr], align 4
84 invoke void @may_throw() to label %try.cont unwind label %lpad
87 %0 = landingpad { ptr, i32 } catch ptr @_ZTIPKc
88 %1 = extractvalue { ptr, i32 } %0, 1
89 %2 = tail call i32 @llvm.eh.typeid.for(ptr @_ZTIPKc) #3
90 %matches = icmp eq i32 %1, %2
91 br i1 %matches, label %catch, label %eh.resume
94 %3 = extractvalue { ptr, i32 } %0, 0
95 %4 = tail call ptr @__cxa_begin_catch(ptr %3) #3
96 store volatile i32 0, ptr @g, align 4
97 %5 = tail call ptr @llvm.frameaddress(i32 0)
98 store ptr %5, ptr %buf, align 16
99 %6 = tail call ptr @llvm.stacksave()
100 %7 = getelementptr [5 x ptr], ptr %buf, i64 0, i64 2
101 store ptr %6, ptr %7, align 16
102 %8 = call i32 @llvm.eh.sjlj.setjmp(ptr %buf)
103 %tobool = icmp eq i32 %8, 0
104 br i1 %tobool, label %if.else, label %if.then
107 store volatile i32 2, ptr @g, align 4
108 call void @__cxa_end_catch() #3
112 store volatile i32 1, ptr @g, align 4
113 call void @llvm.eh.sjlj.longjmp(ptr %buf)
117 resume { ptr, i32 } %0