51ffe7bb3bd503f37078745d4dfabd2c9ee6d14f
[oota-llvm.git] / test / CodeGen / WinEH / seh-prepared-basic.ll
1 ; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s
2 ; RUN: llc -mtriple=x86_64-pc-windows-coreclr < %s | FileCheck %s
3
4 ; Test case based on this code:
5 ; extern "C" unsigned long _exception_code();
6 ; extern "C" int filt(unsigned long);
7 ; extern "C" void g();
8 ; extern "C" void do_except() {
9 ;   __try {
10 ;     g();
11 ;   } __except(filt(_exception_code())) {
12 ;   }
13 ; }
14
15 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
16
17 ; Function Attrs: uwtable
18 define void @do_except() #0 personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
19 entry:
20   call void (...) @llvm.localescape()
21   invoke void @g() #5
22           to label %__try.cont unwind label %lpad1
23
24 lpad1:                                            ; preds = %entry
25   %ehvals = landingpad { i8*, i32 }
26           catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@do_except@@" to i8*)
27   %recover = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@do_except@@" to i8*), i32 -1, i8* blockaddress(@do_except, %__try.cont))
28   indirectbr i8* %recover, [label %__try.cont]
29
30 __try.cont:                                       ; preds = %lpad1, %entry
31   ret void
32 }
33
34 ; CHECK-LABEL: do_except:
35 ; CHECK: .seh_handler __C_specific_handler
36 ; CHECK-NOT: jmpq *
37 ; CHECK: .seh_handlerdata
38 ; CHECK-NEXT: .text
39 ; CHECK: .seh_endproc
40 ; CHECK: .section .xdata,"dr"
41 ; CHECK-NEXT: .long 1
42 ; CHECK-NEXT: .long .Ltmp{{.*}}
43 ; CHECK-NEXT: .long .Ltmp{{.*}}
44 ; CHECK-NEXT: .long "?filt$0@0@do_except@@"@IMGREL
45 ; CHECK-NEXT: .long .Ltmp{{.*}}@IMGREL
46
47 ; Function Attrs: noinline nounwind
48 define internal i32 @"\01?filt$0@0@do_except@@"(i8* nocapture readonly %exception_pointers, i8* nocapture readnone %frame_pointer) #1 {
49 entry:
50   %0 = bitcast i8* %exception_pointers to i32**
51   %1 = load i32*, i32** %0, align 8
52   %2 = load i32, i32* %1, align 4
53   %call = tail call i32 @filt(i32 %2) #4
54   ret i32 %call
55 }
56
57 declare i32 @filt(i32) #2
58
59 declare void @g() #2
60
61 declare i32 @__C_specific_handler(...)
62
63 ; Function Attrs: nounwind readnone
64 declare i32 @llvm.eh.typeid.for(i8*) #3
65
66 ; Function Attrs: nounwind
67 declare i8* @llvm.eh.actions(...) #4
68
69 ; Function Attrs: nounwind
70 declare void @llvm.localescape(...) #4
71
72 ; Function Attrs: nounwind readnone
73 declare i8* @llvm.localrecover(i8*, i8*, i32) #3
74
75 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="do_except" }
76 attributes #1 = { noinline nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
77 attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
78 attributes #3 = { nounwind readnone }
79 attributes #4 = { nounwind }
80 attributes #5 = { noinline }
81
82 !llvm.module.flags = !{!0}
83 !llvm.ident = !{!1}
84
85 !0 = !{i32 1, !"PIC Level", i32 2}
86 !1 = !{!"clang version 3.7.0 "}