--- /dev/null
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test is based on the following code:
+;
+; void test()
+; {
+; try {
+; may_throw();
+; } catch (...) {
+; handle_exception();
+; }
+; }
+;
+; Parts of the IR have been hand-edited to simplify the test case.
+; The full IR will be restored when Windows C++ EH support is complete.
+
+; ModuleID = 'catch-all.cpp'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; Function Attrs: uwtable
+define void @_Z4testv() #0 {
+entry:
+ %exn.slot = alloca i8*
+ %ehselector.slot = alloca i32
+ invoke void @_Z9may_throwv()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ br label %try.cont
+
+lpad: ; preds = %entry
+ %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ catch i8* null
+ %tmp1 = extractvalue { i8*, i32 } %tmp, 0
+ store i8* %tmp1, i8** %exn.slot
+ %tmp2 = extractvalue { i8*, i32 } %tmp, 1
+ store i32 %tmp2, i32* %ehselector.slot
+ br label %catch
+
+catch: ; preds = %lpad
+ %exn = load i8*, i8** %exn.slot
+ call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
+ call void @_Z16handle_exceptionv()
+ br label %invoke.cont2
+
+invoke.cont2: ; preds = %catch
+ call void @llvm.eh.endcatch()
+ br label %try.cont
+
+try.cont: ; preds = %invoke.cont2, %invoke.cont
+ ret void
+}
+
+; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
+; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
+; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
+; CHECK: call void @_Z16handle_exceptionv()
+; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
+; CHECK: }
+
+declare void @_Z9may_throwv() #1
+
+declare i32 @__CxxFrameHandler3(...)
+
+declare void @llvm.eh.begincatch(i8*, i8*)
+
+declare void @_Z16handle_exceptionv() #1
+
+declare void @llvm.eh.endcatch()
+
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { noinline noreturn nounwind }
+attributes #3 = { nounwind }
+attributes #4 = { noreturn nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.7.0 (trunk 226027)"}
--- /dev/null
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test is based on the following code:
+;
+; void test()
+; {
+; try {
+; may_throw();
+; } catch (int i) {
+; handle_int(i);
+; }
+; }
+;
+; Parts of the IR have been hand-edited to simplify the test case.
+; The full IR will be restored when Windows C++ EH support is complete.
+
+;ModuleID = 'cppeh-catch-scalar.cpp'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; This is the structure that will get created for the frame allocation.
+; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, i32 }
+
+@_ZTIi = external constant i8*
+
+; The function entry will be rewritten like this.
+; CHECK: define void @_Z4testv() #0 {
+; CHECK: entry:
+; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24)
+; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
+; CHECK: %exn.slot = alloca i8*
+; CHECK: %ehselector.slot = alloca i32
+; CHECK-NOT: %i = alloca i32, align 4
+; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
+
+; Function Attrs: uwtable
+define void @_Z4testv() #0 {
+entry:
+ %exn.slot = alloca i8*
+ %ehselector.slot = alloca i32
+ %i = alloca i32, align 4
+ invoke void @_Z9may_throwv()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ br label %try.cont
+
+lpad: ; preds = %entry
+ %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ catch i8* bitcast (i8** @_ZTIi to i8*)
+ %tmp1 = extractvalue { i8*, i32 } %tmp, 0
+ store i8* %tmp1, i8** %exn.slot
+ %tmp2 = extractvalue { i8*, i32 } %tmp, 1
+ store i32 %tmp2, i32* %ehselector.slot
+ br label %catch.dispatch
+
+catch.dispatch: ; preds = %lpad
+ %sel = load i32, i32* %ehselector.slot
+ %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
+ %matches = icmp eq i32 %sel, %tmp3
+ br i1 %matches, label %catch, label %eh.resume
+
+catch: ; preds = %catch.dispatch
+ %exn11 = load i8*, i8** %exn.slot
+ %i.i8 = bitcast i32* %i to i8*
+ call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
+ %tmp7 = load i32, i32* %i, align 4
+ call void @_Z10handle_inti(i32 %tmp7)
+ br label %invoke.cont2
+
+invoke.cont2: ; preds = %catch
+ call void @llvm.eh.endcatch() #3
+ br label %try.cont
+
+try.cont: ; preds = %invoke.cont2, %invoke.cont
+ ret void
+
+eh.resume: ; preds = %catch.dispatch
+ %exn3 = load i8*, i8** %exn.slot
+ %sel4 = load i32, i32* %ehselector.slot
+ %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
+ %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
+ resume { i8*, i32 } %lpad.val5
+}
+
+; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
+; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
+; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
+; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
+; CHECK: %tmp7 = load i32, i32* %i, align 4
+; CHECK: call void @_Z10handle_inti(i32 %tmp7)
+; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
+; CHECK: }
+
+declare void @_Z9may_throwv() #1
+
+declare i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #2
+
+declare void @llvm.eh.begincatch(i8*, i8*)
+
+declare void @llvm.eh.endcatch()
+
+declare void @_Z10handle_inti(i32) #1
+
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
+attributes #3 = { nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}
--- /dev/null
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test is based on the following code:
+;
+; struct SomeData {
+; int a;
+; int b;
+; };
+;
+; void may_throw();
+; void does_not_throw(int i);
+; void dump(int *, int, SomeData&);
+;
+; void test() {
+; int NumExceptions = 0;
+; int ExceptionVal[10];
+; SomeData Data = { 0, 0 };
+;
+; for (int i = 0; i < 10; ++i) {
+; try {
+; may_throw();
+; Data.a += i;
+; }
+; catch (int e) {
+; ExceptionVal[NumExceptions] = e;
+; ++NumExceptions;
+; if (e == i)
+; Data.b += e;
+; else
+; Data.a += e;
+; }
+; does_not_throw(NumExceptions);
+; }
+; dump(ExceptionVal, NumExceptions, Data);
+; }
+
+; ModuleID = 'cppeh-frame-vars.cpp'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
+%struct.SomeData = type { i32, i32 }
+
+; This structure should be declared for the frame allocation block.
+; CHECK: %"struct.\01?test@@YAXXZ.ehdata" = type { i32, i8*, i32, i32, [10 x i32], i32, %struct.SomeData }
+
+$"\01??_R0H@8" = comdat any
+
+@"\01??_7type_info@@6B@" = external constant i8*
+@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
+
+; The function entry should be rewritten like this.
+; CHECK: define void @"\01?test@@YAXXZ"() #0 {
+; CHECK: entry:
+; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 80)
+; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
+; CHECK-NOT: %NumExceptions = alloca i32, align 4
+; CHECK: %NumExceptions = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
+; CHECK-NOT: %ExceptionVal = alloca [10 x i32], align 16
+; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
+; CHECK-NOT: %Data = alloca %struct.SomeData, align 4
+; CHECK: %Data = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
+; CHECK: %i = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: %exn.slot = alloca i8*
+; CHECK: %ehselector.slot = alloca i32
+; CHECK-NOT: %e = alloca i32, align 4
+; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
+
+; Function Attrs: uwtable
+define void @"\01?test@@YAXXZ"() #0 {
+entry:
+ %NumExceptions = alloca i32, align 4
+ %ExceptionVal = alloca [10 x i32], align 16
+ %Data = alloca %struct.SomeData, align 4
+ %i = alloca i32, align 4
+ %exn.slot = alloca i8*
+ %ehselector.slot = alloca i32
+ %e = alloca i32, align 4
+ store i32 0, i32* %NumExceptions, align 4
+ %tmp = bitcast %struct.SomeData* %Data to i8*
+ call void @llvm.memset(i8* %tmp, i8 0, i64 8, i32 4, i1 false)
+ store i32 0, i32* %i, align 4
+ br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+ %tmp1 = load i32, i32* %i, align 4
+ %cmp = icmp slt i32 %tmp1, 10
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ invoke void @"\01?may_throw@@YAXXZ"()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %for.body
+ %tmp2 = load i32, i32* %i, align 4
+ %a = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
+ %tmp3 = load i32, i32* %a, align 4
+ %add = add nsw i32 %tmp3, %tmp2
+ store i32 %add, i32* %a, align 4
+ br label %try.cont
+
+lpad: ; preds = %for.body
+ %tmp4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
+ %tmp5 = extractvalue { i8*, i32 } %tmp4, 0
+ store i8* %tmp5, i8** %exn.slot
+ %tmp6 = extractvalue { i8*, i32 } %tmp4, 1
+ store i32 %tmp6, i32* %ehselector.slot
+ br label %catch.dispatch
+
+catch.dispatch: ; preds = %lpad
+ %sel = load i32, i32* %ehselector.slot
+ %tmp7 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
+ %matches = icmp eq i32 %sel, %tmp7
+ br i1 %matches, label %catch, label %eh.resume
+
+catch: ; preds = %catch.dispatch
+ %exn = load i8*, i8** %exn.slot
+ %e.i8 = bitcast i32* %e to i8*
+ call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #1
+ %tmp11 = load i32, i32* %e, align 4
+ %tmp12 = load i32, i32* %NumExceptions, align 4
+ %idxprom = sext i32 %tmp12 to i64
+ %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
+ store i32 %tmp11, i32* %arrayidx, align 4
+ %tmp13 = load i32, i32* %NumExceptions, align 4
+ %inc = add nsw i32 %tmp13, 1
+ store i32 %inc, i32* %NumExceptions, align 4
+ %tmp14 = load i32, i32* %e, align 4
+ %tmp15 = load i32, i32* %i, align 4
+ %cmp1 = icmp eq i32 %tmp14, %tmp15
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then: ; preds = %catch
+ %tmp16 = load i32, i32* %e, align 4
+ %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
+ %tmp17 = load i32, i32* %b, align 4
+ %add2 = add nsw i32 %tmp17, %tmp16
+ store i32 %add2, i32* %b, align 4
+ br label %if.end
+
+if.else: ; preds = %catch
+ %tmp18 = load i32, i32* %e, align 4
+ %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
+ %tmp19 = load i32, i32* %a3, align 4
+ %add4 = add nsw i32 %tmp19, %tmp18
+ store i32 %add4, i32* %a3, align 4
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ call void @llvm.eh.endcatch() #1
+ br label %try.cont
+
+try.cont: ; preds = %if.end, %invoke.cont
+ %tmp20 = load i32, i32* %NumExceptions, align 4
+ call void @"\01?does_not_throw@@YAXH@Z"(i32 %tmp20)
+ br label %for.inc
+
+for.inc: ; preds = %try.cont
+ %tmp21 = load i32, i32* %i, align 4
+ %inc5 = add nsw i32 %tmp21, 1
+ store i32 %inc5, i32* %i, align 4
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ %tmp22 = load i32, i32* %NumExceptions, align 4
+ %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i32 0
+ call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %tmp22, %struct.SomeData* dereferenceable(8) %Data)
+ ret void
+
+eh.resume: ; preds = %catch.dispatch
+ %exn6 = load i8*, i8** %exn.slot
+ %sel7 = load i32, i32* %ehselector.slot
+ %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn6, 0
+ %lpad.val8 = insertvalue { i8*, i32 } %lpad.val, i32 %sel7, 1
+ resume { i8*, i32 } %lpad.val8
+}
+
+; The following catch handler should be outlined.
+; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
+; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
+; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
+; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
+; CHECK: %NumExceptions = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
+; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
+; CHECK: %i = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: %Data = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
+; CHECK: %tmp11 = load i32, i32* %e, align 4
+; CHECK: %tmp12 = load i32, i32* %NumExceptions, align 4
+; CHECK: %idxprom = sext i32 %tmp12 to i64
+; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
+; CHECK: store i32 %tmp11, i32* %arrayidx, align 4
+; CHECK: %tmp13 = load i32, i32* %NumExceptions, align 4
+; CHECK: %inc = add nsw i32 %tmp13, 1
+; CHECK: store i32 %inc, i32* %NumExceptions, align 4
+; CHECK: %tmp14 = load i32, i32* %e, align 4
+; CHECK: %tmp15 = load i32, i32* %i, align 4
+; CHECK: %cmp1 = icmp eq i32 %tmp14, %tmp15
+; CHECK: br i1 %cmp1, label %if.then, label %if.else
+;
+; CHECK: if.then: ; preds = %entry
+; CHECK: %tmp16 = load i32, i32* %e, align 4
+; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
+; CHECK: %tmp17 = load i32, i32* %b, align 4
+; CHECK: %add2 = add nsw i32 %tmp17, %tmp16
+; CHECK: store i32 %add2, i32* %b, align 4
+; CHECK: br label %if.end
+;
+; CHECK: if.else: ; preds = %entry
+; CHECK: %tmp18 = load i32, i32* %e, align 4
+; CHECK: %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
+; CHECK: %tmp19 = load i32, i32* %a3, align 4
+; CHECK: %add4 = add nsw i32 %tmp19, %tmp18
+; CHECK: store i32 %add4, i32* %a3, align 4
+; CHECK: br label %if.end
+;
+; CHECK: if.end: ; preds = %if.else, %if.then
+; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
+; CHECK: }
+
+
+
+
+
+
+; Function Attrs: nounwind
+declare void @llvm.memset(i8* nocapture, i8, i64, i32, i1) #1
+
+declare void @"\01?may_throw@@YAXXZ"() #2
+
+declare i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #3
+
+declare void @llvm.eh.begincatch(i8*, i8*)
+
+declare void @llvm.eh.endcatch()
+
+declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
+
+declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
+
+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" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind }
+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" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { nounwind readnone }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
+!1 = !{!"clang version 3.7.0 (trunk 228868)"}
--- /dev/null
+; RUN: opt -mtriple=i386-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test is built from the following code:
+; struct A {
+; A(int a);
+; A(const A &o);
+; ~A();
+; int a;
+; };
+;
+; void may_throw();
+;
+; int test(A a) {
+; try {
+; may_throw();
+; }
+; catch (int e) {
+; return a.a + e;
+; }
+; return 0;
+; }
+;
+; The test was built for a 32-bit Windows target and then the reference to
+; the inalloca instruction was manually sunk into the landingpad.
+
+; ModuleID = 'cppeh-inalloca.cpp'
+target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
+target triple = "i386-pc-windows-msvc"
+
+%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
+%struct.A = type { i32 }
+
+$"\01??_R0H@8" = comdat any
+
+@"\01??_7type_info@@6B@" = external constant i8*
+@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
+
+; The function entry should be rewritten like this.
+; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
+; CHECK: entry:
+; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24)
+; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAHUA@@@Z.ehdata"*
+; CHECK: %.tmp.reg2mem = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 3
+; CHECK: %.tmp = select i1 true, <{ %struct.A }>* %0, <{ %struct.A }>* undef
+; CHECK: store <{ %struct.A }>* %.tmp, <{ %struct.A }>** %.tmp.reg2mem
+; CHECK-NOT: %retval = alloca i32, align 4
+; CHECK: %retval = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 4
+; CHECK: %exn.slot = alloca i8*
+; CHECK: %ehselector.slot = alloca i32
+; CHECK-NOT: %e = alloca i32, align 4
+; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 2
+; CHECK: %cleanup.dest.slot = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
+; CHECK: to label %invoke.cont unwind label %lpad
+
+define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
+entry:
+ %retval = alloca i32, align 4
+ %exn.slot = alloca i8*
+ %ehselector.slot = alloca i32
+ %e = alloca i32, align 4
+ %cleanup.dest.slot = alloca i32
+ invoke void @"\01?may_throw@@YAXXZ"()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ br label %try.cont
+
+lpad: ; preds = %entry
+ %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ cleanup
+ catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
+ %2 = extractvalue { i8*, i32 } %1, 0
+ store i8* %2, i8** %exn.slot
+ %3 = extractvalue { i8*, i32 } %1, 1
+ store i32 %3, i32* %ehselector.slot
+ br label %catch.dispatch
+
+catch.dispatch: ; preds = %lpad
+ %sel = load i32, i32* %ehselector.slot
+ %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
+ %matches = icmp eq i32 %sel, %4
+ br i1 %matches, label %catch, label %ehcleanup
+
+catch: ; preds = %catch.dispatch
+ %exn = load i8*, i8** %exn.slot
+ %e.i8 = bitcast i32* %e to i8*
+ call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
+ %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
+ %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
+ %tmp8 = load i32, i32* %a1, align 4
+ %tmp9 = load i32, i32* %e, align 4
+ %add = add nsw i32 %tmp8, %tmp9
+ store i32 %add, i32* %retval
+ store i32 1, i32* %cleanup.dest.slot
+ call void @llvm.eh.endcatch() #3
+ br label %cleanup
+
+try.cont: ; preds = %invoke.cont
+ store i32 0, i32* %retval
+ store i32 1, i32* %cleanup.dest.slot
+ br label %cleanup
+
+; The cleanup block should be re-written like this.
+; CHECK: cleanup: ; preds = %try.cont, %catch
+; CHECK-NOT: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
+; CHECK: %.tmp.reload1 = load volatile <{ %struct.A }>*, <{ %struct.A }>** %.tmp.reg2mem
+; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.tmp.reload1, i32 0, i32 0
+; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #2
+; CHECK: %tmp10 = load i32, i32* %retval
+; CHECK: ret i32 %tmp10
+
+cleanup: ; preds = %try.cont, %catch
+ %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
+ call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
+ %tmp10 = load i32, i32* %retval
+ ret i32 %tmp10
+
+ehcleanup: ; preds = %catch.dispatch
+ %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
+ call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
+ br label %eh.resume
+
+eh.resume: ; preds = %ehcleanup
+ %exn2 = load i8*, i8** %exn.slot
+ %sel3 = load i32, i32* %ehselector.slot
+ %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
+ %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
+ resume { i8*, i32 } %lpad.val4
+}
+
+; The following catch handler should be outlined.
+; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAHUA@@@Z.ehdata"*
+; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 1
+; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
+; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 2
+; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 3
+; CHECK: %.reload = load <{ %struct.A }>*, <{ %struct.A }>** %eh.temp.alloca
+; CHECK: %retval = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 4
+; CHECK: %cleanup.dest.slot = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.reload, i32 0, i32 0
+; CHECK: %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
+; CHECK: %tmp8 = load i32, i32* %a1, align 4
+; CHECK: %tmp9 = load i32, i32* %e, align 4
+; CHECK: %add = add nsw i32 %tmp8, %tmp9
+; CHECK: store i32 %add, i32* %retval
+; CHECK: store i32 1, i32* %cleanup.dest.slot
+; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
+; CHECK: }
+
+
+declare void @"\01?may_throw@@YAXXZ"() #0
+
+declare i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #1
+
+declare void @llvm.eh.begincatch(i8*, i8*)
+
+declare void @llvm.eh.endcatch()
+
+; Function Attrs: nounwind
+declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
+
+attributes #0 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone }
+attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.7.0 (trunk 228868)"}
--- /dev/null
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test was generated from the following source:
+;
+; class SomeClass {
+; public:
+; SomeClass();
+; ~SomeClass();
+; };
+;
+; void test() {
+; SomeClass obj;
+; may_throw();
+; }
+
+
+; ModuleID = 'min-unwind.cpp'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+; This structure should be created for the frame allocation.
+; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, %class.SomeClass }
+
+%class.SomeClass = type { [28 x i32] }
+
+; The function entry should be rewritten like this.
+; CHECK: define void @_Z4testv() #0 {
+; CHECK: entry:
+; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 128)
+; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
+; CHECK-NOT: %obj = alloca %class.SomeClass, align 4
+; CHECK: %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
+
+; Function Attrs: uwtable
+define void @_Z4testv() #0 {
+entry:
+ %obj = alloca %class.SomeClass, align 4
+ %exn.slot = alloca i8*
+ %ehselector.slot = alloca i32
+ call void @_ZN9SomeClassC1Ev(%class.SomeClass* %obj)
+ invoke void @_Z9may_throwv()
+ to label %invoke.cont unwind label %lpad
+
+invoke.cont: ; preds = %entry
+ call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
+ ret void
+
+lpad: ; preds = %entry
+ %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ cleanup
+ %tmp1 = extractvalue { i8*, i32 } %tmp, 0
+ store i8* %tmp1, i8** %exn.slot
+ %tmp2 = extractvalue { i8*, i32 } %tmp, 1
+ store i32 %tmp2, i32* %ehselector.slot
+ call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
+ br label %eh.resume
+
+eh.resume: ; preds = %lpad
+ %exn = load i8*, i8** %exn.slot
+ %sel = load i32, i32* %ehselector.slot
+ %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
+ %lpad.val2 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
+ resume { i8*, i32 } %lpad.val2
+}
+
+; This cleanup handler should be outlined.
+; CHECK: define internal void @_Z4testv.cleanup(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
+; CHECK: %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
+; CHECK: call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
+; CHECK: ret void
+; CHECK: }
+
+declare void @_ZN9SomeClassC1Ev(%class.SomeClass*) #1
+
+declare void @_Z9may_throwv() #1
+
+declare i32 @__CxxFrameHandler3(...)
+
+declare void @_ZN9SomeClassD1Ev(%class.SomeClass*) #1
+
+attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { noinline noreturn nounwind }
+attributes #3 = { noreturn nounwind }
+attributes #4 = { nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.7.0 (trunk 226027)"}
--- /dev/null
+; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
+
+; This test is based on the following code:
+;
+; struct SomeData {
+; int a;
+; int b;
+; };
+;
+; void may_throw();
+; void does_not_throw(int i);
+; void dump(int *, int, SomeData&);
+;
+; void test() {
+; int NumExceptions = 0;
+; int ExceptionVal[10];
+; SomeData Data = { 0, 0 };
+;
+; for (int i = 0; i < 10; ++i) {
+; try {
+; may_throw();
+; Data.a += i;
+; }
+; catch (int e) {
+; ExceptionVal[NumExceptions] = e;
+; ++NumExceptions;
+; if (e == i)
+; Data.b += e;
+; else
+; Data.a += e;
+; }
+; does_not_throw(NumExceptions);
+; }
+; dump(ExceptionVal, NumExceptions, Data);
+; }
+;
+; Unlike the cppeh-frame-vars.ll test, this test was generated using -O2
+; optimization, which results in non-alloca values being used in the
+; catch handler.
+
+; ModuleID = 'cppeh-frame-vars.cpp'
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
+%struct.SomeData = type { i32, i32 }
+
+$"\01??_R0H@8" = comdat any
+
+@"\01??_7type_info@@6B@" = external constant i8*
+@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
+
+; This structure should be declared for the frame allocation block.
+; CHECK: %"struct.\01?test@@YAXXZ.ehdata" = type { i32, i8*, i32, i32, [10 x i32], i32, i32*, i32* }
+
+; The function entry should be rewritten like this.
+; CHECK: define void @"\01?test@@YAXXZ"() #0 {
+; CHECK: entry:
+; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 88)
+; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
+; CHECK-NOT: %ExceptionVal = alloca [10 x i32], align 16
+; CHECK: %NumExceptions.020.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
+; CHECK: %i.019.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
+; CHECK: %Data = alloca i64, align 8
+; CHECK: %tmpcast = bitcast i64* %Data to %struct.SomeData*
+; CHECK: %0 = bitcast [10 x i32]* %ExceptionVal to i8*
+; CHECK: call void @llvm.lifetime.start(i64 40, i8* %0) #1
+; CHECK: store i64 0, i64* %Data, align 8
+; CHECK: %a.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
+; CHECK: %a = bitcast i64* %Data to i32*
+; CHECK: store i32* %a, i32** %a.reg2mem
+; CHECK: %b.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
+; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
+; CHECK: store i32* %b, i32** %b.reg2mem
+; CHECK: store i32 0, i32* %NumExceptions.020.reg2mem
+; CHECK: store i32 0, i32* %i.019.reg2mem
+; CHECK: br label %for.body
+
+; Function Attrs: uwtable
+define void @"\01?test@@YAXXZ"() #0 {
+entry:
+ %e = alloca i32, align 4
+ %ExceptionVal = alloca [10 x i32], align 16
+ %Data = alloca i64, align 8
+ %tmpcast = bitcast i64* %Data to %struct.SomeData*
+ %0 = bitcast [10 x i32]* %ExceptionVal to i8*
+ call void @llvm.lifetime.start(i64 40, i8* %0) #1
+ store i64 0, i64* %Data, align 8
+ %a = bitcast i64* %Data to i32*
+ %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
+ br label %for.body
+
+; CHECK: for.body:
+; CHECK-NOT: %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
+; CHECK-NOT: %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
+; CHECK: %i.019.reload = load i32, i32* %i.019.reg2mem
+; CHECK: %NumExceptions.020.reload = load i32, i32* %NumExceptions.020.reg2mem
+for.body: ; preds = %entry, %try.cont
+ %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
+ %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
+ invoke void @"\01?may_throw@@YAXXZ"()
+ to label %invoke.cont unwind label %lpad
+
+; CHECK: invoke.cont: ; preds = %for.body
+; CHECK-NOT: %1 = load i32, i32* %a, align 8, !tbaa !2
+; CHECK-NOT: %add = add nsw i32 %1, %i.019
+; CHECK-NOT: store i32 %add, i32* %a, align 8, !tbaa !2
+; CHECK: %a.reload3 = load volatile i32*, i32** %a.reg2mem
+; CHECK: %1 = load i32, i32* %a.reload3, align 8, !tbaa !2
+; CHECK: %add = add nsw i32 %1, %i.019.reload
+; CHECK: %a.reload2 = load volatile i32*, i32** %a.reg2mem
+; CHECK: store i32 %add, i32* %a.reload2, align 8, !tbaa !2
+; CHECK: br label %try.cont
+invoke.cont: ; preds = %for.body
+ %1 = load i32, i32* %a, align 8, !tbaa !2
+ %add = add nsw i32 %1, %i.019
+ store i32 %add, i32* %a, align 8, !tbaa !2
+ br label %try.cont
+
+lpad: ; preds = %for.body
+ %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
+ catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
+ %3 = extractvalue { i8*, i32 } %2, 1
+ %4 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
+ %matches = icmp eq i32 %3, %4
+ br i1 %matches, label %catch, label %eh.resume
+
+catch: ; preds = %lpad
+ %5 = extractvalue { i8*, i32 } %2, 0
+ %e.i8 = bitcast i32* %e to i8*
+ call void @llvm.eh.begincatch(i8* %5, i8* %e.i8) #1
+ %tmp8 = load i32, i32* %e, align 4, !tbaa !7
+ %idxprom = sext i32 %NumExceptions.020 to i64
+ %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
+ store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
+ %inc = add nsw i32 %NumExceptions.020, 1
+ %cmp1 = icmp eq i32 %tmp8, %i.019
+ br i1 %cmp1, label %if.then, label %if.else
+
+if.then: ; preds = %catch
+ %tmp9 = load i32, i32* %b, align 4, !tbaa !8
+ %add2 = add nsw i32 %tmp9, %i.019
+ store i32 %add2, i32* %b, align 4, !tbaa !8
+ br label %if.end
+
+if.else: ; preds = %catch
+ %tmp10 = load i32, i32* %a, align 8, !tbaa !2
+ %add4 = add nsw i32 %tmp10, %tmp8
+ store i32 %add4, i32* %a, align 8, !tbaa !2
+ br label %if.end
+
+if.end: ; preds = %if.else, %if.then
+ tail call void @llvm.eh.endcatch() #1
+ br label %try.cont
+
+; CHECK: try.cont: ; preds = %if.end, %invoke.cont
+; CHECK-NOT: %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
+; CHECK: %NumExceptions.1 = phi i32 [ %NumExceptions.020.reload, %invoke.cont ], [ %inc, %if.end ]
+; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
+; CHECK-NOT: %inc5 = add nuw nsw i32 %i.019, 1
+; CHECK: %inc5 = add nuw nsw i32 %i.019.reload, 1
+; CHECK: %cmp = icmp slt i32 %inc5, 10
+; CHECK: store i32 %NumExceptions.1, i32* %NumExceptions.020.reg2mem
+; CHECK: store i32 %inc5, i32* %i.019.reg2mem
+; CHECK: br i1 %cmp, label %for.body, label %for.end
+
+try.cont: ; preds = %if.end, %invoke.cont
+ %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
+ tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
+ %inc5 = add nuw nsw i32 %i.019, 1
+ %cmp = icmp slt i32 %inc5, 10
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %try.cont
+ %NumExceptions.1.lcssa = phi i32 [ %NumExceptions.1, %try.cont ]
+ %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 0
+ call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %NumExceptions.1.lcssa, %struct.SomeData* dereferenceable(8) %tmpcast)
+ call void @llvm.lifetime.end(i64 40, i8* %0) #1
+ ret void
+
+eh.resume: ; preds = %lpad
+ %.lcssa = phi { i8*, i32 } [ %2, %lpad ]
+ resume { i8*, i32 } %.lcssa
+}
+
+; The following catch handler should be outlined.
+; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
+; CHECK: entry:
+; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
+; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
+; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
+; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
+; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
+; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
+; CHECK: %NumExceptions.020.reload = load i32, i32* %eh.temp.alloca
+; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
+; CHECK: %eh.temp.alloca1 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
+; CHECK: %i.019.reload = load i32, i32* %eh.temp.alloca1
+; CHECK: %eh.temp.alloca2 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
+; CHECK: %a.reload = load i32*, i32** %eh.temp.alloca2
+; CHECK: %eh.temp.alloca3 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
+; CHECK: %b.reload = load i32*, i32** %eh.temp.alloca3
+; CHECK: %e.i8 = bitcast i32* %e to i8*
+; CHECK: %tmp8 = load i32, i32* %e, align 4, !tbaa !7
+; CHECK: %idxprom = sext i32 %NumExceptions.020.reload to i64
+; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
+; CHECK: store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
+; CHECK: %inc = add nsw i32 %NumExceptions.020.reload, 1
+; CHECK: %cmp1 = icmp eq i32 %tmp8, %i.019.reload
+; CHECK: br i1 %cmp1, label %if.then, label %if.else
+;
+; CHECK: if.then: ; preds = %entry
+; CHECK: %tmp9 = load i32, i32* %b.reload, align 4, !tbaa !8
+; CHECK: %add2 = add nsw i32 %tmp9, %i.019.reload
+; CHECK: store i32 %add2, i32* %b.reload, align 4, !tbaa !8
+; CHECK: br label %if.end
+;
+; CHECK: if.else: ; preds = %entry
+; CHECK: %tmp10 = load i32, i32* %a.reload, align 8, !tbaa !2
+; CHECK: %add4 = add nsw i32 %tmp10, %tmp8
+; CHECK: store i32 %add4, i32* %a.reload, align 8, !tbaa !2
+; CHECK: br label %if.end
+;
+; CHECK: if.end: ; preds = %if.else, %if.then
+; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
+; CHECK: }
+
+; Function Attrs: nounwind
+declare void @llvm.lifetime.start(i64, i8* nocapture) #1
+
+declare void @"\01?may_throw@@YAXXZ"() #2
+
+declare i32 @__CxxFrameHandler3(...)
+
+; Function Attrs: nounwind readnone
+declare i32 @llvm.eh.typeid.for(i8*) #3
+
+declare void @llvm.eh.begincatch(i8*, i8*)
+
+declare void @llvm.eh.endcatch()
+
+declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
+
+declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
+
+; Function Attrs: nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture) #1
+
+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" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind }
+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" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #3 = { nounwind readnone }
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"PIC Level", i32 2}
+!1 = !{!"clang version 3.7.0 (trunk 228868)"}
+!2 = !{!3, !4, i64 0}
+!3 = !{!"?AUSomeData@@", !4, i64 0, !4, i64 4}
+!4 = !{!"int", !5, i64 0}
+!5 = !{!"omnipotent char", !6, i64 0}
+!6 = !{!"Simple C/C++ TBAA"}
+!7 = !{!4, !4, i64 0}
+!8 = !{!3, !4, i64 4}
--- /dev/null
+# FIXME: For now, override suffixes to exclude any .s tests, because some of the
+# buildbots have a stray misched-copy.s output file lying around that causes
+# failures. See misched-copy.s where we try and clean up that file.
+#
+# It should be possible to remove this override once all the bots have cycled
+# cleanly.
+config.suffixes = ['.ll', '.test', '.txt']
+
+# FIXME: Add Windows on ARM support to these tests.
+if not 'X86' in config.root.targets:
+ config.unsupported = True
+
+++ /dev/null
-; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test is based on the following code:
-;
-; void test()
-; {
-; try {
-; may_throw();
-; } catch (...) {
-; handle_exception();
-; }
-; }
-;
-; Parts of the IR have been hand-edited to simplify the test case.
-; The full IR will be restored when Windows C++ EH support is complete.
-
-; ModuleID = 'catch-all.cpp'
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-; Function Attrs: uwtable
-define void @_Z4testv() #0 {
-entry:
- %exn.slot = alloca i8*
- %ehselector.slot = alloca i32
- invoke void @_Z9may_throwv()
- to label %invoke.cont unwind label %lpad
-
-invoke.cont: ; preds = %entry
- br label %try.cont
-
-lpad: ; preds = %entry
- %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- catch i8* null
- %tmp1 = extractvalue { i8*, i32 } %tmp, 0
- store i8* %tmp1, i8** %exn.slot
- %tmp2 = extractvalue { i8*, i32 } %tmp, 1
- store i32 %tmp2, i32* %ehselector.slot
- br label %catch
-
-catch: ; preds = %lpad
- %exn = load i8*, i8** %exn.slot
- call void @llvm.eh.begincatch(i8* %exn, i8* null) #2
- call void @_Z16handle_exceptionv()
- br label %invoke.cont2
-
-invoke.cont2: ; preds = %catch
- call void @llvm.eh.endcatch()
- br label %try.cont
-
-try.cont: ; preds = %invoke.cont2, %invoke.cont
- ret void
-}
-
-; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
-; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
-; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
-; CHECK: call void @_Z16handle_exceptionv()
-; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
-; CHECK: }
-
-declare void @_Z9may_throwv() #1
-
-declare i32 @__CxxFrameHandler3(...)
-
-declare void @llvm.eh.begincatch(i8*, i8*)
-
-declare void @_Z16handle_exceptionv() #1
-
-declare void @llvm.eh.endcatch()
-
-attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #2 = { noinline noreturn nounwind }
-attributes #3 = { nounwind }
-attributes #4 = { noreturn nounwind }
-
-!llvm.ident = !{!0}
-
-!0 = !{!"clang version 3.7.0 (trunk 226027)"}
+++ /dev/null
-; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test is based on the following code:
-;
-; void test()
-; {
-; try {
-; may_throw();
-; } catch (int i) {
-; handle_int(i);
-; }
-; }
-;
-; Parts of the IR have been hand-edited to simplify the test case.
-; The full IR will be restored when Windows C++ EH support is complete.
-
-;ModuleID = 'cppeh-catch-scalar.cpp'
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-; This is the structure that will get created for the frame allocation.
-; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, i32 }
-
-@_ZTIi = external constant i8*
-
-; The function entry will be rewritten like this.
-; CHECK: define void @_Z4testv() #0 {
-; CHECK: entry:
-; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24)
-; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
-; CHECK: %exn.slot = alloca i8*
-; CHECK: %ehselector.slot = alloca i32
-; CHECK-NOT: %i = alloca i32, align 4
-; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
-
-; Function Attrs: uwtable
-define void @_Z4testv() #0 {
-entry:
- %exn.slot = alloca i8*
- %ehselector.slot = alloca i32
- %i = alloca i32, align 4
- invoke void @_Z9may_throwv()
- to label %invoke.cont unwind label %lpad
-
-invoke.cont: ; preds = %entry
- br label %try.cont
-
-lpad: ; preds = %entry
- %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- catch i8* bitcast (i8** @_ZTIi to i8*)
- %tmp1 = extractvalue { i8*, i32 } %tmp, 0
- store i8* %tmp1, i8** %exn.slot
- %tmp2 = extractvalue { i8*, i32 } %tmp, 1
- store i32 %tmp2, i32* %ehselector.slot
- br label %catch.dispatch
-
-catch.dispatch: ; preds = %lpad
- %sel = load i32, i32* %ehselector.slot
- %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #3
- %matches = icmp eq i32 %sel, %tmp3
- br i1 %matches, label %catch, label %eh.resume
-
-catch: ; preds = %catch.dispatch
- %exn11 = load i8*, i8** %exn.slot
- %i.i8 = bitcast i32* %i to i8*
- call void @llvm.eh.begincatch(i8* %exn11, i8* %i.i8) #3
- %tmp7 = load i32, i32* %i, align 4
- call void @_Z10handle_inti(i32 %tmp7)
- br label %invoke.cont2
-
-invoke.cont2: ; preds = %catch
- call void @llvm.eh.endcatch() #3
- br label %try.cont
-
-try.cont: ; preds = %invoke.cont2, %invoke.cont
- ret void
-
-eh.resume: ; preds = %catch.dispatch
- %exn3 = load i8*, i8** %exn.slot
- %sel4 = load i32, i32* %ehselector.slot
- %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn3, 0
- %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
- resume { i8*, i32 } %lpad.val5
-}
-
-; CHECK: define internal i8* @_Z4testv.catch(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
-; CHECK: %eh.obj.ptr = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 1
-; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
-; CHECK: %i = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
-; CHECK: %tmp7 = load i32, i32* %i, align 4
-; CHECK: call void @_Z10handle_inti(i32 %tmp7)
-; CHECK: ret i8* blockaddress(@_Z4testv, %try.cont)
-; CHECK: }
-
-declare void @_Z9may_throwv() #1
-
-declare i32 @__CxxFrameHandler3(...)
-
-; Function Attrs: nounwind readnone
-declare i32 @llvm.eh.typeid.for(i8*) #2
-
-declare void @llvm.eh.begincatch(i8*, i8*)
-
-declare void @llvm.eh.endcatch()
-
-declare void @_Z10handle_inti(i32) #1
-
-attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #2 = { nounwind readnone }
-attributes #3 = { nounwind }
-
-!llvm.ident = !{!0}
-
-!0 = !{!"clang version 3.7.0 (trunk 227474) (llvm/trunk 227508)"}
+++ /dev/null
-; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test is based on the following code:
-;
-; struct SomeData {
-; int a;
-; int b;
-; };
-;
-; void may_throw();
-; void does_not_throw(int i);
-; void dump(int *, int, SomeData&);
-;
-; void test() {
-; int NumExceptions = 0;
-; int ExceptionVal[10];
-; SomeData Data = { 0, 0 };
-;
-; for (int i = 0; i < 10; ++i) {
-; try {
-; may_throw();
-; Data.a += i;
-; }
-; catch (int e) {
-; ExceptionVal[NumExceptions] = e;
-; ++NumExceptions;
-; if (e == i)
-; Data.b += e;
-; else
-; Data.a += e;
-; }
-; does_not_throw(NumExceptions);
-; }
-; dump(ExceptionVal, NumExceptions, Data);
-; }
-
-; ModuleID = 'cppeh-frame-vars.cpp'
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
-%struct.SomeData = type { i32, i32 }
-
-; This structure should be declared for the frame allocation block.
-; CHECK: %"struct.\01?test@@YAXXZ.ehdata" = type { i32, i8*, i32, i32, [10 x i32], i32, %struct.SomeData }
-
-$"\01??_R0H@8" = comdat any
-
-@"\01??_7type_info@@6B@" = external constant i8*
-@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
-
-; The function entry should be rewritten like this.
-; CHECK: define void @"\01?test@@YAXXZ"() #0 {
-; CHECK: entry:
-; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 80)
-; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
-; CHECK-NOT: %NumExceptions = alloca i32, align 4
-; CHECK: %NumExceptions = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
-; CHECK-NOT: %ExceptionVal = alloca [10 x i32], align 16
-; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
-; CHECK-NOT: %Data = alloca %struct.SomeData, align 4
-; CHECK: %Data = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
-; CHECK: %i = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: %exn.slot = alloca i8*
-; CHECK: %ehselector.slot = alloca i32
-; CHECK-NOT: %e = alloca i32, align 4
-; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
-
-; Function Attrs: uwtable
-define void @"\01?test@@YAXXZ"() #0 {
-entry:
- %NumExceptions = alloca i32, align 4
- %ExceptionVal = alloca [10 x i32], align 16
- %Data = alloca %struct.SomeData, align 4
- %i = alloca i32, align 4
- %exn.slot = alloca i8*
- %ehselector.slot = alloca i32
- %e = alloca i32, align 4
- store i32 0, i32* %NumExceptions, align 4
- %tmp = bitcast %struct.SomeData* %Data to i8*
- call void @llvm.memset(i8* %tmp, i8 0, i64 8, i32 4, i1 false)
- store i32 0, i32* %i, align 4
- br label %for.cond
-
-for.cond: ; preds = %for.inc, %entry
- %tmp1 = load i32, i32* %i, align 4
- %cmp = icmp slt i32 %tmp1, 10
- br i1 %cmp, label %for.body, label %for.end
-
-for.body: ; preds = %for.cond
- invoke void @"\01?may_throw@@YAXXZ"()
- to label %invoke.cont unwind label %lpad
-
-invoke.cont: ; preds = %for.body
- %tmp2 = load i32, i32* %i, align 4
- %a = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
- %tmp3 = load i32, i32* %a, align 4
- %add = add nsw i32 %tmp3, %tmp2
- store i32 %add, i32* %a, align 4
- br label %try.cont
-
-lpad: ; preds = %for.body
- %tmp4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
- %tmp5 = extractvalue { i8*, i32 } %tmp4, 0
- store i8* %tmp5, i8** %exn.slot
- %tmp6 = extractvalue { i8*, i32 } %tmp4, 1
- store i32 %tmp6, i32* %ehselector.slot
- br label %catch.dispatch
-
-catch.dispatch: ; preds = %lpad
- %sel = load i32, i32* %ehselector.slot
- %tmp7 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
- %matches = icmp eq i32 %sel, %tmp7
- br i1 %matches, label %catch, label %eh.resume
-
-catch: ; preds = %catch.dispatch
- %exn = load i8*, i8** %exn.slot
- %e.i8 = bitcast i32* %e to i8*
- call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #1
- %tmp11 = load i32, i32* %e, align 4
- %tmp12 = load i32, i32* %NumExceptions, align 4
- %idxprom = sext i32 %tmp12 to i64
- %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
- store i32 %tmp11, i32* %arrayidx, align 4
- %tmp13 = load i32, i32* %NumExceptions, align 4
- %inc = add nsw i32 %tmp13, 1
- store i32 %inc, i32* %NumExceptions, align 4
- %tmp14 = load i32, i32* %e, align 4
- %tmp15 = load i32, i32* %i, align 4
- %cmp1 = icmp eq i32 %tmp14, %tmp15
- br i1 %cmp1, label %if.then, label %if.else
-
-if.then: ; preds = %catch
- %tmp16 = load i32, i32* %e, align 4
- %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
- %tmp17 = load i32, i32* %b, align 4
- %add2 = add nsw i32 %tmp17, %tmp16
- store i32 %add2, i32* %b, align 4
- br label %if.end
-
-if.else: ; preds = %catch
- %tmp18 = load i32, i32* %e, align 4
- %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
- %tmp19 = load i32, i32* %a3, align 4
- %add4 = add nsw i32 %tmp19, %tmp18
- store i32 %add4, i32* %a3, align 4
- br label %if.end
-
-if.end: ; preds = %if.else, %if.then
- call void @llvm.eh.endcatch() #1
- br label %try.cont
-
-try.cont: ; preds = %if.end, %invoke.cont
- %tmp20 = load i32, i32* %NumExceptions, align 4
- call void @"\01?does_not_throw@@YAXH@Z"(i32 %tmp20)
- br label %for.inc
-
-for.inc: ; preds = %try.cont
- %tmp21 = load i32, i32* %i, align 4
- %inc5 = add nsw i32 %tmp21, 1
- store i32 %inc5, i32* %i, align 4
- br label %for.cond
-
-for.end: ; preds = %for.cond
- %tmp22 = load i32, i32* %NumExceptions, align 4
- %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i32 0
- call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %tmp22, %struct.SomeData* dereferenceable(8) %Data)
- ret void
-
-eh.resume: ; preds = %catch.dispatch
- %exn6 = load i8*, i8** %exn.slot
- %sel7 = load i32, i32* %ehselector.slot
- %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn6, 0
- %lpad.val8 = insertvalue { i8*, i32 } %lpad.val, i32 %sel7, 1
- resume { i8*, i32 } %lpad.val8
-}
-
-; The following catch handler should be outlined.
-; CHECK-LABEL: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
-; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
-; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
-; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
-; CHECK: %NumExceptions = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
-; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
-; CHECK: %i = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: %Data = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
-; CHECK: %tmp11 = load i32, i32* %e, align 4
-; CHECK: %tmp12 = load i32, i32* %NumExceptions, align 4
-; CHECK: %idxprom = sext i32 %tmp12 to i64
-; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i32 0, i64 %idxprom
-; CHECK: store i32 %tmp11, i32* %arrayidx, align 4
-; CHECK: %tmp13 = load i32, i32* %NumExceptions, align 4
-; CHECK: %inc = add nsw i32 %tmp13, 1
-; CHECK: store i32 %inc, i32* %NumExceptions, align 4
-; CHECK: %tmp14 = load i32, i32* %e, align 4
-; CHECK: %tmp15 = load i32, i32* %i, align 4
-; CHECK: %cmp1 = icmp eq i32 %tmp14, %tmp15
-; CHECK: br i1 %cmp1, label %if.then, label %if.else
-;
-; CHECK: if.then: ; preds = %entry
-; CHECK: %tmp16 = load i32, i32* %e, align 4
-; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 1
-; CHECK: %tmp17 = load i32, i32* %b, align 4
-; CHECK: %add2 = add nsw i32 %tmp17, %tmp16
-; CHECK: store i32 %add2, i32* %b, align 4
-; CHECK: br label %if.end
-;
-; CHECK: if.else: ; preds = %entry
-; CHECK: %tmp18 = load i32, i32* %e, align 4
-; CHECK: %a3 = getelementptr inbounds %struct.SomeData, %struct.SomeData* %Data, i32 0, i32 0
-; CHECK: %tmp19 = load i32, i32* %a3, align 4
-; CHECK: %add4 = add nsw i32 %tmp19, %tmp18
-; CHECK: store i32 %add4, i32* %a3, align 4
-; CHECK: br label %if.end
-;
-; CHECK: if.end: ; preds = %if.else, %if.then
-; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
-; CHECK: }
-
-
-
-
-
-
-; Function Attrs: nounwind
-declare void @llvm.memset(i8* nocapture, i8, i64, i32, i1) #1
-
-declare void @"\01?may_throw@@YAXXZ"() #2
-
-declare i32 @__CxxFrameHandler3(...)
-
-; Function Attrs: nounwind readnone
-declare i32 @llvm.eh.typeid.for(i8*) #3
-
-declare void @llvm.eh.begincatch(i8*, i8*)
-
-declare void @llvm.eh.endcatch()
-
-declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
-
-declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
-
-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" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { nounwind }
-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" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #3 = { nounwind readnone }
-
-!llvm.module.flags = !{!0}
-!llvm.ident = !{!1}
-
-!0 = !{i32 1, !"PIC Level", i32 2}
-!1 = !{!"clang version 3.7.0 (trunk 228868)"}
+++ /dev/null
-; RUN: opt -mtriple=i386-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test is built from the following code:
-; struct A {
-; A(int a);
-; A(const A &o);
-; ~A();
-; int a;
-; };
-;
-; void may_throw();
-;
-; int test(A a) {
-; try {
-; may_throw();
-; }
-; catch (int e) {
-; return a.a + e;
-; }
-; return 0;
-; }
-;
-; The test was built for a 32-bit Windows target and then the reference to
-; the inalloca instruction was manually sunk into the landingpad.
-
-; ModuleID = 'cppeh-inalloca.cpp'
-target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
-target triple = "i386-pc-windows-msvc"
-
-%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
-%struct.A = type { i32 }
-
-$"\01??_R0H@8" = comdat any
-
-@"\01??_7type_info@@6B@" = external constant i8*
-@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
-
-; The function entry should be rewritten like this.
-; CHECK: define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
-; CHECK: entry:
-; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 24)
-; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAHUA@@@Z.ehdata"*
-; CHECK: %.tmp.reg2mem = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 3
-; CHECK: %.tmp = select i1 true, <{ %struct.A }>* %0, <{ %struct.A }>* undef
-; CHECK: store <{ %struct.A }>* %.tmp, <{ %struct.A }>** %.tmp.reg2mem
-; CHECK-NOT: %retval = alloca i32, align 4
-; CHECK: %retval = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 4
-; CHECK: %exn.slot = alloca i8*
-; CHECK: %ehselector.slot = alloca i32
-; CHECK-NOT: %e = alloca i32, align 4
-; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 2
-; CHECK: %cleanup.dest.slot = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: invoke void @"\01?may_throw@@YAXXZ"()
-; CHECK: to label %invoke.cont unwind label %lpad
-
-define i32 @"\01?test@@YAHUA@@@Z"(<{ %struct.A }>* inalloca) #0 {
-entry:
- %retval = alloca i32, align 4
- %exn.slot = alloca i8*
- %ehselector.slot = alloca i32
- %e = alloca i32, align 4
- %cleanup.dest.slot = alloca i32
- invoke void @"\01?may_throw@@YAXXZ"()
- to label %invoke.cont unwind label %lpad
-
-invoke.cont: ; preds = %entry
- br label %try.cont
-
-lpad: ; preds = %entry
- %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- cleanup
- catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
- %2 = extractvalue { i8*, i32 } %1, 0
- store i8* %2, i8** %exn.slot
- %3 = extractvalue { i8*, i32 } %1, 1
- store i32 %3, i32* %ehselector.slot
- br label %catch.dispatch
-
-catch.dispatch: ; preds = %lpad
- %sel = load i32, i32* %ehselector.slot
- %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #3
- %matches = icmp eq i32 %sel, %4
- br i1 %matches, label %catch, label %ehcleanup
-
-catch: ; preds = %catch.dispatch
- %exn = load i8*, i8** %exn.slot
- %e.i8 = bitcast i32* %e to i8*
- call void @llvm.eh.begincatch(i8* %exn, i8* %e.i8) #3
- %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
- %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
- %tmp8 = load i32, i32* %a1, align 4
- %tmp9 = load i32, i32* %e, align 4
- %add = add nsw i32 %tmp8, %tmp9
- store i32 %add, i32* %retval
- store i32 1, i32* %cleanup.dest.slot
- call void @llvm.eh.endcatch() #3
- br label %cleanup
-
-try.cont: ; preds = %invoke.cont
- store i32 0, i32* %retval
- store i32 1, i32* %cleanup.dest.slot
- br label %cleanup
-
-; The cleanup block should be re-written like this.
-; CHECK: cleanup: ; preds = %try.cont, %catch
-; CHECK-NOT: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
-; CHECK: %.tmp.reload1 = load volatile <{ %struct.A }>*, <{ %struct.A }>** %.tmp.reg2mem
-; CHECK: %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.tmp.reload1, i32 0, i32 0
-; CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #2
-; CHECK: %tmp10 = load i32, i32* %retval
-; CHECK: ret i32 %tmp10
-
-cleanup: ; preds = %try.cont, %catch
- %a2 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
- call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a2) #3
- %tmp10 = load i32, i32* %retval
- ret i32 %tmp10
-
-ehcleanup: ; preds = %catch.dispatch
- %a3 = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %0, i32 0, i32 0
- call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %a3) #3
- br label %eh.resume
-
-eh.resume: ; preds = %ehcleanup
- %exn2 = load i8*, i8** %exn.slot
- %sel3 = load i32, i32* %ehselector.slot
- %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn2, 0
- %lpad.val4 = insertvalue { i8*, i32 } %lpad.val, i32 %sel3, 1
- resume { i8*, i32 } %lpad.val4
-}
-
-; The following catch handler should be outlined.
-; CHECK: define internal i8* @"\01?test@@YAHUA@@@Z.catch"(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (i32 (<{ %struct.A }>*)* @"\01?test@@YAHUA@@@Z" to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAHUA@@@Z.ehdata"*
-; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 1
-; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
-; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 2
-; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 3
-; CHECK: %.reload = load <{ %struct.A }>*, <{ %struct.A }>** %eh.temp.alloca
-; CHECK: %retval = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 4
-; CHECK: %cleanup.dest.slot = getelementptr inbounds %"struct.\01?test@@YAHUA@@@Z.ehdata", %"struct.\01?test@@YAHUA@@@Z.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: %a = getelementptr inbounds <{ %struct.A }>, <{ %struct.A }>* %.reload, i32 0, i32 0
-; CHECK: %a1 = getelementptr inbounds %struct.A, %struct.A* %a, i32 0, i32 0
-; CHECK: %tmp8 = load i32, i32* %a1, align 4
-; CHECK: %tmp9 = load i32, i32* %e, align 4
-; CHECK: %add = add nsw i32 %tmp8, %tmp9
-; CHECK: store i32 %add, i32* %retval
-; CHECK: store i32 1, i32* %cleanup.dest.slot
-; CHECK: ret i8* blockaddress(@"\01?test@@YAHUA@@@Z", %cleanup)
-; CHECK: }
-
-
-declare void @"\01?may_throw@@YAXXZ"() #0
-
-declare i32 @__CxxFrameHandler3(...)
-
-; Function Attrs: nounwind readnone
-declare i32 @llvm.eh.typeid.for(i8*) #1
-
-declare void @llvm.eh.begincatch(i8*, i8*)
-
-declare void @llvm.eh.endcatch()
-
-; Function Attrs: nounwind
-declare x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A*) #2
-
-attributes #0 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { nounwind readnone }
-attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #3 = { nounwind }
-
-!llvm.ident = !{!0}
-
-!0 = !{!"clang version 3.7.0 (trunk 228868)"}
+++ /dev/null
-; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test was generated from the following source:
-;
-; class SomeClass {
-; public:
-; SomeClass();
-; ~SomeClass();
-; };
-;
-; void test() {
-; SomeClass obj;
-; may_throw();
-; }
-
-
-; ModuleID = 'min-unwind.cpp'
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-; This structure should be created for the frame allocation.
-; CHECK: %struct._Z4testv.ehdata = type { i32, i8*, %class.SomeClass }
-
-%class.SomeClass = type { [28 x i32] }
-
-; The function entry should be rewritten like this.
-; CHECK: define void @_Z4testv() #0 {
-; CHECK: entry:
-; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 128)
-; CHECK: %eh.data = bitcast i8* %frame.alloc to %struct._Z4testv.ehdata*
-; CHECK-NOT: %obj = alloca %class.SomeClass, align 4
-; CHECK: %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
-
-; Function Attrs: uwtable
-define void @_Z4testv() #0 {
-entry:
- %obj = alloca %class.SomeClass, align 4
- %exn.slot = alloca i8*
- %ehselector.slot = alloca i32
- call void @_ZN9SomeClassC1Ev(%class.SomeClass* %obj)
- invoke void @_Z9may_throwv()
- to label %invoke.cont unwind label %lpad
-
-invoke.cont: ; preds = %entry
- call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
- ret void
-
-lpad: ; preds = %entry
- %tmp = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- cleanup
- %tmp1 = extractvalue { i8*, i32 } %tmp, 0
- store i8* %tmp1, i8** %exn.slot
- %tmp2 = extractvalue { i8*, i32 } %tmp, 1
- store i32 %tmp2, i32* %ehselector.slot
- call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
- br label %eh.resume
-
-eh.resume: ; preds = %lpad
- %exn = load i8*, i8** %exn.slot
- %sel = load i32, i32* %ehselector.slot
- %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
- %lpad.val2 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
- resume { i8*, i32 } %lpad.val2
-}
-
-; This cleanup handler should be outlined.
-; CHECK: define internal void @_Z4testv.cleanup(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @_Z4testv to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %struct._Z4testv.ehdata*
-; CHECK: %obj = getelementptr inbounds %struct._Z4testv.ehdata, %struct._Z4testv.ehdata* %eh.data, i32 0, i32 2
-; CHECK: call void @_ZN9SomeClassD1Ev(%class.SomeClass* %obj)
-; CHECK: ret void
-; CHECK: }
-
-declare void @_ZN9SomeClassC1Ev(%class.SomeClass*) #1
-
-declare void @_Z9may_throwv() #1
-
-declare i32 @__CxxFrameHandler3(...)
-
-declare void @_ZN9SomeClassD1Ev(%class.SomeClass*) #1
-
-attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #2 = { noinline noreturn nounwind }
-attributes #3 = { noreturn nounwind }
-attributes #4 = { nounwind }
-
-!llvm.ident = !{!0}
-
-!0 = !{!"clang version 3.7.0 (trunk 226027)"}
+++ /dev/null
-; RUN: opt -mtriple=x86_64-pc-windows-msvc -winehprepare -S -o - < %s | FileCheck %s
-
-; This test is based on the following code:
-;
-; struct SomeData {
-; int a;
-; int b;
-; };
-;
-; void may_throw();
-; void does_not_throw(int i);
-; void dump(int *, int, SomeData&);
-;
-; void test() {
-; int NumExceptions = 0;
-; int ExceptionVal[10];
-; SomeData Data = { 0, 0 };
-;
-; for (int i = 0; i < 10; ++i) {
-; try {
-; may_throw();
-; Data.a += i;
-; }
-; catch (int e) {
-; ExceptionVal[NumExceptions] = e;
-; ++NumExceptions;
-; if (e == i)
-; Data.b += e;
-; else
-; Data.a += e;
-; }
-; does_not_throw(NumExceptions);
-; }
-; dump(ExceptionVal, NumExceptions, Data);
-; }
-;
-; Unlike the cppeh-frame-vars.ll test, this test was generated using -O2
-; optimization, which results in non-alloca values being used in the
-; catch handler.
-
-; ModuleID = 'cppeh-frame-vars.cpp'
-target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-pc-windows-msvc"
-
-%rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
-%struct.SomeData = type { i32, i32 }
-
-$"\01??_R0H@8" = comdat any
-
-@"\01??_7type_info@@6B@" = external constant i8*
-@"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
-
-; This structure should be declared for the frame allocation block.
-; CHECK: %"struct.\01?test@@YAXXZ.ehdata" = type { i32, i8*, i32, i32, [10 x i32], i32, i32*, i32* }
-
-; The function entry should be rewritten like this.
-; CHECK: define void @"\01?test@@YAXXZ"() #0 {
-; CHECK: entry:
-; CHECK: %frame.alloc = call i8* @llvm.frameallocate(i32 88)
-; CHECK: %eh.data = bitcast i8* %frame.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
-; CHECK-NOT: %ExceptionVal = alloca [10 x i32], align 16
-; CHECK: %NumExceptions.020.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
-; CHECK: %i.019.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
-; CHECK: %Data = alloca i64, align 8
-; CHECK: %tmpcast = bitcast i64* %Data to %struct.SomeData*
-; CHECK: %0 = bitcast [10 x i32]* %ExceptionVal to i8*
-; CHECK: call void @llvm.lifetime.start(i64 40, i8* %0) #1
-; CHECK: store i64 0, i64* %Data, align 8
-; CHECK: %a.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
-; CHECK: %a = bitcast i64* %Data to i32*
-; CHECK: store i32* %a, i32** %a.reg2mem
-; CHECK: %b.reg2mem = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
-; CHECK: %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
-; CHECK: store i32* %b, i32** %b.reg2mem
-; CHECK: store i32 0, i32* %NumExceptions.020.reg2mem
-; CHECK: store i32 0, i32* %i.019.reg2mem
-; CHECK: br label %for.body
-
-; Function Attrs: uwtable
-define void @"\01?test@@YAXXZ"() #0 {
-entry:
- %e = alloca i32, align 4
- %ExceptionVal = alloca [10 x i32], align 16
- %Data = alloca i64, align 8
- %tmpcast = bitcast i64* %Data to %struct.SomeData*
- %0 = bitcast [10 x i32]* %ExceptionVal to i8*
- call void @llvm.lifetime.start(i64 40, i8* %0) #1
- store i64 0, i64* %Data, align 8
- %a = bitcast i64* %Data to i32*
- %b = getelementptr inbounds %struct.SomeData, %struct.SomeData* %tmpcast, i64 0, i32 1
- br label %for.body
-
-; CHECK: for.body:
-; CHECK-NOT: %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
-; CHECK-NOT: %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
-; CHECK: %i.019.reload = load i32, i32* %i.019.reg2mem
-; CHECK: %NumExceptions.020.reload = load i32, i32* %NumExceptions.020.reg2mem
-for.body: ; preds = %entry, %try.cont
- %NumExceptions.020 = phi i32 [ 0, %entry ], [ %NumExceptions.1, %try.cont ]
- %i.019 = phi i32 [ 0, %entry ], [ %inc5, %try.cont ]
- invoke void @"\01?may_throw@@YAXXZ"()
- to label %invoke.cont unwind label %lpad
-
-; CHECK: invoke.cont: ; preds = %for.body
-; CHECK-NOT: %1 = load i32, i32* %a, align 8, !tbaa !2
-; CHECK-NOT: %add = add nsw i32 %1, %i.019
-; CHECK-NOT: store i32 %add, i32* %a, align 8, !tbaa !2
-; CHECK: %a.reload3 = load volatile i32*, i32** %a.reg2mem
-; CHECK: %1 = load i32, i32* %a.reload3, align 8, !tbaa !2
-; CHECK: %add = add nsw i32 %1, %i.019.reload
-; CHECK: %a.reload2 = load volatile i32*, i32** %a.reg2mem
-; CHECK: store i32 %add, i32* %a.reload2, align 8, !tbaa !2
-; CHECK: br label %try.cont
-invoke.cont: ; preds = %for.body
- %1 = load i32, i32* %a, align 8, !tbaa !2
- %add = add nsw i32 %1, %i.019
- store i32 %add, i32* %a, align 8, !tbaa !2
- br label %try.cont
-
-lpad: ; preds = %for.body
- %2 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
- catch i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)
- %3 = extractvalue { i8*, i32 } %2, 1
- %4 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*)) #1
- %matches = icmp eq i32 %3, %4
- br i1 %matches, label %catch, label %eh.resume
-
-catch: ; preds = %lpad
- %5 = extractvalue { i8*, i32 } %2, 0
- %e.i8 = bitcast i32* %e to i8*
- call void @llvm.eh.begincatch(i8* %5, i8* %e.i8) #1
- %tmp8 = load i32, i32* %e, align 4, !tbaa !7
- %idxprom = sext i32 %NumExceptions.020 to i64
- %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
- store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
- %inc = add nsw i32 %NumExceptions.020, 1
- %cmp1 = icmp eq i32 %tmp8, %i.019
- br i1 %cmp1, label %if.then, label %if.else
-
-if.then: ; preds = %catch
- %tmp9 = load i32, i32* %b, align 4, !tbaa !8
- %add2 = add nsw i32 %tmp9, %i.019
- store i32 %add2, i32* %b, align 4, !tbaa !8
- br label %if.end
-
-if.else: ; preds = %catch
- %tmp10 = load i32, i32* %a, align 8, !tbaa !2
- %add4 = add nsw i32 %tmp10, %tmp8
- store i32 %add4, i32* %a, align 8, !tbaa !2
- br label %if.end
-
-if.end: ; preds = %if.else, %if.then
- tail call void @llvm.eh.endcatch() #1
- br label %try.cont
-
-; CHECK: try.cont: ; preds = %if.end, %invoke.cont
-; CHECK-NOT: %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
-; CHECK: %NumExceptions.1 = phi i32 [ %NumExceptions.020.reload, %invoke.cont ], [ %inc, %if.end ]
-; CHECK: tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
-; CHECK-NOT: %inc5 = add nuw nsw i32 %i.019, 1
-; CHECK: %inc5 = add nuw nsw i32 %i.019.reload, 1
-; CHECK: %cmp = icmp slt i32 %inc5, 10
-; CHECK: store i32 %NumExceptions.1, i32* %NumExceptions.020.reg2mem
-; CHECK: store i32 %inc5, i32* %i.019.reg2mem
-; CHECK: br i1 %cmp, label %for.body, label %for.end
-
-try.cont: ; preds = %if.end, %invoke.cont
- %NumExceptions.1 = phi i32 [ %NumExceptions.020, %invoke.cont ], [ %inc, %if.end ]
- tail call void @"\01?does_not_throw@@YAXH@Z"(i32 %NumExceptions.1)
- %inc5 = add nuw nsw i32 %i.019, 1
- %cmp = icmp slt i32 %inc5, 10
- br i1 %cmp, label %for.body, label %for.end
-
-for.end: ; preds = %try.cont
- %NumExceptions.1.lcssa = phi i32 [ %NumExceptions.1, %try.cont ]
- %arraydecay = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 0
- call void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32* %arraydecay, i32 %NumExceptions.1.lcssa, %struct.SomeData* dereferenceable(8) %tmpcast)
- call void @llvm.lifetime.end(i64 40, i8* %0) #1
- ret void
-
-eh.resume: ; preds = %lpad
- %.lcssa = phi { i8*, i32 } [ %2, %lpad ]
- resume { i8*, i32 } %.lcssa
-}
-
-; The following catch handler should be outlined.
-; CHECK: define internal i8* @"\01?test@@YAXXZ.catch"(i8*, i8*) {
-; CHECK: entry:
-; CHECK: %eh.alloc = call i8* @llvm.framerecover(i8* bitcast (void ()* @"\01?test@@YAXXZ" to i8*), i8* %1)
-; CHECK: %eh.data = bitcast i8* %eh.alloc to %"struct.\01?test@@YAXXZ.ehdata"*
-; CHECK: %eh.obj.ptr = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 1
-; CHECK: %eh.obj = load i8*, i8** %eh.obj.ptr
-; CHECK: %e = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 2
-; CHECK: %eh.temp.alloca = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 3
-; CHECK: %NumExceptions.020.reload = load i32, i32* %eh.temp.alloca
-; CHECK: %ExceptionVal = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 4
-; CHECK: %eh.temp.alloca1 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 5
-; CHECK: %i.019.reload = load i32, i32* %eh.temp.alloca1
-; CHECK: %eh.temp.alloca2 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 6
-; CHECK: %a.reload = load i32*, i32** %eh.temp.alloca2
-; CHECK: %eh.temp.alloca3 = getelementptr inbounds %"struct.\01?test@@YAXXZ.ehdata", %"struct.\01?test@@YAXXZ.ehdata"* %eh.data, i32 0, i32 7
-; CHECK: %b.reload = load i32*, i32** %eh.temp.alloca3
-; CHECK: %e.i8 = bitcast i32* %e to i8*
-; CHECK: %tmp8 = load i32, i32* %e, align 4, !tbaa !7
-; CHECK: %idxprom = sext i32 %NumExceptions.020.reload to i64
-; CHECK: %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* %ExceptionVal, i64 0, i64 %idxprom
-; CHECK: store i32 %tmp8, i32* %arrayidx, align 4, !tbaa !7
-; CHECK: %inc = add nsw i32 %NumExceptions.020.reload, 1
-; CHECK: %cmp1 = icmp eq i32 %tmp8, %i.019.reload
-; CHECK: br i1 %cmp1, label %if.then, label %if.else
-;
-; CHECK: if.then: ; preds = %entry
-; CHECK: %tmp9 = load i32, i32* %b.reload, align 4, !tbaa !8
-; CHECK: %add2 = add nsw i32 %tmp9, %i.019.reload
-; CHECK: store i32 %add2, i32* %b.reload, align 4, !tbaa !8
-; CHECK: br label %if.end
-;
-; CHECK: if.else: ; preds = %entry
-; CHECK: %tmp10 = load i32, i32* %a.reload, align 8, !tbaa !2
-; CHECK: %add4 = add nsw i32 %tmp10, %tmp8
-; CHECK: store i32 %add4, i32* %a.reload, align 8, !tbaa !2
-; CHECK: br label %if.end
-;
-; CHECK: if.end: ; preds = %if.else, %if.then
-; CHECK: ret i8* blockaddress(@"\01?test@@YAXXZ", %try.cont)
-; CHECK: }
-
-; Function Attrs: nounwind
-declare void @llvm.lifetime.start(i64, i8* nocapture) #1
-
-declare void @"\01?may_throw@@YAXXZ"() #2
-
-declare i32 @__CxxFrameHandler3(...)
-
-; Function Attrs: nounwind readnone
-declare i32 @llvm.eh.typeid.for(i8*) #3
-
-declare void @llvm.eh.begincatch(i8*, i8*)
-
-declare void @llvm.eh.endcatch()
-
-declare void @"\01?does_not_throw@@YAXH@Z"(i32) #2
-
-declare void @"\01?dump@@YAXPEAHHAEAUSomeData@@@Z"(i32*, i32, %struct.SomeData* dereferenceable(8)) #2
-
-; Function Attrs: nounwind
-declare void @llvm.lifetime.end(i64, i8* nocapture) #1
-
-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" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { nounwind }
-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" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #3 = { nounwind readnone }
-
-!llvm.module.flags = !{!0}
-!llvm.ident = !{!1}
-
-!0 = !{i32 1, !"PIC Level", i32 2}
-!1 = !{!"clang version 3.7.0 (trunk 228868)"}
-!2 = !{!3, !4, i64 0}
-!3 = !{!"?AUSomeData@@", !4, i64 0, !4, i64 4}
-!4 = !{!"int", !5, i64 0}
-!5 = !{!"omnipotent char", !6, i64 0}
-!6 = !{!"Simple C/C++ TBAA"}
-!7 = !{!4, !4, i64 0}
-!8 = !{!3, !4, i64 4}