From 88d117c2eedd7c5bec57ac983a98d5e12bdd2cc6 Mon Sep 17 00:00:00 2001 From: Tilmann Scheller Date: Wed, 2 Mar 2011 19:36:23 +0000 Subject: [PATCH] Add CC_Win64ThisCall and set it in the necessary places. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126863 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Type.h | 3 ++- include/clang/Basic/TargetInfo.h | 6 ++++++ lib/AST/DumpXML.cpp | 1 + lib/AST/MicrosoftMangle.cpp | 3 +++ lib/AST/Type.cpp | 1 + lib/CodeGen/CGBlocks.cpp | 10 +++++----- lib/CodeGen/CGCall.cpp | 29 +++++++++++++++++++++-------- lib/CodeGen/CGDeclCXX.cpp | 11 +++++++---- lib/CodeGen/CGExpr.cpp | 2 +- lib/CodeGen/CGExprCXX.cpp | 30 +++++++++++++++++++++--------- lib/CodeGen/CGObjC.cpp | 3 ++- lib/CodeGen/CGVTables.cpp | 16 ++++++++++++---- lib/CodeGen/CodeGenFunction.cpp | 7 ++++--- lib/CodeGen/CodeGenFunction.h | 3 ++- lib/CodeGen/CodeGenTypes.h | 8 +++++--- lib/CodeGen/TargetInfo.cpp | 20 ++++++++++++++++++++ 16 files changed, 113 insertions(+), 40 deletions(-) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 9b177cceed..2b34b716d4 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -354,7 +354,8 @@ enum CallingConv { CC_X86StdCall, // __attribute__((stdcall)) CC_X86FastCall, // __attribute__((fastcall)) CC_X86ThisCall, // __attribute__((thiscall)) - CC_X86Pascal // __attribute__((pascal)) + CC_X86Pascal, // __attribute__((pascal)) + CC_Win64ThisCall }; typedef std::pair SplitQualType; diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index b9087f2c47..446fec59ac 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -530,6 +530,12 @@ public: virtual const char *getStaticInitSectionSpecifier() const { return 0; } + + // isWin64 - Whether the target is MSVC Win64. + bool isWin64() const { + return (Triple.getArch() == llvm::Triple::x86_64) + && (Triple.getOS() == llvm::Triple::Win32); + } protected: virtual uint64_t getPointerWidthV(unsigned AddrSpace) const { return PointerWidth; diff --git a/lib/AST/DumpXML.cpp b/lib/AST/DumpXML.cpp index 9d828fcfb8..4f548b265c 100644 --- a/lib/AST/DumpXML.cpp +++ b/lib/AST/DumpXML.cpp @@ -911,6 +911,7 @@ struct XMLDumper : public XMLDeclVisitor, case CC_X86StdCall: return set("cc", "x86_stdcall"); case CC_X86ThisCall: return set("cc", "x86_thiscall"); case CC_X86Pascal: return set("cc", "x86_pascal"); + case CC_Win64ThisCall: return set("cc", "win64_thiscall"); } } diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index 4bf7f23a0a..f5bdd4b537 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -879,6 +879,9 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T, case CC_X86ThisCall: Out << 'E'; break; case CC_X86StdCall: Out << 'G'; break; case CC_X86FastCall: Out << 'I'; break; + case CC_Win64ThisCall: + assert(false && "Don't know how to mangle Win64 thiscall cc yet!"); + break; } } void MicrosoftCXXNameMangler::mangleThrowSpecification( diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index cde865f5b9..2cab221448 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1157,6 +1157,7 @@ llvm::StringRef FunctionType::getNameForCallConv(CallingConv CC) { case CC_X86FastCall: return "fastcall"; case CC_X86ThisCall: return "thiscall"; case CC_X86Pascal: return "pascal"; + case CC_Win64ThisCall: return "win64_thiscall"; } llvm_unreachable("Invalid calling convention."); diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 9587de223a..8cd1f5e38d 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -922,7 +922,7 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD, // Begin generating the function. StartFunction(blockDecl, fnType->getResultType(), fn, args, - blockInfo.getBlockExpr()->getBody()->getLocEnd()); + blockInfo.getBlockExpr()->getBody()->getLocEnd(), CC_Default); CurFuncDecl = outerFnDecl; // StartFunction sets this to blockDecl // Okay. Undo some of what StartFunction did. @@ -1078,7 +1078,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { SC_None, false, true); - StartFunction(FD, C.VoidTy, Fn, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, args, SourceLocation(), CC_Default); const llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); @@ -1167,7 +1167,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { SC_Static, SC_None, false, true); - StartFunction(FD, C.VoidTy, Fn, args, SourceLocation()); + StartFunction(FD, C.VoidTy, Fn, args, SourceLocation(), CC_Default); const llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo(); @@ -1270,7 +1270,7 @@ GeneratebyrefCopyHelperFunction(const llvm::Type *T, BlockFieldFlags flags, SC_Static, SC_None, false, true); - StartFunction(FD, R, Fn, Args, SourceLocation()); + StartFunction(FD, R, Fn, Args, SourceLocation(), CC_Default); // dst->x llvm::Value *V = GetAddrOfLocalVar(Dst); @@ -1340,7 +1340,7 @@ CodeGenFunction::GeneratebyrefDestroyHelperFunction(const llvm::Type *T, SC_Static, SC_None, false, true); - StartFunction(FD, R, Fn, Args, SourceLocation()); + StartFunction(FD, R, Fn, Args, SourceLocation(), CC_Default); llvm::Value *V = GetAddrOfLocalVar(Src); V = Builder.CreateBitCast(V, llvm::PointerType::get(T, 0)); diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index bd14d1be09..1116053b52 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -36,6 +36,7 @@ static unsigned ClangCallConvToLLVMCallConv(CallingConv CC) { case CC_X86StdCall: return llvm::CallingConv::X86_StdCall; case CC_X86FastCall: return llvm::CallingConv::X86_FastCall; case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall; + case CC_Win64ThisCall: return llvm::CallingConv::Win64_ThisCall; // TODO: add support for CC_X86Pascal to llvm } } @@ -75,19 +76,23 @@ CodeGenTypes::getFunctionInfo(CanQual FTNP, static const CGFunctionInfo &getFunctionInfo(CodeGenTypes &CGT, llvm::SmallVectorImpl &ArgTys, CanQual FTP, + CallingConv CC, bool IsRecursive = false) { // FIXME: Kill copy. for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) ArgTys.push_back(FTP->getArgType(i)); CanQualType ResTy = FTP->getResultType().getUnqualifiedType(); - return CGT.getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo(), IsRecursive); + + return CGT.getFunctionInfo(ResTy, ArgTys, + FTP->getExtInfo().withCallingConv(CC), + IsRecursive); } const CGFunctionInfo & CodeGenTypes::getFunctionInfo(CanQual FTP, bool IsRecursive) { llvm::SmallVector ArgTys; - return ::getFunctionInfo(*this, ArgTys, FTP, IsRecursive); + return ::getFunctionInfo(*this, ArgTys, FTP, CC_Default, IsRecursive); } static CallingConv getCallingConventionForDecl(const Decl *D) { @@ -114,8 +119,10 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXRecordDecl *RD, // Add the 'this' pointer. ArgTys.push_back(GetThisType(Context, RD)); + CallingConv CC = Context.Target.isWin64() ? CC_Win64ThisCall : CC_Default; + return ::getFunctionInfo(*this, ArgTys, - FTP->getCanonicalTypeUnqualified().getAs()); + FTP->getCanonicalTypeUnqualified().getAs(), CC); } const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXMethodDecl *MD) { @@ -128,7 +135,9 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXMethodDecl *MD) { if (MD->isInstance()) ArgTys.push_back(GetThisType(Context, MD->getParent())); - return ::getFunctionInfo(*this, ArgTys, GetFormalType(MD)); + CallingConv CC = Context.Target.isWin64() ? CC_Win64ThisCall : CC_Default; + + return ::getFunctionInfo(*this, ArgTys, GetFormalType(MD), CC); } const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXConstructorDecl *D, @@ -145,7 +154,9 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXConstructorDecl *D, for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) ArgTys.push_back(FTP->getArgType(i)); - return getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo()); + CallingConv CC = Context.Target.isWin64() ? CC_Win64ThisCall : CC_Default; + + return getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo().withCallingConv(CC)); } const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXDestructorDecl *D, @@ -159,7 +170,9 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXDestructorDecl *D, CanQual FTP = GetFormalType(D); assert(FTP->getNumArgs() == 0 && "dtor with formal parameters"); - return getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo()); + CallingConv CC = Context.Target.isWin64() ? CC_Win64ThisCall : CC_Default; + + return getFunctionInfo(ResTy, ArgTys, FTP->getExtInfo().withCallingConv(CC)); } const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) { @@ -250,8 +263,8 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(CanQualType ResTy, return *FI; // Construct the function info. - FI = new CGFunctionInfo(CC, Info.getNoReturn(), Info.getRegParm(), ResTy, - ArgTys.data(), ArgTys.size()); + FI = new CGFunctionInfo(CC, Info.getNoReturn(), Info.getRegParm(), + ResTy, ArgTys.data(), ArgTys.size()); FunctionInfos.InsertNode(FI, InsertPos); // Compute ABI information. diff --git a/lib/CodeGen/CGDeclCXX.cpp b/lib/CodeGen/CGDeclCXX.cpp index 8b37e9af3c..e9c6d003de 100644 --- a/lib/CodeGen/CGDeclCXX.cpp +++ b/lib/CodeGen/CGDeclCXX.cpp @@ -261,7 +261,7 @@ void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D, llvm::GlobalVariable *Addr) { StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(), - SourceLocation()); + SourceLocation(), CC_Default); // Use guarded initialization if the global variable is weak due to // being a class template's static data member. @@ -278,7 +278,7 @@ void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, llvm::Constant **Decls, unsigned NumDecls) { StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(), - SourceLocation()); + SourceLocation(), CC_Default); for (unsigned i = 0; i != NumDecls; ++i) if (Decls[i]) @@ -290,8 +290,10 @@ void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn, void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn, const std::vector > &DtorsAndObjects) { + const bool IsWin64 = getContext().Target.isWin64(); + StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(), - SourceLocation()); + SourceLocation(), IsWin64 ? CC_Win64ThisCall : CC_Default); // Emit the dtors, in reverse order from construction. for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) { @@ -327,7 +329,8 @@ CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D, llvm::Function *Fn = CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor"); - StartFunction(GlobalDecl(), getContext().VoidTy, Fn, Args, SourceLocation()); + StartFunction(GlobalDecl(), getContext().VoidTy, Fn, Args, SourceLocation(), + CC_Default); QualType BaseElementTy = getContext().getBaseElementType(Array); const llvm::Type *BasePtr = ConvertType(BaseElementTy)->getPointerTo(); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 0f9abc7c35..f2cd951d27 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2121,7 +2121,7 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, llvm::Value *Callee, CallArgList Args; EmitCallArgs(Args, dyn_cast(FnType), ArgBeg, ArgEnd); - return EmitCall(CGM.getTypes().getFunctionInfo(Args, FnType), + return EmitCall(CGM.getTypes().getFunctionInfo(Args, FnType, CC_Default), Callee, ReturnValue, Args, TargetDecl); } diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index bba7864bff..06d04a5e52 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -48,8 +48,13 @@ RValue CodeGenFunction::EmitCXXMemberCall(const CXXMethodDecl *MD, EmitCallArgs(Args, FPT, ArgBeg, ArgEnd); QualType ResultType = FPT->getResultType(); - return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args, - FPT->getExtInfo()), + FunctionType::ExtInfo Info = FPT->getExtInfo(); + + if (getContext().Target.isWin64()) { + Info = Info.withCallingConv(CC_Win64ThisCall); + } + + return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args, Info), Callee, ReturnValue, Args, MD); } @@ -292,8 +297,11 @@ CodeGenFunction::EmitCXXMemberPointerCallExpr(const CXXMemberCallExpr *E, // And the rest of the call args EmitCallArgs(Args, FPT, E->arg_begin(), E->arg_end()); const FunctionType *BO_FPT = BO->getType()->getAs(); - return EmitCall(CGM.getTypes().getFunctionInfo(Args, BO_FPT), Callee, - ReturnValue, Args); + + const CGFunctionInfo &FI = CGM.getTypes().getFunctionInfo(Args, BO_FPT, + CGM.getContext().Target.isWin64() ? CC_Win64ThisCall : CC_Default); + + return EmitCall(FI , Callee, ReturnValue, Args); } RValue @@ -810,8 +818,10 @@ namespace { for (unsigned I = 0; I != NumPlacementArgs; ++I) DeleteArgs.push_back(std::make_pair(getPlacementArgs()[I], *AI++)); + // FIXME Check whether this needs thiscall on Win64. // Call 'operator delete'. - CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(DeleteArgs, FPT), + CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(DeleteArgs, FPT, + CC_Default), CGF.CGM.GetAddrOfFunction(OperatorDelete), ReturnValueSlot(), DeleteArgs, OperatorDelete); } @@ -871,8 +881,10 @@ namespace { DeleteArgs.push_back(std::make_pair(RV, *AI++)); } + // FIXME Check whether this needs thiscall on Win64. // Call 'operator delete'. - CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(DeleteArgs, FPT), + CGF.EmitCall(CGF.CGM.getTypes().getFunctionInfo(DeleteArgs, FPT, + CC_Default), CGF.CGM.GetAddrOfFunction(OperatorDelete), ReturnValueSlot(), DeleteArgs, OperatorDelete); } @@ -976,7 +988,7 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) { // Emit the call to new. RValue RV = - EmitCall(CGM.getTypes().getFunctionInfo(NewArgs, NewFTy), + EmitCall(CGM.getTypes().getFunctionInfo(NewArgs, NewFTy, CC_Default), CGM.GetAddrOfFunction(NewFD), ReturnValueSlot(), NewArgs, NewFD); // If an allocation function is declared with an empty exception specification @@ -1086,7 +1098,7 @@ void CodeGenFunction::EmitDeleteCall(const FunctionDecl *DeleteFD, DeleteArgs.push_back(std::make_pair(RValue::get(Size), SizeTy)); // Emit the call to delete. - EmitCall(CGM.getTypes().getFunctionInfo(DeleteArgs, DeleteFTy), + EmitCall(CGM.getTypes().getFunctionInfo(DeleteArgs, DeleteFTy, CC_Default), CGM.GetAddrOfFunction(DeleteFD), ReturnValueSlot(), DeleteArgs, DeleteFD); } @@ -1207,7 +1219,7 @@ namespace { } // Emit the call to delete. - CGF.EmitCall(CGF.getTypes().getFunctionInfo(Args, DeleteFTy), + CGF.EmitCall(CGF.getTypes().getFunctionInfo(Args, DeleteFTy, CC_Default), CGF.CGM.GetAddrOfFunction(OperatorDelete), ReturnValueSlot(), Args, OperatorDelete); } diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 5d34907699..6ae1ac8a49 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -140,7 +140,8 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, CurGD = OMD; - StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocStart()); + StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocStart(), + CC_Default); } void CodeGenFunction::GenerateObjCGetterBody(ObjCIvarDecl *Ivar, diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 891697f4cd..6acbe436c8 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -2582,8 +2582,11 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn, GlobalDecl GD, FunctionArgs.push_back(std::make_pair(Param, Param->getType())); } - - StartFunction(GlobalDecl(), ResultType, Fn, FunctionArgs, SourceLocation()); + + const bool IsWin64 = CGM.getContext().Target.isWin64(); + + StartFunction(GlobalDecl(), ResultType, Fn, FunctionArgs, SourceLocation(), + IsWin64 ? CC_Win64ThisCall : CC_Default); CGM.getCXXABI().EmitInstanceFunctionProlog(*this); @@ -2614,9 +2617,14 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn, GlobalDecl GD, FPT->isVariadic()); llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); + FunctionType::ExtInfo Info = FPT->getExtInfo(); + + if (IsWin64) { + Info = Info.withCallingConv(CC_Win64ThisCall); + } + const CGFunctionInfo &FnInfo = - CGM.getTypes().getFunctionInfo(ResultType, CallArgs, - FPT->getExtInfo()); + CGM.getTypes().getFunctionInfo(ResultType, CallArgs, Info); // Determine whether we have a return value slot to use. ReturnValueSlot Slot; diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 4ab327712a..9660b071e2 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -211,7 +211,8 @@ void CodeGenFunction::EmitMCountInstrumentation() { void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, - SourceLocation StartLoc) { + SourceLocation StartLoc, + CallingConv CC) { const Decl *D = GD.getDecl(); DidCallStackSave = false; @@ -278,7 +279,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, // FIXME: Leaked. // CC info is ignored, hopefully? CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args, - FunctionType::ExtInfo()); + FunctionType::ExtInfo().withCallingConv(CC)); if (RetTy->isVoidType()) { // Void type; nothing to return. @@ -359,7 +360,7 @@ void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) { if (Stmt *Body = FD->getBody()) BodyRange = Body->getSourceRange(); // Emit the standard function prologue. - StartFunction(GD, ResTy, Fn, Args, BodyRange.getBegin()); + StartFunction(GD, ResTy, Fn, Args, BodyRange.getBegin(), CC_Default); // Generate the body of the function. if (isa(FD)) diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index ef006d9b20..25fbd8146e 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1126,7 +1126,8 @@ public: void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, - SourceLocation StartLoc); + SourceLocation StartLoc, + CallingConv CC); void EmitConstructorBody(FunctionArgList &Args); void EmitDestructorBody(FunctionArgList &Args); diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h index 41513daf17..6bf3f92ada 100644 --- a/lib/CodeGen/CodeGenTypes.h +++ b/lib/CodeGen/CodeGenTypes.h @@ -161,9 +161,11 @@ public: CXXDtorType Type); const CGFunctionInfo &getFunctionInfo(const CallArgList &Args, - const FunctionType *Ty) { - return getFunctionInfo(Ty->getResultType(), Args, - Ty->getExtInfo()); + const FunctionType *Ty, + CallingConv CC) { + FunctionType::ExtInfo Info = Ty->getExtInfo().withCallingConv(CC); + + return getFunctionInfo(Ty->getResultType(), Args, Info); } const CGFunctionInfo &getFunctionInfo(CanQual Ty, diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 2ffc840b9f..14a6e0a589 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -942,6 +942,26 @@ public: return false; } + + void SetTargetAttributes(const Decl *D, + llvm::GlobalValue *GV, + CodeGen::CodeGenModule &M) const { + if (M.getContext().Target.isWin64()) { + if (const FunctionDecl *FD = dyn_cast(D)) { + const CXXMethodDecl *M = dyn_cast(FD); + + if ((M && M->isInstance()) + || dyn_cast(FD) + || dyn_cast(FD)) { + // When using the MSVC Win64 ABI, methods/constructors/destructors + // use the Win64 thiscall calling convention. + llvm::Function *F = cast(GV); + F->setCallingConv(llvm::CallingConv::Win64_ThisCall); + } + } + } + } + }; } -- 2.40.0