1
; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
3
; This test is based on the following code:
20
; ModuleID = 'cppeh-catch-and-throw.cpp'
21
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
22
target triple = "x86_64-pc-windows-msvc"
24
%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
25
%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
26
%eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
27
%eh.ThrowInfo = type { i32, i32, i32, i32 }
28
%class.Obj = type { i8 }
30
$"\01??_R0H@8" = comdat any
32
$"_CT??_R0H@84" = comdat any
38
@"\01??_7type_info@@6B@" = external constant i8*
39
@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
40
@__ImageBase = external constant i8
41
@"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
42
@_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
43
@_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
45
; This is just a minimal check to verify that main was handled by WinEHPrepare.
46
; CHECK: define void @"\01?test@@YAXXZ"()
48
; CHECK: call void (...) @llvm.localescape
49
; CHECK: invoke void @_CxxThrowException
52
; Function Attrs: uwtable
53
define void @"\01?test@@YAXXZ"() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
55
%o = alloca %class.Obj, align 1
56
%tmp = alloca i32, align 4
57
%exn.slot = alloca i8*
58
%ehselector.slot = alloca i32
59
store i32 1, i32* %tmp
60
%0 = bitcast i32* %tmp to i8*
61
invoke void @_CxxThrowException(i8* %0, %eh.ThrowInfo* @_TI1H) #3
62
to label %unreachable unwind label %lpad
64
lpad: ; preds = %entry
65
%1 = landingpad { i8*, i32 }
67
%2 = extractvalue { i8*, i32 } %1, 0
68
store i8* %2, i8** %exn.slot
69
%3 = extractvalue { i8*, i32 } %1, 1
70
store i32 %3, i32* %ehselector.slot
71
call void @"\01??1Obj@@QEAA@XZ"(%class.Obj* %o) #2
74
catch: ; preds = %lpad
75
%exn = load i8*, i8** %exn.slot
76
call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
77
invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #3
78
to label %unreachable unwind label %lpad1
80
lpad1: ; preds = %catch
81
%4 = landingpad { i8*, i32 }
83
%5 = extractvalue { i8*, i32 } %4, 0
84
store i8* %5, i8** %exn.slot
85
%6 = extractvalue { i8*, i32 } %4, 1
86
store i32 %6, i32* %ehselector.slot
87
call void @llvm.eh.endcatch() #2
90
try.cont: ; No predecessors!
93
eh.resume: ; preds = %lpad1
94
%exn2 = load i8*, i8** %exn.slot
95
%sel = load i32, i32* %ehselector.slot
96
%lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
97
%lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
98
resume { i8*, i32 } %lpad.val3
100
unreachable: ; preds = %catch, %entry
104
; Verify that we inserted a stub invoke into the outlined cleanup handler.
106
; CHECK-LABEL: define internal void @"\01?test@@YAXXZ.cleanup"(i8*, i8*)
108
; CHECK: call i8* @llvm.localrecover
109
; CHECK: call void @"\01??1Obj@@QEAA@XZ"
110
; CHECK: invoke void @llvm.donothing()
111
; CHECK: to label %[[SPLIT_LABEL:.+]] unwind label %[[LPAD_LABEL:.+]]
113
; CHECK: [[SPLIT_LABEL]]
115
; CHECK: [[LPAD_LABEL]]
116
; CHECK: landingpad { i8*, i32 }
121
declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
123
declare i32 @__CxxFrameHandler3(...)
125
; Function Attrs: nounwind
126
declare void @"\01??1Obj@@QEAA@XZ"(%class.Obj*) #1
128
; Function Attrs: nounwind
129
declare void @llvm.eh.begincatch(i8* nocapture, i8* nocapture) #2
131
; Function Attrs: nounwind
132
declare void @llvm.eh.endcatch() #2
134
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" }
135
attributes #1 = { 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" }
136
attributes #2 = { nounwind }
137
attributes #3 = { noreturn }
139
!llvm.module.flags = !{!0}
142
!0 = !{i32 1, !"PIC Level", i32 2}
143
!1 = !{!"clang version 3.7.0 (trunk 235214) (llvm/trunk 235213)"}