aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-07-06 01:22:26 +0000
committerJohn McCall <rjmccall@apple.com>2011-07-06 01:22:26 +0000
commit256a76e0b0e0c9e65a3122917d553ef10bc84d29 (patch)
treeeed80264ac453d3e22cd9e9d1b364c41e1a12c5a /lib
parentc06e0743431b28c96e0bbe27cc07851d2e0d2681 (diff)
Call objc_terminate() instead of abort() when a cleanup throws an
exception in Objective-C; in Objective-C++ we still use std::terminate(). This is only available in very recent runtimes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134456 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CGException.cpp13
-rw-r--r--lib/Driver/ToolChain.cpp2
-rw-r--r--lib/Driver/ToolChains.cpp7
-rw-r--r--lib/Driver/Tools.cpp2
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
5 files changed, 25 insertions, 2 deletions
diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp
index 1a4a5f988a..af54f39686 100644
--- a/lib/CodeGen/CGException.cpp
+++ b/lib/CodeGen/CGException.cpp
@@ -137,8 +137,17 @@ static llvm::Constant *getTerminateFn(CodeGenFunction &CGF) {
llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()),
/*IsVarArgs=*/false);
- return CGF.CGM.CreateRuntimeFunction(FTy,
- CGF.CGM.getLangOptions().CPlusPlus ? "_ZSt9terminatev" : "abort");
+ llvm::StringRef name;
+
+ // In C++, use std::terminate().
+ if (CGF.getLangOptions().CPlusPlus)
+ name = "_ZSt9terminatev"; // FIXME: mangling!
+ else if (CGF.getLangOptions().ObjC1 &&
+ CGF.CGM.getCodeGenOpts().ObjCRuntimeHasTerminate)
+ name = "objc_terminate";
+ else
+ name = "abort";
+ return CGF.CGM.CreateRuntimeFunction(FTy, name);
}
static llvm::Constant *getCatchallRethrowFn(CodeGenFunction &CGF,
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 0cce517549..74b65918f3 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -55,12 +55,14 @@ void ToolChain::configureObjCRuntime(ObjCRuntime &runtime) const {
// Assume a minimal NeXT runtime.
runtime.HasARC = false;
runtime.HasWeak = false;
+ runtime.HasTerminate = false;
return;
case ObjCRuntime::GNU:
// Assume a maximal GNU runtime.
runtime.HasARC = true;
runtime.HasWeak = true;
+ runtime.HasTerminate = false; // to be added
return;
}
llvm_unreachable("invalid runtime kind!");
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 68ebc1b6b3..1619ef8f84 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -99,6 +99,13 @@ void Darwin::configureObjCRuntime(ObjCRuntime &runtime) const {
return ToolChain::configureObjCRuntime(runtime);
runtime.HasARC = runtime.HasWeak = hasARCRuntime();
+
+ // So far, objc_terminate is only available in iOS 5.
+ // FIXME: do the simulator logic properly.
+ if (!ARCRuntimeForSimulator && isTargetIPhoneOS())
+ runtime.HasTerminate = !isIPhoneOSVersionLT(5);
+ else
+ runtime.HasTerminate = false;
}
// FIXME: Can we tablegen this?
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index d0fd914bf0..d4d41d28d5 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1781,6 +1781,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fobjc-runtime-has-arc");
if (objCRuntime.HasWeak)
CmdArgs.push_back("-fobjc-runtime-has-weak");
+ if (objCRuntime.HasTerminate)
+ CmdArgs.push_back("-fobjc-runtime-has-terminate");
// Compute the Objective-C ABI "version" to use. Version numbers are
// slightly confusing for historical reasons:
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 31c86432b7..fd57f59e64 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -125,6 +125,8 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
}
if (Opts.ObjCRuntimeHasARC)
Res.push_back("-fobjc-runtime-has-arc");
+ if (Opts.ObjCRuntimeHasTerminate)
+ Res.push_back("-fobjc-runtime-has-terminate");
if (Opts.EmitGcovArcs)
Res.push_back("-femit-coverage-data");
if (Opts.EmitGcovNotes)
@@ -979,6 +981,7 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
Opts.ObjCRuntimeHasARC = Args.hasArg(OPT_fobjc_runtime_has_arc);
+ Opts.ObjCRuntimeHasTerminate = Args.hasArg(OPT_fobjc_runtime_has_terminate);
Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
Opts.CodeModel = Args.getLastArgValue(OPT_mcode_model);