summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2010-05-17 13:49:20 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2010-05-17 13:49:20 +0000
commitf9c4225af6b83828326fd97b8b0ca5d84a3ee74c (patch)
tree80dda898259d8bbd61c87765b15b79a2c123c2dd /clang/lib/CodeGen
parent05fa30d5954324865a1ae221d7821829227017ba (diff)
downloadbcm5719-llvm-f9c4225af6b83828326fd97b8b0ca5d84a3ee74c.tar.gz
bcm5719-llvm-f9c4225af6b83828326fd97b8b0ca5d84a3ee74c.zip
Pick the correct personality function based on the language. This prevents link failures when C/ObjC code uses __attribute__((cleanup())) (previously this was inserting references to two libstc++ symbols; the personality function and the __terminate() function).
This is still probably wrong for Objective-C++ and adds a couple of lines in CGException that should probably be in the CGObjCRuntime subclass. The personality function is now only looked up in one place in CGException though, so this should be easier to fix in the future. llvm-svn: 103938
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGException.cpp51
1 files changed, 26 insertions, 25 deletions
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 9fa195235ff..ed392bd0d34 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -119,7 +119,28 @@ static llvm::Constant *getTerminateFn(CodeGenFunction &CGF) {
const llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::getVoidTy(CGF.getLLVMContext()), false);
- return CGF.CGM.CreateRuntimeFunction(FTy, "_ZSt9terminatev");
+ return CGF.CGM.CreateRuntimeFunction(FTy,
+ CGF.CGM.getLangOptions().CPlusPlus ? "_ZSt9terminatev" : "abort");
+}
+
+static llvm::Constant *getPersonalityFn(CodeGenModule &CGM) {
+ const char *PersonalityFnName = "__gcc_personality_v0";
+ LangOptions Opts = CGM.getLangOptions();
+ if (Opts.CPlusPlus)
+ PersonalityFnName = "__gxx_personality_v0";
+ else if (Opts.ObjC1)
+ if (Opts.NeXTRuntime) {
+ if (Opts.ObjCNonFragileABI)
+ PersonalityFnName = "__gcc_personality_v0";
+ } else
+ PersonalityFnName = "__gnu_objc_personality_v0";
+
+ llvm::Constant *Personality =
+ CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty(
+ CGM.getLLVMContext()),
+ true),
+ PersonalityFnName);
+ return llvm::ConstantExpr::getBitCast(Personality, CGM.PtrToInt8Ty);
}
// Emits an exception expression into the given location. This
@@ -324,12 +345,7 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
if (!Proto->hasExceptionSpec())
return;
- llvm::Constant *Personality =
- CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty
- (VMContext),
- true),
- "__gxx_personality_v0");
- Personality = llvm::ConstantExpr::getBitCast(Personality, PtrToInt8Ty);
+ llvm::Constant *Personality = getPersonalityFn(CGM);
llvm::Value *llvm_eh_exception =
CGM.getIntrinsic(llvm::Intrinsic::eh_exception);
llvm::Value *llvm_eh_selector =
@@ -444,12 +460,7 @@ CodeGenFunction::EnterCXXTryStmt(const CXXTryStmt &S) {
void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S,
CXXTryStmtInfo TryInfo) {
// Pointer to the personality function
- llvm::Constant *Personality =
- CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty
- (VMContext),
- true),
- "__gxx_personality_v0");
- Personality = llvm::ConstantExpr::getBitCast(Personality, PtrToInt8Ty);
+ llvm::Constant *Personality = getPersonalityFn(CGM);
llvm::Value *llvm_eh_exception =
CGM.getIntrinsic(llvm::Intrinsic::eh_exception);
llvm::Value *llvm_eh_selector =
@@ -654,12 +665,7 @@ CodeGenFunction::EHCleanupBlock::~EHCleanupBlock() {
// The libstdc++ personality function.
// TODO: generalize to work with other libraries.
- llvm::Constant *Personality =
- CGF.CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty
- (CGF.VMContext),
- true),
- "__gxx_personality_v0");
- Personality = llvm::ConstantExpr::getBitCast(Personality, CGF.PtrToInt8Ty);
+ llvm::Constant *Personality = getPersonalityFn(CGF.CGM);
// %exception = call i8* @llvm.eh.exception()
// Magic intrinsic which tells gives us a handle to the caught
@@ -715,12 +721,7 @@ llvm::BasicBlock *CodeGenFunction::getTerminateHandler() {
llvm::BasicBlock::iterator SavedInsertPoint = Builder.GetInsertPoint();
Builder.ClearInsertionPoint();
- llvm::Constant *Personality =
- CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty
- (VMContext),
- true),
- "__gxx_personality_v0");
- Personality = llvm::ConstantExpr::getBitCast(Personality, PtrToInt8Ty);
+ llvm::Constant *Personality = getPersonalityFn(CGM);
llvm::Value *llvm_eh_exception =
CGM.getIntrinsic(llvm::Intrinsic::eh_exception);
llvm::Value *llvm_eh_selector =
OpenPOWER on IntegriCloud