blob: 28b0bca962ea8e870f250ce71feeb574985ac625 [file] [log] [blame]
Reid Klecknera9d62532015-06-11 22:32:23 +00001; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s
2
3; 32-bit catch-all has to use a filter function because that's how it saves the
4; exception code.
5
6@str = linkonce_odr unnamed_addr constant [27 x i8] c"GetExceptionCode(): 0x%lx\0A\00", align 1
7
8declare i32 @_except_handler3(...)
9declare void @crash()
10declare i32 @printf(i8* nocapture readonly, ...) nounwind
11declare i32 @llvm.eh.typeid.for(i8*)
12declare i8* @llvm.frameaddress(i32)
13declare i8* @llvm.framerecover(i8*, i8*, i32)
14declare void @llvm.frameescape(...)
15declare i8* @llvm.x86.seh.exceptioninfo(i8*, i8*)
16
David Majnemer7fddecc2015-06-17 20:52:32 +000017define i32 @main() personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) {
Reid Klecknera9d62532015-06-11 22:32:23 +000018entry:
19 %__exceptioncode = alloca i32, align 4
20 call void (...) @llvm.frameescape(i32* %__exceptioncode)
21 invoke void @crash() #5
22 to label %__try.cont unwind label %lpad
23
24lpad: ; preds = %entry
David Majnemer7fddecc2015-06-17 20:52:32 +000025 %0 = landingpad { i8*, i32 }
Reid Klecknera9d62532015-06-11 22:32:23 +000026 catch i8* bitcast (i32 ()* @"filt$main" to i8*)
27 %1 = extractvalue { i8*, i32 } %0, 1
28 %2 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ()* @"filt$main" to i8*)) #4
29 %matches = icmp eq i32 %1, %2
30 br i1 %matches, label %__except, label %eh.resume
31
32__except: ; preds = %lpad
33 %3 = load i32, i32* %__exceptioncode, align 4
34 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i32 0, i32 0), i32 %3) #4
35 br label %__try.cont
36
37__try.cont: ; preds = %entry, %__except
38 ret i32 0
39
40eh.resume: ; preds = %lpad
41 resume { i8*, i32 } %0
42}
43
44define internal i32 @"filt$main"() {
45entry:
46 %0 = tail call i8* @llvm.frameaddress(i32 1)
47 %1 = tail call i8* @llvm.framerecover(i8* bitcast (i32 ()* @main to i8*), i8* %0, i32 0)
48 %__exceptioncode = bitcast i8* %1 to i32*
49 %2 = tail call i8* @llvm.x86.seh.exceptioninfo(i8* bitcast (i32 ()* @main to i8*), i8* %0)
50 %3 = bitcast i8* %2 to i32**
51 %4 = load i32*, i32** %3, align 4
52 %5 = load i32, i32* %4, align 4
53 store i32 %5, i32* %__exceptioncode, align 4
54 ret i32 1
55}
56
57; Check that we can get the exception code from eax to the printf.
58
59; CHECK-LABEL: _main:
60; CHECK: Lmain$frame_escape_0 = [[code_offs:[-0-9]+]]
61; CHECK: Lmain$frame_escape_1 = [[reg_offs:[-0-9]+]]
62; CHECK: movl %esp, [[reg_offs]](%ebp)
63; CHECK: movl $L__ehtable$main,
64; EH state 0
65; CHECK: movl $0, -4(%ebp)
66; CHECK: calll _crash
67; CHECK: retl
68; CHECK: # Block address taken
69; stackrestore
70; CHECK: movl [[reg_offs]](%ebp), %esp
71; EH state -1
72; CHECK: movl [[code_offs]](%ebp), %[[code:[a-z]+]]
73; CHECK: movl $-1, -4(%ebp)
74; CHECK-DAG: movl %[[code]], 4(%esp)
75; CHECK-DAG: movl $_str, (%esp)
76; CHECK: calll _printf
77
78; CHECK: .section .xdata,"dr"
79; CHECK: L__ehtable$main
80; CHECK-NEXT: .long -1
81; CHECK-NEXT: .long _filt$main
82; CHECK-NEXT: .long Ltmp{{[0-9]+}}
83
84; CHECK-LABEL: _filt$main:
85; CHECK: movl