summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprCXX.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-04-11 14:13:40 +0000
committerAnders Carlsson <andersca@mac.com>2011-04-11 14:13:40 +0000
commit4bdbc0cb1e29ac870b7e7985cf4a1b5c34176e8c (patch)
treeb13b23a6072bd5bf6a862c0c389f5ea4ec247f4b /lib/CodeGen/CGExprCXX.cpp
parent379b5155b4566f63679e1da6b0ceb5fdfa2aec6d (diff)
downloadclang-4bdbc0cb1e29ac870b7e7985cf4a1b5c34176e8c.tar.gz
If there's an invoke destination, we should use invoke instead of call when calling the __cxa_bad_typeid function. Fixes PR7400.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129273 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprCXX.cpp')
-rw-r--r--lib/CodeGen/CGExprCXX.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index ef71e89077..4d5f8827de 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -1338,6 +1338,28 @@ void CodeGenFunction::EmitCXXDeleteExpr(const CXXDeleteExpr *E) {
EmitBlock(DeleteEnd);
}
+static llvm::Constant *getBadTypeidFn(CodeGenFunction &CGF) {
+ // void __cxa_bad_typeid();
+
+ const llvm::Type *VoidTy = llvm::Type::getVoidTy(CGF.getLLVMContext());
+ const llvm::FunctionType *FTy =
+ llvm::FunctionType::get(VoidTy, false);
+
+ return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_bad_typeid");
+}
+
+static void EmitBadTypeidCall(CodeGenFunction &CGF) {
+ llvm::Value *F = getBadTypeidFn(CGF);
+ if (llvm::BasicBlock *InvokeDest = CGF.getInvokeDest()) {
+ llvm::BasicBlock *Cont = CGF.createBasicBlock("invoke.cont");
+ CGF.Builder.CreateInvoke(F, Cont, InvokeDest)->setDoesNotReturn();
+ CGF.EmitBlock(Cont);
+ } else
+ CGF.Builder.CreateCall(F)->setDoesNotReturn();
+
+ CGF.Builder.CreateUnreachable();
+}
+
llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) {
QualType Ty = E->getType();
const llvm::Type *LTy = ConvertType(Ty)->getPointerTo();
@@ -1372,13 +1394,9 @@ llvm::Value *CodeGenFunction::EmitCXXTypeidExpr(const CXXTypeidExpr *E) {
Builder.CreateCondBr(Builder.CreateICmpNE(This, Zero),
NonZeroBlock, ZeroBlock);
EmitBlock(ZeroBlock);
- /// Call __cxa_bad_typeid
- const llvm::Type *ResultType = llvm::Type::getVoidTy(getLLVMContext());
- const llvm::FunctionType *FTy;
- FTy = llvm::FunctionType::get(ResultType, false);
- llvm::Value *F = CGM.CreateRuntimeFunction(FTy, "__cxa_bad_typeid");
- Builder.CreateCall(F)->setDoesNotReturn();
- Builder.CreateUnreachable();
+
+ EmitBadTypeidCall(*this);
+
EmitBlock(NonZeroBlock);
}
llvm::Value *V = GetVTablePtr(This, LTy->getPointerTo());