Author: rnk Date: Thu Sep 10 13:39:41 2015 New Revision: 247318 URL: http://llvm.org/viewvc/llvm-project?rev=247318&view=rev Log: [SEH] Use catchret in the new EH IR like we do for C++
Also add tests for SEH with the new IRGen. Added: cfe/trunk/test/CodeGen/exceptions-seh-new.c - copied, changed from r247317, cfe/trunk/test/CodeGen/exceptions-seh.c Modified: cfe/trunk/lib/CodeGen/CGException.cpp cfe/trunk/test/CodeGen/exceptions-seh.c Modified: cfe/trunk/lib/CodeGen/CGException.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=247318&r1=247317&r2=247318&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGException.cpp (original) +++ cfe/trunk/lib/CodeGen/CGException.cpp Thu Sep 10 13:39:41 2015 @@ -1807,7 +1807,7 @@ void CodeGenFunction::EnterSEHTryStmt(co HelperCGF.GenerateSEHFilterFunction(*this, *Except); llvm::Constant *OpaqueFunc = llvm::ConstantExpr::getBitCast(FilterFunc, Int8PtrTy); - CatchScope->setHandler(0, OpaqueFunc, createBasicBlock("__except")); + CatchScope->setHandler(0, OpaqueFunc, createBasicBlock("__except.ret")); } void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) { @@ -1848,6 +1848,18 @@ void CodeGenFunction::ExitSEHTryStmt(con EmitBlockAfterUses(ExceptBB); + if (CGM.getCodeGenOpts().NewMSEH) { + // __except blocks don't get outlined into funclets, so immediately do a + // catchret. + llvm::BasicBlock *CatchPadBB = ExceptBB->getSinglePredecessor(); + assert(CatchPadBB && "only ExceptBB pred should be catchpad"); + llvm::CatchPadInst *CPI = + cast<llvm::CatchPadInst>(CatchPadBB->getFirstNonPHI()); + ExceptBB = createBasicBlock("__except"); + Builder.CreateCatchRet(CPI, ExceptBB); + EmitBlock(ExceptBB); + } + // On Win64, the exception pointer is the exception code. Copy it to the slot. if (CGM.getTarget().getTriple().getArch() != llvm::Triple::x86) { llvm::Value *Code = Copied: cfe/trunk/test/CodeGen/exceptions-seh-new.c (from r247317, cfe/trunk/test/CodeGen/exceptions-seh.c) URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh-new.c?p2=cfe/trunk/test/CodeGen/exceptions-seh-new.c&p1=cfe/trunk/test/CodeGen/exceptions-seh.c&r1=247317&r2=247318&rev=247318&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/exceptions-seh.c (original) +++ cfe/trunk/test/CodeGen/exceptions-seh-new.c Thu Sep 10 13:39:41 2015 @@ -1,6 +1,6 @@ -// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -o - \ +// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -fnew-ms-eh -emit-llvm -o - \ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X64 -// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -o - \ +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -fnew-ms-eh -emit-llvm -o - \ // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=X86 void try_body(int numerator, int denominator, int *myres) { @@ -23,36 +23,27 @@ int safe_div(int numerator, int denomina return success; } -// X64-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) {{.*}} personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) -// X64: invoke void @try_body(i32 %{{.*}}, i32 %{{.*}}, i32* %{{.*}}) #[[NOINLINE:[0-9]+]] -// X64: to label %{{.*}} unwind label %[[lpad:[^ ]*]] -// -// X64: [[lpad]] -// X64: landingpad { i8*, i32 } -// X64-NEXT: catch i8* null -// X64-NOT: br i1 -// X64: br label %[[except:[^ ]*]] -// X64: [[except]] -// X64: store i32 -42, i32* %[[success:[^ ]*]] -// -// X64: %[[res:[^ ]*]] = load i32, i32* %[[success]] -// X64: ret i32 %[[res]] - -// X86-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) {{.*}} personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) -// X86: invoke void @try_body(i32 %{{.*}}, i32 %{{.*}}, i32* %{{.*}}) #[[NOINLINE:[0-9]+]] -// X86: to label %{{.*}} unwind label %[[lpad:[^ ]*]] -// -// X86: [[lpad]] -// X86: landingpad { i8*, i32 } -// X86-NEXT: catch i8* bitcast (i32 ()* @"\01?filt$0@0@safe_div@@" to i8*) -// X86-NOT: br i1 -// X86: br label %[[except:[^ ]*]] -// X86: [[except]] -// X86: store i32 -42, i32* %[[success:[^ ]*]] +// CHECK-LABEL: define i32 @safe_div(i32 %numerator, i32 %denominator, i32* %res) +// X64-SAME: personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) +// X86-SAME: personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) +// CHECK: invoke void @try_body(i32 %{{.*}}, i32 %{{.*}}, i32* %{{.*}}) #[[NOINLINE:[0-9]+]] +// CHECK: to label %{{.*}} unwind label %[[catchpad:[^ ]*]] +// +// CHECK: [[catchpad]] +// X64: %[[padtoken:[^ ]*]] = catchpad [i8* null] to label %[[exceptret:[^ ]*]] unwind label +// X86: %[[padtoken:[^ ]*]] = catchpad [i8* bitcast (i32 ()* @"\01?filt$0@0@safe_div@@" to i8*)] to label %[[exceptret:[^ ]*]] unwind label +// +// CHECK: [[exceptret]] +// CHECK: catchret %[[padtoken]] to label %[[except:[^ ]*]] // -// X86: %[[res:[^ ]*]] = load i32, i32* %[[success]] -// X86: ret i32 %[[res]] +// CHECK: [[except]] +// CHECK: store i32 -42, i32* %[[success:[^ ]*]] +// +// CHECK: %[[res:[^ ]*]] = load i32, i32* %[[success]] +// CHECK: ret i32 %[[res]] +// 32-bit SEH needs this filter to save the exception code. +// // X86-LABEL: define internal i32 @"\01?filt$0@0@safe_div@@"() // X86: %[[ebp:[^ ]*]] = call i8* @llvm.frameaddress(i32 1) // X86: %[[fp:[^ ]*]] = call i8* @llvm.x86.seh.recoverfp(i8* bitcast (i32 (i32, i32, i32*)* @safe_div to i8*), i8* %[[ebp]]) @@ -83,8 +74,7 @@ int filter_expr_capture(void) { // CHECK: store i32 42, i32* %[[r]] // CHECK: invoke void @j() #[[NOINLINE]] // -// CHECK: landingpad -// CHECK-NEXT: catch i8* bitcast (i32 ({{.*}})* @"\01?filt$0@0@filter_expr_capture@@" to i8*) +// CHECK: catchpad [i8* bitcast (i32 ({{.*}})* @"\01?filt$0@0@filter_expr_capture@@" to i8*)] // CHECK: store i32 13, i32* %[[r]] // // CHECK: %[[rv:[^ ]*]] = load i32, i32* %[[r]] @@ -120,42 +110,39 @@ int nested_try(void) { // X86-SAME: personality i8* bitcast (i32 (...)* @_except_handler3 to i8*) // CHECK: store i32 42, i32* %[[r:[^ ,]*]] // CHECK: invoke void @j() #[[NOINLINE]] -// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[cpad_inner:[^ ]*]] // -// CHECK: [[cont]] -// CHECK: store i32 0, i32* %[[r]] +// CHECK: [[cpad_inner]] +// CHECK: catchpad [i8* bitcast (i32 ({{.*}})* @"\01?filt$1@0@nested_try@@" to i8*)] to label %[[exceptret_inner:[^ ]*]] unwind label %[[cpad_outer:[^ ]*]] +// +// CHECK: [[exceptret_inner]] +// CHECK: catchret {{.*}} to label %[[except_inner:[^ ]*]] +// +// CHECK: [[except_inner]] +// CHECK: store i32 123, i32* %[[r]] // CHECK: br label %[[inner_try_cont:[^ ]*]] // -// CHECK: [[lpad]] -// CHECK: landingpad { i8*, i32 } -// CHECK: catch i8* bitcast (i32 ({{.*}})* @"\01?filt$1@0@nested_try@@" to i8*) -// CHECK: catch i8* bitcast (i32 ({{.*}})* @"\01?filt$0@0@nested_try@@" to i8*) -// CHECK: store i8* %{{.*}}, i8** %[[ehptr_slot:[^ ]*]] -// CHECK: store i32 %{{.*}}, i32* %[[sel_slot:[^ ]*]] -// -// CHECK: load i32, i32* %[[sel_slot]] -// CHECK: call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ({{.*}})* @"\01?filt$1@0@nested_try@@" to i8*)) -// CHECK: icmp eq i32 -// CHECK: br i1 -// -// CHECK: load i32, i32* %[[sel_slot]] -// CHECK: call i32 @llvm.eh.typeid.for(i8* bitcast (i32 ({{.*}})* @"\01?filt$0@0@nested_try@@" to i8*)) -// CHECK: icmp eq i32 -// CHECK: br i1 +// CHECK: [[inner_try_cont]] +// CHECK: br label %[[outer_try_cont:[^ ]*]] +// +// CHECK: [[cpad_outer]] +// CHECK: catchpad [i8* bitcast (i32 ({{.*}})* @"\01?filt$0@0@nested_try@@" to i8*)] to label %[[exceptret_outer:[^ ]*]] unwind label +// +// CHECK: [[exceptret_outer]] +// CHECK: catchret {{.*}} to label %[[except_outer:[^ ]*]] // +// CHECK: [[except_outer]] // CHECK: store i32 456, i32* %[[r]] -// CHECK: br label %[[outer_try_cont:[^ ]*]] +// CHECK: br label %[[outer_try_cont]] // // CHECK: [[outer_try_cont]] // CHECK: %[[r_load:[^ ]*]] = load i32, i32* %[[r]] // CHECK: ret i32 %[[r_load]] // -// CHECK: store i32 123, i32* %[[r]] +// CHECK: [[cont]] +// CHECK: store i32 0, i32* %[[r]] // CHECK: br label %[[inner_try_cont]] // -// CHECK: [[inner_try_cont]] -// CHECK: br label %[[outer_try_cont]] -// // CHECK-LABEL: define internal i32 @"\01?filt$0@0@nested_try@@"({{.*}}) // X86: call i8* @llvm.x86.seh.recoverfp({{.*}}) // CHECK: load i32*, i32** @@ -184,7 +171,7 @@ int basic_finally(int g) { // CHECK: store i32 %g, i32* %[[g_addr]] // // CHECK: invoke void @j() -// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[cleanuppad:[^ ]*]] // // CHECK: [[cont]] // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress() @@ -192,12 +179,11 @@ int basic_finally(int g) { // CHECK: load i32, i32* %[[g_addr]], align 4 // CHECK: ret i32 // -// CHECK: [[lpad]] -// CHECK: landingpad { i8*, i32 } -// CHECK-NEXT: cleanup +// CHECK: [[cleanuppad]] +// CHECK: %[[padtoken:[^ ]*]] = cleanuppad [] // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.localaddress() // CHECK: call void @"\01?fin$0@0@basic_finally@@"({{i8( zeroext)?}} 1, i8* %[[fp]]) -// CHECK: resume +// CHECK: cleanupret %[[padtoken]] unwind to caller // CHECK: define internal void @"\01?fin$0@0@basic_finally@@"({{i8( zeroext)?}} %abnormal_termination, i8* %frame_pointer) // CHECK: call i8* @llvm.localrecover(i8* bitcast (i32 (i32)* @basic_finally to i8*), i8* %frame_pointer, i32 0) @@ -216,14 +202,16 @@ int except_return(void) { } // CHECK-LABEL: define i32 @except_return() // CHECK: %[[tmp:[^ ]*]] = invoke i32 @returns_int() -// CHECK: to label %[[cont:[^ ]*]] unwind label %[[lpad:[^ ]*]] +// CHECK: to label %[[cont:[^ ]*]] unwind label %[[catchpad:[^ ]*]] // -// CHECK: [[cont]] -// CHECK: store i32 %[[tmp]], i32* %[[rv:[^ ]*]] +// CHECK: [[catchpad]] +// CHECK: catchpad +// CHECK: catchret +// CHECK: store i32 42, i32* %[[rv:[^ ]*]] // CHECK: br label %[[retbb:[^ ]*]] // -// CHECK: [[lpad]] -// CHECK: store i32 42, i32* %[[rv]] +// CHECK: [[cont]] +// CHECK: store i32 %[[tmp]], i32* %[[rv]] // CHECK: br label %[[retbb]] // // CHECK: [[retbb]] @@ -240,7 +228,7 @@ void finally_capture_twice(int x) { int z = x; } } -// +// // CHECK-LABEL: define void @finally_capture_twice( // CHECK: [[X:%.*]] = alloca i32, align 4 // CHECK: call void (...) @llvm.localescape(i32* [[X]]) Modified: cfe/trunk/test/CodeGen/exceptions-seh.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exceptions-seh.c?rev=247318&r1=247317&r2=247318&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/exceptions-seh.c (original) +++ cfe/trunk/test/CodeGen/exceptions-seh.c Thu Sep 10 13:39:41 2015 @@ -240,7 +240,7 @@ void finally_capture_twice(int x) { int z = x; } } -// +// // CHECK-LABEL: define void @finally_capture_twice( // CHECK: [[X:%.*]] = alloca i32, align 4 // CHECK: call void (...) @llvm.localescape(i32* [[X]]) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits