diff --git a/clang/include/clang/CodeGen/CodeGenABITypes.h b/clang/include/clang/CodeGen/CodeGenABITypes.h --- a/clang/include/clang/CodeGen/CodeGenABITypes.h +++ b/clang/include/clang/CodeGen/CodeGenABITypes.h @@ -25,7 +25,9 @@ #include "clang/AST/CanonicalType.h" #include "clang/AST/Type.h" +#include "clang/Basic/ABI.h" #include "clang/CodeGen/CGFunctionInfo.h" +#include "llvm/IR/BasicBlock.h" namespace llvm { class AttrBuilder; @@ -40,6 +42,7 @@ namespace clang { class ASTContext; class CXXConstructorDecl; +class CXXDestructorDecl; class CXXRecordDecl; class CXXMethodDecl; class CodeGenOptions; @@ -49,6 +52,7 @@ class ObjCMethodDecl; class ObjCProtocolDecl; class PreprocessorOptions; +class QualType; namespace CodeGen { class CGFunctionInfo; @@ -90,6 +94,13 @@ ImplicitCXXConstructorArgs getImplicitCXXConstructorArgs(CodeGenModule &CGM, const CXXConstructorDecl *D); +void emitCXXDestructorCall(CodeGenModule &CGM, llvm::BasicBlock *InsertBlock, + llvm::BasicBlock::iterator InsertPoint, + const CXXDestructorDecl *D, CXXDtorType Type, + bool ForVirtualBase, bool Delegating, + llvm::Value *This, CharUnits ThisAlign, + QualType ThisTy); + /// Returns null if the function type is incomplete and can't be lowered. llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD); diff --git a/clang/lib/CodeGen/ABIInfo.h b/clang/lib/CodeGen/ABIInfo.h --- a/clang/lib/CodeGen/ABIInfo.h +++ b/clang/lib/CodeGen/ABIInfo.h @@ -28,7 +28,6 @@ namespace CodeGen { class ABIArgInfo; - class Address; class CGCXXABI; class CGFunctionInfo; class CodeGenFunction; diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1462,9 +1462,10 @@ case ABIArgInfo::Extend: case ABIArgInfo::Direct: { // FIXME: handle sseregparm someday... - llvm::StructType *STy = dyn_cast(AI.getCoerceToType()); - if (AI.isDirect() && AI.getCanBeFlattened() && STy) { - IRArgs.NumberOfArgs = STy->getNumElements(); + llvm::Type *Ty = AI.getCoerceToType(); + if (AI.isDirect() && AI.getCanBeFlattened() && + isa(Ty)) { + IRArgs.NumberOfArgs = cast(Ty)->getNumElements(); } else { IRArgs.NumberOfArgs = 1; } @@ -1644,8 +1645,9 @@ // Fast-isel and the optimizer generally like scalar values better than // FCAs, so we flatten them if this is safe to do for this argument. llvm::Type *argType = ArgInfo.getCoerceToType(); - llvm::StructType *st = dyn_cast(argType); - if (st && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) { + if (ArgInfo.isDirect() && ArgInfo.getCanBeFlattened() && + isa(argType)) { + llvm::StructType *st = cast(argType); assert(NumIRArgs == st->getNumElements()); for (unsigned i = 0, e = st->getNumElements(); i != e; ++i) ArgTypes[FirstIRArg + i] = st->getElementType(i); diff --git a/clang/lib/CodeGen/CodeGenABITypes.cpp b/clang/lib/CodeGen/CodeGenABITypes.cpp --- a/clang/lib/CodeGen/CodeGenABITypes.cpp +++ b/clang/lib/CodeGen/CodeGenABITypes.cpp @@ -115,3 +115,20 @@ const FieldDecl *FD) { return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD); } + +void CodeGen::emitCXXDestructorCall(CodeGenModule &CGM, + llvm::BasicBlock *InsertBlock, + llvm::BasicBlock::iterator InsertPoint, + const CXXDestructorDecl *D, + CXXDtorType Type, bool ForVirtualBase, + bool Delegating, llvm::Value *This, + CharUnits ThisAlign, QualType ThisTy) { + Address ThisAddr(This, ThisAlign); + CodeGenFunction CGF(CGM); + CGF.CurCodeDecl = D; + CGF.CurFuncDecl = D; + CGF.CurFn = InsertBlock->getParent(); + CGF.Builder.SetInsertPoint(InsertBlock, InsertPoint); + CGF.EmitCXXDestructorCall(D, Type, ForVirtualBase, Delegating, ThisAddr, + ThisTy); +}