]> granicus.if.org Git - clang/commitdiff
Pick the correct personality function based on the language. This prevents link...
authorDavid Chisnall <csdavec@swan.ac.uk>
Mon, 17 May 2010 13:49:20 +0000 (13:49 +0000)
committerDavid Chisnall <csdavec@swan.ac.uk>
Mon, 17 May 2010 13:49:20 +0000 (13:49 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103938 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGException.cpp

index 9fa195235ff5df7313b230d8353d91a8fb29d772..ed392bd0d345ce4e4fc47e7885e665d1687d7c26 100644 (file)
@@ -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 =