From 65bd4ac6ffbf6de30cd6f36735539ff8172a904a Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Fri, 11 Jan 2013 15:33:01 +0000 Subject: [PATCH] Enable the new (more C++-like, less broken) EH model when targeting the GNUstep Objective-C runtime 1.7 or greater. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172207 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGException.cpp | 6 ++++++ lib/CodeGen/CGObjCGNU.cpp | 11 +++++++++++ test/CodeGenObjC/gnu-exceptions.m | 3 +++ 3 files changed, 20 insertions(+) diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index 5797fd7578..b30d820a92 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -156,6 +156,7 @@ namespace { static const EHPersonality GNU_C; static const EHPersonality GNU_C_SJLJ; static const EHPersonality GNU_ObjC; + static const EHPersonality GNUstep_ObjC; static const EHPersonality GNU_ObjCXX; static const EHPersonality NeXT_ObjC; static const EHPersonality GNU_CPlusPlus; @@ -173,6 +174,8 @@ const EHPersonality EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0", "objc_exception_throw"}; const EHPersonality EHPersonality::GNU_ObjCXX = { "__gnustep_objcxx_personality_v0", 0 }; +const EHPersonality +EHPersonality::GNUstep_ObjC = { "__gnustep_objc_personality_v0", 0 }; static const EHPersonality &getCPersonality(const LangOptions &L) { if (L.SjLjExceptions) @@ -188,6 +191,9 @@ static const EHPersonality &getObjCPersonality(const LangOptions &L) { case ObjCRuntime::iOS: return EHPersonality::NeXT_ObjC; case ObjCRuntime::GNUstep: + if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7)) + return EHPersonality::GNUstep_ObjC; + // fallthrough case ObjCRuntime::GCC: case ObjCRuntime::ObjFW: return EHPersonality::GNU_ObjC; diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index d1ca3bf263..adc2ed0285 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -675,6 +675,8 @@ class CGObjCGNUstep : public CGObjCGNU { } public: CGObjCGNUstep(CodeGenModule &Mod) : CGObjCGNU(Mod, 9, 3) { + ObjCRuntime R = CGM.getLangOpts().ObjCRuntime; + llvm::StructType *SlotStructTy = llvm::StructType::get(PtrTy, PtrTy, PtrTy, IntTy, IMPTy, NULL); SlotTy = llvm::PointerType::getUnqual(SlotStructTy); @@ -694,6 +696,15 @@ class CGObjCGNUstep : public CGObjCGNU { // void _Unwind_Resume_or_Rethrow(void*) ExceptionReThrowFn.init(&CGM, "_Unwind_Resume_or_Rethrow", VoidTy, PtrTy, NULL); + } else if (R.getVersion() >= VersionTuple(1, 7)) { + llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); + // id objc_begin_catch(void *e) + EnterCatchFn.init(&CGM, "objc_begin_catch", IdTy, PtrTy, NULL); + // void objc_end_catch(void) + ExitCatchFn.init(&CGM, "objc_end_catch", VoidTy, NULL); + // void _Unwind_Resume_or_Rethrow(void*) + ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, + PtrTy, NULL); } llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); SetPropertyAtomic.init(&CGM, "objc_setProperty_atomic", VoidTy, IdTy, diff --git a/test/CodeGenObjC/gnu-exceptions.m b/test/CodeGenObjC/gnu-exceptions.m index b7d0adbc6d..4a046e2134 100644 --- a/test/CodeGenObjC/gnu-exceptions.m +++ b/test/CodeGenObjC/gnu-exceptions.m @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fexceptions -fobjc-exceptions -fobjc-runtime=gcc -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm -fexceptions -fobjc-exceptions -fobjc-runtime=gnustep-1.7 -o - %s | FileCheck -check-prefix=NEW-ABI %s void opaque(void); void log(int i); @@ -21,6 +22,8 @@ void test0() { // CHECK: call void @log(i32 0) // CHECK: resume + // NEW-ABI: objc_begin_catch + // NEW-ABI: objc_end_catch log(0); } -- 2.40.0