diff options
author | James Y Knight <jyknight@google.com> | 2019-02-01 02:28:03 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2019-02-01 02:28:03 +0000 |
commit | 13680223b9d80bb01e17372f0907cf215e424cce (patch) | |
tree | 774a79c2eef0e125cf5beb33a7515f581397c398 /llvm/lib/Transforms/Utils/BuildLibCalls.cpp | |
parent | b4744d306c0a21933d4339fa4fb497866a36ee49 (diff) | |
download | bcm5719-llvm-13680223b9d80bb01e17372f0907cf215e424cce.tar.gz bcm5719-llvm-13680223b9d80bb01e17372f0907cf215e424cce.zip |
[opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.
Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.
Then:
- update the CallInst/InvokeInst instruction creation functions to
take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.
One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.
However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)
Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.
Differential Revision: https://reviews.llvm.org/D57315
llvm-svn: 352827
Diffstat (limited to 'llvm/lib/Transforms/Utils/BuildLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 150 |
1 files changed, 87 insertions, 63 deletions
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 348d5b0df67..568850876a2 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -797,11 +797,12 @@ Value *llvm::emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL, Module *M = B.GetInsertBlock()->getModule(); StringRef StrlenName = TLI->getName(LibFunc_strlen); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Constant *StrLen = M->getOrInsertFunction(StrlenName, DL.getIntPtrType(Context), - B.getInt8PtrTy()); + FunctionCallee StrLen = M->getOrInsertFunction( + StrlenName, DL.getIntPtrType(Context), B.getInt8PtrTy()); inferLibFuncAttributes(M, StrlenName, *TLI); CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), StrlenName); - if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrLen.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -816,12 +817,13 @@ Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B, StringRef StrChrName = TLI->getName(LibFunc_strchr); Type *I8Ptr = B.getInt8PtrTy(); Type *I32Ty = B.getInt32Ty(); - Constant *StrChr = + FunctionCallee StrChr = M->getOrInsertFunction(StrChrName, I8Ptr, I8Ptr, I32Ty); inferLibFuncAttributes(M, StrChrName, *TLI); CallInst *CI = B.CreateCall( StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, StrChrName); - if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrChr.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -834,14 +836,15 @@ Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef StrNCmpName = TLI->getName(LibFunc_strncmp); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Value *StrNCmp = M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(), - B.getInt8PtrTy(), B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee StrNCmp = + M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(), B.getInt8PtrTy(), + B.getInt8PtrTy(), DL.getIntPtrType(Context)); inferLibFuncAttributes(M, StrNCmpName, *TLI); CallInst *CI = B.CreateCall( StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, StrNCmpName); - if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrNCmp.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -854,11 +857,12 @@ Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr); + FunctionCallee StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr); inferLibFuncAttributes(M, Name, *TLI); CallInst *CI = B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name); - if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -870,12 +874,13 @@ Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); Type *I8Ptr = B.getInt8PtrTy(); - Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, - Len->getType()); + FunctionCallee StrNCpy = + M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr, Len->getType()); inferLibFuncAttributes(M, Name, *TLI); CallInst *CI = B.CreateCall( StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, Name); - if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(StrNCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -891,14 +896,15 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex, Attribute::NoUnwind); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Value *MemCpy = M->getOrInsertFunction( + FunctionCallee MemCpy = M->getOrInsertFunction( "__memcpy_chk", AttributeList::get(M->getContext(), AS), B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context)); Dst = castToCStr(Dst, B); Src = castToCStr(Src, B); CallInst *CI = B.CreateCall(MemCpy, {Dst, Src, Len, ObjSize}); - if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -911,13 +917,14 @@ Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef MemChrName = TLI->getName(LibFunc_memchr); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Value *MemChr = M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(), - B.getInt8PtrTy(), B.getInt32Ty(), - DL.getIntPtrType(Context)); + FunctionCallee MemChr = + M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(), B.getInt8PtrTy(), + B.getInt32Ty(), DL.getIntPtrType(Context)); inferLibFuncAttributes(M, MemChrName, *TLI); CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, MemChrName); - if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemChr.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -931,14 +938,15 @@ Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef MemCmpName = TLI->getName(LibFunc_memcmp); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Value *MemCmp = M->getOrInsertFunction(MemCmpName, B.getInt32Ty(), - B.getInt8PtrTy(), B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee MemCmp = + M->getOrInsertFunction(MemCmpName, B.getInt32Ty(), B.getInt8PtrTy(), + B.getInt8PtrTy(), DL.getIntPtrType(Context)); inferLibFuncAttributes(M, MemCmpName, *TLI); CallInst *CI = B.CreateCall( MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, MemCmpName); - if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(MemCmp.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -965,8 +973,8 @@ static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name, assert((Name != "") && "Must specify Name to emitUnaryFloatFnCall"); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op->getType(), - Op->getType()); + FunctionCallee Callee = + M->getOrInsertFunction(Name, Op->getType(), Op->getType()); CallInst *CI = B.CreateCall(Callee, Op, Name); // The incoming attribute set may have come from a speculatable intrinsic, but @@ -975,7 +983,8 @@ static Value *emitUnaryFloatFnCallHelper(Value *Op, StringRef Name, CI->setAttributes(Attrs.removeAttribute(B.getContext(), AttributeList::FunctionIndex, Attribute::Speculatable)); - if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1008,11 +1017,12 @@ Value *llvm::emitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name, appendTypeSuffix(Op1, Name, NameBuffer); Module *M = B.GetInsertBlock()->getModule(); - Value *Callee = M->getOrInsertFunction(Name, Op1->getType(), Op1->getType(), - Op2->getType()); + FunctionCallee Callee = M->getOrInsertFunction( + Name, Op1->getType(), Op1->getType(), Op2->getType()); CallInst *CI = B.CreateCall(Callee, {Op1, Op2}, Name); CI->setAttributes(Attrs); - if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1025,7 +1035,8 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef PutCharName = TLI->getName(LibFunc_putchar); - Value *PutChar = M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty()); + FunctionCallee PutChar = + M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty()); inferLibFuncAttributes(M, PutCharName, *TLI); CallInst *CI = B.CreateCall(PutChar, B.CreateIntCast(Char, @@ -1034,7 +1045,8 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B, "chari"), PutCharName); - if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(PutChar.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -1046,11 +1058,12 @@ Value *llvm::emitPutS(Value *Str, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef PutsName = TLI->getName(LibFunc_puts); - Value *PutS = + FunctionCallee PutS = M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy()); inferLibFuncAttributes(M, PutsName, *TLI); CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName); - if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(PutS.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; } @@ -1062,15 +1075,16 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcName = TLI->getName(LibFunc_fputc); - Constant *F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), B.getInt32Ty(), - File->getType()); + FunctionCallee F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), + B.getInt32Ty(), File->getType()); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutcName, *TLI); Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true, "chari"); CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1082,14 +1096,15 @@ Value *llvm::emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked); - Constant *F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(), - B.getInt32Ty(), File->getType()); + FunctionCallee F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(), + B.getInt32Ty(), File->getType()); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutcUnlockedName, *TLI); Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari"); CallInst *CI = B.CreateCall(F, {Char, File}, FPutcUnlockedName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1101,13 +1116,14 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsName = TLI->getName(LibFunc_fputs); - Constant *F = M->getOrInsertFunction( - FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType()); + FunctionCallee F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(), + B.getInt8PtrTy(), File->getType()); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutsName, *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1119,13 +1135,14 @@ Value *llvm::emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FPutsUnlockedName = TLI->getName(LibFunc_fputs_unlocked); - Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(), - B.getInt8PtrTy(), File->getType()); + FunctionCallee F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(), + B.getInt8PtrTy(), File->getType()); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FPutsUnlockedName, *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsUnlockedName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1138,7 +1155,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FWriteName = TLI->getName(LibFunc_fwrite); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FWriteName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1148,7 +1165,8 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B, B.CreateCall(F, {castToCStr(Ptr, B), Size, ConstantInt::get(DL.getIntPtrType(Context), 1), File}); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1161,12 +1179,13 @@ Value *llvm::emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL, Module *M = B.GetInsertBlock()->getModule(); StringRef MallocName = TLI->getName(LibFunc_malloc); LLVMContext &Context = B.GetInsertBlock()->getContext(); - Value *Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(), - DL.getIntPtrType(Context)); + FunctionCallee Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(), + DL.getIntPtrType(Context)); inferLibFuncAttributes(M, MallocName, *TLI); CallInst *CI = B.CreateCall(Malloc, Num, MallocName); - if (const Function *F = dyn_cast<Function>(Malloc->stripPointerCasts())) + if (const Function *F = + dyn_cast<Function>(Malloc.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1181,12 +1200,13 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs, StringRef CallocName = TLI.getName(LibFunc_calloc); const DataLayout &DL = M->getDataLayout(); IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext())); - Value *Calloc = M->getOrInsertFunction(CallocName, Attrs, B.getInt8PtrTy(), - PtrType, PtrType); + FunctionCallee Calloc = M->getOrInsertFunction( + CallocName, Attrs, B.getInt8PtrTy(), PtrType, PtrType); inferLibFuncAttributes(M, CallocName, TLI); CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName); - if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts())) + if (const auto *F = + dyn_cast<Function>(Calloc.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); return CI; @@ -1201,7 +1221,7 @@ Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FWriteUnlockedName = TLI->getName(LibFunc_fwrite_unlocked); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FWriteUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1209,7 +1229,8 @@ Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, inferLibFuncAttributes(M, FWriteUnlockedName, *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File}); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1221,13 +1242,14 @@ Value *llvm::emitFGetCUnlocked(Value *File, IRBuilder<> &B, Module *M = B.GetInsertBlock()->getModule(); StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked); - Constant *F = - M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), File->getType()); + FunctionCallee F = M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), + File->getType()); if (File->getType()->isPointerTy()) inferLibFuncAttributes(M, FGetCUnlockedName, *TLI); CallInst *CI = B.CreateCall(F, File, FGetCUnlockedName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1239,14 +1261,15 @@ Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File, Module *M = B.GetInsertBlock()->getModule(); StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked); - Constant *F = + FunctionCallee F = M->getOrInsertFunction(FGetSUnlockedName, B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), File->getType()); inferLibFuncAttributes(M, FGetSUnlockedName, *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), Size, File}, FGetSUnlockedName); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } @@ -1260,7 +1283,7 @@ Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, Module *M = B.GetInsertBlock()->getModule(); LLVMContext &Context = B.GetInsertBlock()->getContext(); StringRef FReadUnlockedName = TLI->getName(LibFunc_fread_unlocked); - Constant *F = M->getOrInsertFunction( + FunctionCallee F = M->getOrInsertFunction( FReadUnlockedName, DL.getIntPtrType(Context), B.getInt8PtrTy(), DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType()); @@ -1268,7 +1291,8 @@ Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File, inferLibFuncAttributes(M, FReadUnlockedName, *TLI); CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File}); - if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts())) + if (const Function *Fn = + dyn_cast<Function>(F.getCallee()->stripPointerCasts())) CI->setCallingConv(Fn->getCallingConv()); return CI; } |