diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp')
| -rw-r--r-- | contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp | 35 | 
1 files changed, 23 insertions, 12 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp b/contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp index 9443fecf9b79..cd1a0b6a130f 100644 --- a/contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/contrib/llvm-project/clang/lib/CodeGen/CGObjCGNU.cpp @@ -168,6 +168,8 @@ protected:    /// Does the current target use SEH-based exceptions? False implies    /// Itanium-style DWARF unwinding.    bool usesSEHExceptions; +  /// Does the current target uses C++-based exceptions? +  bool usesCxxExceptions;    /// Helper to check if we are targeting a specific runtime version or later.    bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) { @@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {        SlotLookupSuperFn.init(&CGM, "objc_slot_lookup_super", SlotTy,                               PtrToObjCSuperTy, SelectorTy);        // If we're in ObjC++ mode, then we want to make -      if (usesSEHExceptions) { -          llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); -          // void objc_exception_rethrow(void) -          ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy); +      llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext); +      if (usesCxxExceptions) { +        // void *__cxa_begin_catch(void *e) +        EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy); +        // void __cxa_end_catch(void) +        ExitCatchFn.init(&CGM, "__cxa_end_catch", VoidTy); +        // void objc_exception_rethrow(void*) +        ExceptionReThrowFn.init(&CGM, "__cxa_rethrow", PtrTy); +      } else if (usesSEHExceptions) { +        // void objc_exception_rethrow(void) +        ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy);        } else if (CGM.getLangOpts().CPlusPlus) { -        llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);          // void *__cxa_begin_catch(void *e)          EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy);          // void __cxa_end_catch(void) @@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {          ExceptionReThrowFn.init(&CGM, "_Unwind_Resume_or_Rethrow", VoidTy,                                  PtrTy);        } 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);          // void objc_end_catch(void) @@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {          // void _Unwind_Resume_or_Rethrow(void*)          ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, PtrTy);        } -      llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);        SetPropertyAtomic.init(&CGM, "objc_setProperty_atomic", VoidTy, IdTy,                               SelectorTy, IdTy, PtrDiffTy);        SetPropertyAtomicCopy.init(&CGM, "objc_setProperty_atomic_copy", VoidTy, @@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion,    msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");    usesSEHExceptions =        cgm.getContext().getTargetInfo().getTriple().isWindowsMSVCEnvironment(); +  usesCxxExceptions = +      cgm.getContext().getTargetInfo().getTriple().isOSCygMing() && +      isRuntime(ObjCRuntime::GNUstep, 2);    CodeGenTypes &Types = CGM.getTypes();    IntTy = cast<llvm::IntegerType>( @@ -2212,7 +2221,10 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion,    // void objc_exception_throw(id);    ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy); -  ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy); +  ExceptionReThrowFn.init(&CGM, +                          usesCxxExceptions ? "objc_exception_rethrow" +                                            : "objc_exception_throw", +                          VoidTy, IdTy);    // int objc_sync_enter(id);    SyncEnterFn.init(&CGM, "objc_sync_enter", IntTy, IdTy);    // int objc_sync_exit(id); @@ -2389,7 +2401,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {    if (usesSEHExceptions)      return CGM.getCXXABI().getAddrOfRTTIDescriptor(T); -  if (!CGM.getLangOpts().CPlusPlus) +  if (!CGM.getLangOpts().CPlusPlus && !usesCxxExceptions)      return CGObjCGNU::GetEHType(T);    // For Objective-C++, we want to provide the ability to catch both C++ and @@ -3995,7 +4007,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,      ExceptionAsObject = CGF.ObjCEHValueStack.back();      isRethrow = true;    } -  if (isRethrow && usesSEHExceptions) { +  if (isRethrow && (usesSEHExceptions || usesCxxExceptions)) {      // For SEH, ExceptionAsObject may be undef, because the catch handler is      // not passed it for catchalls and so it is not visible to the catch      // funclet.  The real thrown object will still be live on the stack at this @@ -4005,8 +4017,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,      // argument.      llvm::CallBase *Throw = CGF.EmitRuntimeCallOrInvoke(ExceptionReThrowFn);      Throw->setDoesNotReturn(); -  } -  else { +  } else {      ExceptionAsObject = CGF.Builder.CreateBitCast(ExceptionAsObject, IdTy);      llvm::CallBase *Throw =          CGF.EmitRuntimeCallOrInvoke(ExceptionThrowFn, ExceptionAsObject);  | 
