blob: 1225faebdb83e35d98ab23ed0a67b5ed2d16c6dc [file] [log] [blame]
Zia Ansari30a02382016-02-15 23:44:13 +00001; RUN: llc -stack-symbol-ordering=0 -mtriple=i686-windows-msvc < %s | FileCheck %s
Reid Kleckner0a3f5f62015-07-08 18:09:39 +00002
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.localrecover(i8*, i8*, i32)
14declare void @llvm.localescape(...)
15declare i8* @llvm.x86.seh.recoverfp(i8*, i8*)
16
17define i32 @main() personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) {
18entry:
19 ; The EH code allocation is overaligned, triggering realignment.
20 %__exceptioncode = alloca i32, align 8
21 call void (...) @llvm.localescape(i32* %__exceptioncode)
22 invoke void @crash() #5
23 to label %__try.cont unwind label %lpad
24
25lpad: ; preds = %entry
David Majnemer8a1c45d2015-12-12 05:38:55 +000026 %cs1 = catchswitch within none [label %__except] unwind to caller
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000027
28__except: ; preds = %lpad
David Majnemer8a1c45d2015-12-12 05:38:55 +000029 %p = catchpad within %cs1 [i8* bitcast (i32 ()* @"filt$main" to i8*)]
Reid Klecknereb7cd6c2015-10-09 23:05:54 +000030 %code = load i32, i32* %__exceptioncode, align 4
David Majnemer3bb88c02015-12-15 21:27:27 +000031 %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @str, i32 0, i32 0), i32 %code) #4 [ "funclet"(token %p) ]
David Majnemer8a1c45d2015-12-12 05:38:55 +000032 catchret from %p to label %__try.cont
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000033
34__try.cont: ; preds = %entry, %__except
35 ret i32 0
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000036}
37
38define internal i32 @"filt$main"() {
39entry:
40 %ebp = tail call i8* @llvm.frameaddress(i32 1)
41 %parentfp = tail call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 ()* @main to i8*), i8* %ebp)
42 %code.i8 = tail call i8* @llvm.localrecover(i8* bitcast (i32 ()* @main to i8*), i8* %parentfp, i32 0)
43 %__exceptioncode = bitcast i8* %code.i8 to i32*
44 %info.addr = getelementptr inbounds i8, i8* %ebp, i32 -20
45 %0 = bitcast i8* %info.addr to i32***
46 %1 = load i32**, i32*** %0, align 4
47 %2 = load i32*, i32** %1, align 4
48 %3 = load i32, i32* %2, align 4
49 store i32 %3, i32* %__exceptioncode, align 4
50 ret i32 1
51}
52
53; Check that we can get the exception code from eax to the printf.
54
55; CHECK-LABEL: _main:
56; CHECK: Lmain$frame_escape_0 = [[code_offs:[-0-9]+]]
Reid Klecknerc20276d2015-11-17 21:10:25 +000057; CHECK: movl %esp, [[reg_offs:[-0-9]+]](%esi)
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000058; CHECK: movl $L__ehtable$main,
59; EH state 0
Hans Wennborg65969772016-03-30 23:38:01 +000060; CHECK: movl $0, 32(%esi)
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000061; CHECK: calll _crash
62; CHECK: retl
David Majnemer8a1c45d2015-12-12 05:38:55 +000063; CHECK: LBB0_[[lpbb:[0-9]+]]: # %__except
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000064; Restore ESP
65; CHECK: movl -24(%ebp), %esp
66; Restore ESI
Hans Wennborg65969772016-03-30 23:38:01 +000067; CHECK: leal -36(%ebp), %esi
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000068; Restore EBP
Hans Wennborg65969772016-03-30 23:38:01 +000069; CHECK: movl 4(%esi), %ebp
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000070; CHECK: movl [[code_offs]](%esi), %[[code:[a-z]+]]
Hans Wennborg65969772016-03-30 23:38:01 +000071; CHECK: pushl %[[code]]
72; CHECK: pushl $_str
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000073; CHECK: calll _printf
74
75; CHECK: .section .xdata,"dr"
Reid Klecknerc20276d2015-11-17 21:10:25 +000076; CHECK: Lmain$parent_frame_offset = [[reg_offs]]
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000077; CHECK: L__ehtable$main
78; CHECK-NEXT: .long -1
79; CHECK-NEXT: .long _filt$main
Reid Klecknereb7cd6c2015-10-09 23:05:54 +000080; CHECK-NEXT: .long LBB0_[[lpbb]]
Reid Kleckner0a3f5f62015-07-08 18:09:39 +000081
82; CHECK-LABEL: _filt$main:
83; CHECK: pushl %ebp
84; CHECK: movl %esp, %ebp
85; CHECK: movl (%ebp), %[[oldebp:[a-z]+]]
86; CHECK: movl -20(%[[oldebp]]), %[[ehinfo:[a-z]+]]
87; CHECK: movl (%[[ehinfo]]), %[[ehrec:[a-z]+]]
88; CHECK: movl (%[[ehrec]]), %[[ehcode:[a-z]+]]
89; CHECK: movl %[[ehcode]], {{.*}}(%{{.*}})