[cfe-commits] r129273 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/typeid.cpp
Anders Carlsson
andersca at mac.com
Mon Apr 11 07:13:40 PDT 2011
Author: andersca
Date: Mon Apr 11 09:13:40 2011
New Revision: 129273
URL: http://llvm.org/viewvc/llvm-project?rev=129273&view=rev
Log:
If there's an invoke destination, we should use invoke instead of call when calling the __cxa_bad_typeid function. Fixes PR7400.
Added:
cfe/trunk/test/CodeGenCXX/typeid.cpp
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=129273&r1=129272&r2=129273&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Mon Apr 11 09:13:40 2011
@@ -1338,6 +1338,28 @@
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 @@
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());
Added: cfe/trunk/test/CodeGenCXX/typeid.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/typeid.cpp?rev=129273&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/typeid.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/typeid.cpp Mon Apr 11 09:13:40 2011
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -I%S %s -triple x86_64-apple-darwin10 -emit-llvm -fcxx-exceptions -fexceptions -o - | FileCheck %s
+#include <typeinfo>
+
+// PR7400
+struct A { virtual void f(); };
+
+// CHECK: define i8* @_Z1fv
+const char *f() {
+ try {
+ // CHECK: br i1
+ // CHECK: invoke void @__cxa_bad_typeid() noreturn
+ return typeid(*static_cast<A *>(0)).name();
+ } catch (...) {
+ // CHECK: call i8* @llvm.eh.exception
+ }
+
+ return 0;
+}
More information about the cfe-commits
mailing list