1 ; RUN: llc %s -o - | FileCheck %s
2 ; RUN: llc -mtriple=armv7-linux -exception-model sjlj %s -o - | FileCheck %s -check-prefix CHECK-LINUX
3 ; RUN: llc -mtriple=thumbv7-win32 -exception-model sjlj %s -o - | FileCheck %s -check-prefix CHECK-WIN32
4 target triple = "armv7-apple-ios"
6 declare i32 @llvm.eh.sjlj.setjmp(i8*)
7 declare void @llvm.eh.sjlj.longjmp(i8*)
8 @g = external global i32
10 declare void @may_throw()
11 declare i32 @__gxx_personality_sj0(...)
12 declare i8* @__cxa_begin_catch(i8*)
13 declare void @__cxa_end_catch()
14 declare i32 @llvm.eh.typeid.for(i8*)
15 declare i8* @llvm.frameaddress(i32)
16 declare i8* @llvm.stacksave()
17 @_ZTIPKc = external constant i8*
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 i8*], align 4
46 %arraydecay = getelementptr inbounds [5 x i8*], [5 x i8*]* %buf, i32 0, i32 0
47 %bufptr = bitcast i8** %arraydecay to i8*
48 ; Note: This is simplified, in reality you have to store the framepointer +
49 ; stackpointer in the buffer as well for this to be legal!
50 %setjmpres = call i32 @llvm.eh.sjlj.setjmp(i8* %bufptr)
51 %tobool = icmp ne i32 %setjmpres, 0
52 br i1 %tobool, label %if.then, label %if.else
55 store volatile i32 1, i32* @g, align 4
59 store volatile i32 0, i32* @g, align 4
60 call void @llvm.eh.sjlj.longjmp(i8* %bufptr)
67 ; CHECK-LABEL: combine_sjlj_eh_and_setjmp_longjmp
68 ; Check that we can mix sjlj exception handling with __builtin_setjmp
69 ; and __builtin_longjmp.
72 ; CHECK: add [[PCREG:r[0-9]+]], pc, #8
73 ; CHECK-NEXT: str [[PCREG]], {{\[}}[[BUFREG:r[0-9]+]], #4]
74 ; CHECK-NEXT: mov r0, #0
75 ; CHECK-NEXT: add pc, pc, #0
76 ; CHECK-NEXT: mov r0, #1
79 ; CHECK: ldr sp, [{{\s*}}[[BUFREG:r[0-9]+]], #8]
80 ; CHECK-NEXT: ldr [[DESTREG:r[0-9]+]], {{\[}}[[BUFREG]], #4]
81 ; CHECK-NEXT: ldr r7, {{\[}}[[BUFREG]]{{\]}}
82 ; CHECK-NEXT: bx [[DESTREG]]
83 define void @combine_sjlj_eh_and_setjmp_longjmp() personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*) {
85 %buf = alloca [5 x i8*], align 4
86 invoke void @may_throw() to label %try.cont unwind label %lpad
89 %0 = landingpad { i8*, i32 } catch i8* bitcast (i8** @_ZTIPKc to i8*)
90 %1 = extractvalue { i8*, i32 } %0, 1
91 %2 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIPKc to i8*)) #3
92 %matches = icmp eq i32 %1, %2
93 br i1 %matches, label %catch, label %eh.resume
96 %3 = extractvalue { i8*, i32 } %0, 0
97 %4 = tail call i8* @__cxa_begin_catch(i8* %3) #3
98 store volatile i32 0, i32* @g, align 4
99 %5 = bitcast [5 x i8*]* %buf to i8*
100 %arraydecay = getelementptr inbounds [5 x i8*], [5 x i8*]* %buf, i64 0, i64 0
101 %6 = tail call i8* @llvm.frameaddress(i32 0)
102 store i8* %6, i8** %arraydecay, align 16
103 %7 = tail call i8* @llvm.stacksave()
104 %8 = getelementptr [5 x i8*], [5 x i8*]* %buf, i64 0, i64 2
105 store i8* %7, i8** %8, align 16
106 %9 = call i32 @llvm.eh.sjlj.setjmp(i8* %5)
107 %tobool = icmp eq i32 %9, 0
108 br i1 %tobool, label %if.else, label %if.then
111 store volatile i32 2, i32* @g, align 4
112 call void @__cxa_end_catch() #3
116 store volatile i32 1, i32* @g, align 4
117 call void @llvm.eh.sjlj.longjmp(i8* %5)
121 resume { i8*, i32 } %0