summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/MicrosoftCXXABI.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-11-25 07:20:20 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-11-25 07:20:20 +0000
commit442d0a2e5a4df40b3c8f9b131c26778402cb3886 (patch)
treeeeb678ac8cef0113796779bd91a206d83941a077 /clang/lib/CodeGen/MicrosoftCXXABI.cpp
parent4646b11acfa88c3a1f0e9fdea1e3da31a64d2452 (diff)
downloadbcm5719-llvm-442d0a2e5a4df40b3c8f9b131c26778402cb3886.tar.gz
bcm5719-llvm-442d0a2e5a4df40b3c8f9b131c26778402cb3886.zip
MS ABI: Add CodeGen support for rethrowing MS C++ exceptions
Rethrowing exceptions in the MS model is very simple: just call _CxxThrowException with nullptr for both arguments. N.B. They chose stdcall as the calling convention for x86 but cdecl for all other platforms. llvm-svn: 222733
Diffstat (limited to 'clang/lib/CodeGen/MicrosoftCXXABI.cpp')
-rw-r--r--clang/lib/CodeGen/MicrosoftCXXABI.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 659ed0a3050..6e7d4385d03 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -70,6 +70,8 @@ public:
llvm::Value *Ptr, QualType ElementType,
const CXXDestructorDecl *Dtor) override;
+ void emitRethrow(CodeGenFunction &CGF, bool isNoReturn);
+
llvm::GlobalVariable *getMSCompleteObjectLocator(const CXXRecordDecl *RD,
const VPtrInfo *Info);
@@ -665,6 +667,30 @@ void MicrosoftCXXABI::emitVirtualObjectDelete(CodeGenFunction &CGF,
CGF.EmitDeleteCall(DE->getOperatorDelete(), MDThis, ElementType);
}
+static llvm::Function *getRethrowFn(CodeGenModule &CGM) {
+ // _CxxThrowException takes two pointer width arguments: a value and a context
+ // object which points to a TypeInfo object.
+ llvm::Type *ArgTypes[] = {CGM.Int8PtrTy, CGM.Int8PtrTy};
+ llvm::FunctionType *FTy =
+ llvm::FunctionType::get(CGM.VoidTy, ArgTypes, false);
+ auto *Fn = cast<llvm::Function>(
+ CGM.CreateRuntimeFunction(FTy, "_CxxThrowException"));
+ // _CxxThrowException is stdcall on 32-bit x86 platforms.
+ if (CGM.getTarget().getTriple().getArch() == llvm::Triple::x86)
+ Fn->setCallingConv(llvm::CallingConv::X86_StdCall);
+ return Fn;
+}
+
+void MicrosoftCXXABI::emitRethrow(CodeGenFunction &CGF, bool isNoReturn) {
+ llvm::Value *Args[] = {llvm::ConstantPointerNull::get(CGM.Int8PtrTy),
+ llvm::ConstantPointerNull::get(CGM.Int8PtrTy)};
+ auto *Fn = getRethrowFn(CGM);
+ if (isNoReturn)
+ CGF.EmitNoreturnRuntimeCallOrInvoke(Fn, Args);
+ else
+ CGF.EmitRuntimeCallOrInvoke(Fn, Args);
+}
+
/// \brief Gets the offset to the virtual base that contains the vfptr for
/// MS-ABI polymorphic types.
static llvm::Value *getPolymorphicOffset(CodeGenFunction &CGF,
OpenPOWER on IntegriCloud