| Andrew Kaylor | 046f7b4 | 2015-04-28 21:54:14 +0000 | [diff] [blame] | 1 | ; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s |
| 2 | |
| 3 | ; This test is based on the following code: |
| 4 | ; |
| 5 | ; void test() |
| 6 | ; { |
| 7 | ; try { |
| 8 | ; Obj o; |
| 9 | ; may_throw(); |
| 10 | ; } catch (...) { |
| 11 | ; } |
| 12 | ; } |
| 13 | ; |
| 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 |
| 21 | ; the process |
| 22 | |
| 23 | |
| 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" |
| 27 | |
| 28 | %class.Obj = type { i8 } |
| 29 | |
| 30 | ; This just verifies that the function was processed by WinEHPrepare. |
| 31 | ; |
| 32 | ; CHECK-LABEL: define void @"\01?test@@YAXXZ"() |
| 33 | ; CHECK: entry: |
| 34 | ; CHECK: call void (...) @llvm.frameescape |
| 35 | ; CHECK: } |
| 36 | |
| 37 | ; Function Attrs: nounwind uwtable |
| 38 | define void @"\01?test@@YAXXZ"() #0 { |
| 39 | entry: |
| 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 |
| 45 | |
| 46 | invoke.cont: ; preds = %entry |
| 47 | call void @"\01??1Obj@@QEAA@XZ"(%class.Obj* %o) #3 |
| 48 | br label %try.cont |
| 49 | |
| 50 | lpad: ; preds = %entry |
| 51 | %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) |
| 52 | catch i8* null |
| 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 |
| 61 | br label %try.cont |
| 62 | |
| 63 | try.cont: ; preds = %catch, %invoke.cont |
| 64 | ret void |
| 65 | } |
| 66 | |
| 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*) |
| 69 | ; CHECK: entry: |
| 70 | ; CHECK: @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1, i32 0) |
| 71 | ; CHECK: call void @"\01??1Obj@@QEAA@XZ" |
| 72 | ; CHECK: ret void |
| 73 | ; CHECK: } |
| 74 | |
| 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*) |
| 77 | ; CHECK: entry: |
| 78 | ; CHECK-NOT: call void @"\01??1Obj@@QEAA@XZ" |
| 79 | ; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont) |
| 80 | ; CHECK: } |
| 81 | |
| 82 | |
| 83 | |
| 84 | declare void @"\01?may_throw@@YAXXZ"() #1 |
| 85 | |
| 86 | declare i32 @__CxxFrameHandler3(...) |
| 87 | |
| 88 | ; Function Attrs: nounwind |
| 89 | declare void @"\01??1Obj@@QEAA@XZ"(%class.Obj*) #2 |
| 90 | |
| 91 | ; Function Attrs: nounwind |
| 92 | declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #3 |
| 93 | |
| 94 | ; Function Attrs: nounwind |
| 95 | declare void @llvm.eh.endcatch() #3 |
| 96 | |
| 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 } |
| 101 | |
| 102 | !llvm.module.flags = !{!0} |
| 103 | !llvm.ident = !{!1} |
| 104 | |
| 105 | !0 = !{i32 1, !"PIC Level", i32 2} |
| 106 | !1 = !{!"clang version 3.7.0 (trunk 235779) (llvm/trunk 235769)"} |