Index: lib/CodeGen/StackProtector.cpp =================================================================== --- lib/CodeGen/StackProtector.cpp +++ lib/CodeGen/StackProtector.cpp @@ -422,7 +422,6 @@ CallInst *Call = B.CreateCall(GuardCheck, {Guard}); llvm::Function *Function = cast(GuardCheck); Call->setAttributes(Function->getAttributes()); - Call->setCallingConv(Function->getCallingConv()); } else { // Generate the epilogue with inline instrumentation. // If we do not support SelectionDAG based tail calls, generate IR level Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -281,6 +281,13 @@ // CallInst Implementation //===----------------------------------------------------------------------===// +template +static void tryCopyCallingConvention(CallTy *To, Value const *From) { + // ensure Calling Convention consistency if possible + if (Function const *F = dyn_cast(From->stripPointerCasts())) + To->setCallingConv(F->getCallingConv()); +} + void CallInst::init(FunctionType *FTy, Value *Func, ArrayRef Args, ArrayRef Bundles, const Twine &NameStr) { this->FTy = FTy; @@ -306,6 +313,7 @@ assert(It + 1 == op_end() && "Should add up!"); setName(NameStr); + tryCopyCallingConvention(this, Func); } void CallInst::init(Value *Func, const Twine &NameStr) { @@ -317,6 +325,7 @@ assert(FTy->getNumParams() == 0 && "Calling a function with bad signature"); setName(NameStr); + tryCopyCallingConvention(this, Func); } CallInst::CallInst(Value *Func, const Twine &Name, @@ -652,9 +661,6 @@ Result = CallInst::Create(FreeFunc, PtrCast, Bundles, ""); } Result->setTailCall(); - if (Function *F = dyn_cast(FreeFunc)) - Result->setCallingConv(F->getCallingConv()); - return Result; } @@ -718,6 +724,7 @@ assert(It + 3 == op_end() && "Should add up!"); setName(NameStr); + tryCopyCallingConvention(this, Fn); } InvokeInst::InvokeInst(const InvokeInst &II) Index: lib/Target/AMDGPU/AMDGPULibCalls.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPULibCalls.cpp +++ lib/Target/AMDGPU/AMDGPULibCalls.cpp @@ -220,8 +220,6 @@ CallInst *CreateCallEx(IRB &B, Value *Callee, Value *Arg, const Twine &Name="") { CallInst *R = B.CreateCall(Callee, Arg, Name); - if (Function* F = dyn_cast(Callee)) - R->setCallingConv(F->getCallingConv()); return R; } @@ -229,8 +227,6 @@ CallInst *CreateCallEx2(IRB &B, Value *Callee, Value *Arg1, Value *Arg2, const Twine &Name="") { CallInst *R = B.CreateCall(Callee, {Arg1, Arg2}, Name); - if (Function* F = dyn_cast(Callee)) - R->setCallingConv(F->getCallingConv()); return R; } Index: lib/Transforms/Utils/BuildLibCalls.cpp =================================================================== --- lib/Transforms/Utils/BuildLibCalls.cpp +++ lib/Transforms/Utils/BuildLibCalls.cpp @@ -727,9 +727,6 @@ B.getInt8PtrTy()); inferLibFuncAttributes(*M->getFunction("strlen"), *TLI); CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen"); - if (const Function *F = dyn_cast(StrLen->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -746,8 +743,6 @@ inferLibFuncAttributes(*M->getFunction("strchr"), *TLI); CallInst *CI = B.CreateCall( StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr"); - if (const Function *F = dyn_cast(StrChr->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -764,10 +759,6 @@ inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI); CallInst *CI = B.CreateCall( StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp"); - - if (const Function *F = dyn_cast(StrNCmp->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -782,8 +773,6 @@ inferLibFuncAttributes(*M->getFunction(Name), *TLI); CallInst *CI = B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name); - if (const Function *F = dyn_cast(StrCpy->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -799,8 +788,6 @@ inferLibFuncAttributes(*M->getFunction(Name), *TLI); CallInst *CI = B.CreateCall( StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy"); - if (const Function *F = dyn_cast(StrNCpy->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -822,8 +809,6 @@ Dst = castToCStr(Dst, B); Src = castToCStr(Src, B); CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); - if (const Function *F = dyn_cast(MemCpy->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -839,10 +824,6 @@ DL.getIntPtrType(Context)); inferLibFuncAttributes(*M->getFunction("memchr"), *TLI); CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr"); - - if (const Function *F = dyn_cast(MemChr->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -859,10 +840,6 @@ inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI); CallInst *CI = B.CreateCall( MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp"); - - if (const Function *F = dyn_cast(MemCmp->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -897,9 +874,6 @@ CI->setAttributes(Attrs.removeAttribute(B.getContext(), AttributeList::FunctionIndex, Attribute::Speculatable)); - if (const Function *F = dyn_cast(Callee->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -913,9 +887,6 @@ Op2->getType()); CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); CI->setAttributes(Attrs); - if (const Function *F = dyn_cast(Callee->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -933,9 +904,6 @@ /*isSigned*/true, "chari"), "putchar"); - - if (const Function *F = dyn_cast(PutChar->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -949,8 +917,6 @@ M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy()); inferLibFuncAttributes(*M->getFunction("puts"), *TLI); CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts"); - if (const Function *F = dyn_cast(PutS->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; } @@ -967,9 +933,6 @@ Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true, "chari"); CallInst *CI = B.CreateCall(F, {Char, File}, "fputc"); - - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) - CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -985,9 +948,6 @@ if (File->getType()->isPointerTy()) inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs"); - - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) - CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1008,8 +968,5 @@ CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, ConstantInt::get(DL.getIntPtrType(Context), 1), File}); - - if (const Function *Fn = dyn_cast(F->stripPointerCasts())) - CI->setCallingConv(Fn->getCallingConv()); return CI; } Index: lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- lib/Transforms/Utils/SimplifyLibCalls.cpp +++ lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -844,9 +844,6 @@ PtrType, PtrType); CallInst *CI = B.CreateCall(Calloc, { Num, Size }, "calloc"); - if (const auto *F = dyn_cast(Calloc->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); - return CI; } @@ -1280,8 +1277,6 @@ M->getOrInsertFunction(TLI->getName(LdExp), Op->getType(), Op->getType(), B.getInt32Ty()); CallInst *CI = B.CreateCall(NewCallee, {One, LdExpArg}); - if (const Function *F = dyn_cast(Callee->stripPointerCasts())) - CI->setCallingConv(F->getCallingConv()); return CI; }