1 ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3 ; This test is based on the following code:
14 ; The purpose of this test is to verify that we create separate catch and
15 ; cleanup handlers. When compiling for the C++ 11 standard, this isn't
16 ; strictly necessary, since calling the destructor from the catch handler
17 ; would be logically equivalent to calling it from a cleanup handler.
18 ; However, if the -std=c++98 option is used, an exception in the cleanup
19 ; code should terminate the process (the MSVCRT runtime will do that) but
20 ; if the destructor is called from the catch handler, it wouldn't terminate
24 ; ModuleID = 'cppeh-mixed-catch-and-cleanup.cpp'
25 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
26 target triple = "x86_64-pc-windows-msvc"
28 %class.Obj = type { i8 }
30 ; This just verifies that the function was processed by WinEHPrepare.
32 ; CHECK-LABEL: define void @"\01?test@@YAXXZ"()
34 ; CHECK: call void (...) @llvm.localescape
37 ; Function Attrs: nounwind uwtable
38 define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
40 %o = alloca %class.Obj, align 1
41 %exn.slot = alloca i8*
42 %ehselector.slot = alloca i32
43 invoke void @"\01?may_throw@@YAXXZ"()
44 to label %invoke.cont unwind label %lpad
46 invoke.cont: ; preds = %entry
47 call void @"\01??1Obj@@QEAA@XZ"(%class.Obj* %o) #3
50 lpad: ; preds = %entry
51 %0 = landingpad { i8*, i32 }
53 %1 = extractvalue { i8*, i32 } %0, 0
54 store i8* %1, i8** %exn.slot
55 %2 = extractvalue { i8*, i32 } %0, 1
56 store i32 %2, i32* %ehselector.slot
57 call void @"\01??1Obj@@QEAA@XZ"(%class.Obj* %o) #3
58 %exn = load i8*, i8** %exn.slot
59 call void @llvm.eh.begincatch(i8* %exn, i8* null) #3
60 call void @llvm.eh.endcatch() #3
63 try.cont: ; preds = %catch, %invoke.cont
67 ; Verify that a cleanup handler was created and that it calls ~Obj().
68 ; CHECK-LABEL: define internal void @"\01?test@@YAXXZ.cleanup"(i8*, i8*)
70 ; CHECK: @llvm.localrecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0)
71 ; CHECK: call void @"\01??1Obj@@QEAA@XZ"
75 ; Verify that a catch handler was created and that it does not call ~Obj().
76 ; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*)
78 ; CHECK-NOT: call void @"\01??1Obj@@QEAA@XZ"
79 ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
84 declare void @"\01?may_throw@@YAXXZ"() #1
86 declare i32 @__CxxFrameHandler3(...)
88 ; Function Attrs: nounwind
89 declare void @"\01??1Obj@@QEAA@XZ"(%class.Obj*) #2
91 ; Function Attrs: nounwind
92 declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3
94 ; Function Attrs: nounwind
95 declare void @llvm.eh.endcatch() #3
97 attributes #0 = { nounwind 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" }
98 attributes #1 = { "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" }
99 attributes #2 = { 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" }
100 attributes #3 = { nounwind }
102 !llvm.module.flags = !{!0}
105 !0 = !{i32 1, !"PIC Level", i32 2}
106 !1 = !{!"clang version 3.7.0 (trunk 235779) (llvm/trunk 235769)"}