@@ -1444,7 +1444,8 @@ static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
14441444Value *llvm::emitStrLen (Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
14451445 const TargetLibraryInfo *TLI) {
14461446 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1447- return emitLibCall (LibFunc_strlen, DL.getIntPtrType (Context),
1447+ Type *SizeTTy = DL.getIntPtrType (Context);
1448+ return emitLibCall (LibFunc_strlen, SizeTTy,
14481449 B.getInt8PtrTy (), castToCStr (Ptr, B), B, TLI);
14491450}
14501451
@@ -1457,17 +1458,19 @@ Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
14571458Value *llvm::emitStrChr (Value *Ptr, char C, IRBuilderBase &B,
14581459 const TargetLibraryInfo *TLI) {
14591460 Type *I8Ptr = B.getInt8PtrTy ();
1460- Type *I32Ty = B.getInt32Ty ();
1461- return emitLibCall (LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty },
1462- {castToCStr (Ptr, B), ConstantInt::get (I32Ty , C)}, B, TLI);
1461+ Type *IntTy = B.getInt32Ty ();
1462+ return emitLibCall (LibFunc_strchr, I8Ptr, {I8Ptr, IntTy },
1463+ {castToCStr (Ptr, B), ConstantInt::get (IntTy , C)}, B, TLI);
14631464}
14641465
14651466Value *llvm::emitStrNCmp (Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
14661467 const DataLayout &DL, const TargetLibraryInfo *TLI) {
14671468 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1469+ Type *SizeTTy = DL.getIntPtrType (Context);
1470+ Type *IntTy = B.getInt32Ty ();
14681471 return emitLibCall (
1469- LibFunc_strncmp, B. getInt32Ty () ,
1470- {B.getInt8PtrTy (), B.getInt8PtrTy (), DL. getIntPtrType (Context) },
1472+ LibFunc_strncmp, IntTy ,
1473+ {B.getInt8PtrTy (), B.getInt8PtrTy (), SizeTTy },
14711474 {castToCStr (Ptr1, B), castToCStr (Ptr2, B), Len}, B, TLI);
14721475}
14731476
@@ -1488,14 +1491,16 @@ Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
14881491Value *llvm::emitStrNCpy (Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
14891492 const TargetLibraryInfo *TLI) {
14901493 Type *I8Ptr = B.getInt8PtrTy ();
1491- return emitLibCall (LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType ()},
1494+ Type *SizeTTy = Len->getType ();
1495+ return emitLibCall (LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
14921496 {castToCStr (Dst, B), castToCStr (Src, B), Len}, B, TLI);
14931497}
14941498
14951499Value *llvm::emitStpNCpy (Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
14961500 const TargetLibraryInfo *TLI) {
14971501 Type *I8Ptr = B.getInt8PtrTy ();
1498- return emitLibCall (LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType ()},
1502+ Type *SizeTTy = Len->getType ();
1503+ return emitLibCall (LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
14991504 {castToCStr (Dst, B), castToCStr (Src, B), Len}, B, TLI);
15001505}
15011506
@@ -1510,10 +1515,11 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15101515 AS = AttributeList::get (M->getContext (), AttributeList::FunctionIndex,
15111516 Attribute::NoUnwind);
15121517 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1518+ Type *I8Ptr = B.getInt8PtrTy ();
1519+ Type *SizeTTy = DL.getIntPtrType (Context);
15131520 FunctionCallee MemCpy = getOrInsertLibFunc (M, *TLI, LibFunc_memcpy_chk,
1514- AttributeList::get (M->getContext (), AS), B.getInt8PtrTy (),
1515- B.getInt8PtrTy (), B.getInt8PtrTy (), DL.getIntPtrType (Context),
1516- DL.getIntPtrType (Context));
1521+ AttributeList::get (M->getContext (), AS), I8Ptr,
1522+ I8Ptr, I8Ptr, SizeTTy, SizeTTy);
15171523 Dst = castToCStr (Dst, B);
15181524 Src = castToCStr (Src, B);
15191525 CallInst *CI = B.CreateCall (MemCpy, {Dst, Src, Len, ObjSize});
@@ -1526,73 +1532,92 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15261532Value *llvm::emitMemPCpy (Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15271533 const DataLayout &DL, const TargetLibraryInfo *TLI) {
15281534 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1529- return emitLibCall (
1530- LibFunc_mempcpy, B.getInt8PtrTy (),
1531- {B.getInt8PtrTy (), B.getInt8PtrTy (), DL.getIntPtrType (Context)},
1532- {Dst, Src, Len}, B, TLI);
1535+ Type *I8Ptr = B.getInt8PtrTy ();
1536+ Type *SizeTTy = DL.getIntPtrType (Context);
1537+ return emitLibCall (LibFunc_mempcpy, I8Ptr,
1538+ {I8Ptr, I8Ptr, SizeTTy},
1539+ {Dst, Src, Len}, B, TLI);
15331540}
15341541
15351542Value *llvm::emitMemChr (Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15361543 const DataLayout &DL, const TargetLibraryInfo *TLI) {
15371544 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1538- return emitLibCall (
1539- LibFunc_memchr, B.getInt8PtrTy (),
1540- {B.getInt8PtrTy (), B.getInt32Ty (), DL.getIntPtrType (Context)},
1541- {castToCStr (Ptr, B), Val, Len}, B, TLI);
1545+ Type *I8Ptr = B.getInt8PtrTy ();
1546+ Type *IntTy = B.getInt32Ty ();
1547+ Type *SizeTTy = DL.getIntPtrType (Context);
1548+ return emitLibCall (LibFunc_memchr, I8Ptr,
1549+ {I8Ptr, IntTy, SizeTTy},
1550+ {castToCStr (Ptr, B), Val, Len}, B, TLI);
15421551}
15431552
15441553Value *llvm::emitMemRChr (Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15451554 const DataLayout &DL, const TargetLibraryInfo *TLI) {
15461555 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1547- return emitLibCall (
1548- LibFunc_memrchr, B.getInt8PtrTy (),
1549- {B.getInt8PtrTy (), B.getInt32Ty (), DL.getIntPtrType (Context)},
1550- {castToCStr (Ptr, B), Val, Len}, B, TLI);
1556+ Type *I8Ptr = B.getInt8PtrTy ();
1557+ Type *IntTy = B.getInt32Ty ();
1558+ Type *SizeTTy = DL.getIntPtrType (Context);
1559+ return emitLibCall (LibFunc_memrchr, I8Ptr,
1560+ {I8Ptr, IntTy, SizeTTy},
1561+ {castToCStr (Ptr, B), Val, Len}, B, TLI);
15511562}
15521563
15531564Value *llvm::emitMemCmp (Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15541565 const DataLayout &DL, const TargetLibraryInfo *TLI) {
15551566 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1567+ Type *I8Ptr = B.getInt8PtrTy ();
1568+ Type *IntTy = B.getInt32Ty ();
1569+ Type *SizeTTy = DL.getIntPtrType (Context);
15561570 return emitLibCall (
1557- LibFunc_memcmp, B. getInt32Ty () ,
1558- {B. getInt8PtrTy (), B. getInt8PtrTy (), DL. getIntPtrType (Context) },
1571+ LibFunc_memcmp, IntTy ,
1572+ {I8Ptr, I8Ptr, SizeTTy },
15591573 {castToCStr (Ptr1, B), castToCStr (Ptr2, B), Len}, B, TLI);
15601574}
15611575
15621576Value *llvm::emitBCmp (Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15631577 const DataLayout &DL, const TargetLibraryInfo *TLI) {
15641578 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1579+ Type *I8Ptr = B.getInt8PtrTy ();
1580+ Type *IntTy = B.getInt32Ty ();
1581+ Type *SizeTTy = DL.getIntPtrType (Context);
15651582 return emitLibCall (
1566- LibFunc_bcmp, B. getInt32Ty () ,
1567- {B. getInt8PtrTy (), B. getInt8PtrTy (), DL. getIntPtrType (Context) },
1583+ LibFunc_bcmp, IntTy ,
1584+ {I8Ptr, I8Ptr, SizeTTy },
15681585 {castToCStr (Ptr1, B), castToCStr (Ptr2, B), Len}, B, TLI);
15691586}
15701587
15711588Value *llvm::emitMemCCpy (Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
15721589 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1590+ Type *I8Ptr = B.getInt8PtrTy ();
1591+ Type *IntTy = B.getInt32Ty ();
1592+ Type *SizeTTy = Len->getType ();
15731593 return emitLibCall (
1574- LibFunc_memccpy, B. getInt8PtrTy () ,
1575- {B. getInt8PtrTy (), B. getInt8PtrTy (), B. getInt32Ty (), Len-> getType () },
1594+ LibFunc_memccpy, I8Ptr ,
1595+ {I8Ptr, I8Ptr, IntTy, SizeTTy },
15761596 {Ptr1, Ptr2, Val, Len}, B, TLI);
15771597}
15781598
15791599Value *llvm::emitSNPrintf (Value *Dest, Value *Size, Value *Fmt,
15801600 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
15811601 const TargetLibraryInfo *TLI) {
1602+ Type *I8Ptr = B.getInt8PtrTy ();
1603+ Type *IntTy = B.getInt32Ty ();
1604+ Type *SizeTTy = Size->getType ();
15821605 SmallVector<Value *, 8 > Args{castToCStr (Dest, B), Size, castToCStr (Fmt, B)};
15831606 llvm::append_range (Args, VariadicArgs);
1584- return emitLibCall (LibFunc_snprintf, B. getInt32Ty () ,
1585- {B. getInt8PtrTy (), Size-> getType (), B. getInt8PtrTy () },
1607+ return emitLibCall (LibFunc_snprintf, IntTy ,
1608+ {I8Ptr, SizeTTy, I8Ptr },
15861609 Args, B, TLI, /* IsVaArgs=*/ true );
15871610}
15881611
15891612Value *llvm::emitSPrintf (Value *Dest, Value *Fmt,
15901613 ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
15911614 const TargetLibraryInfo *TLI) {
1615+ Type *I8Ptr = B.getInt8PtrTy ();
1616+ Type *IntTy = B.getInt32Ty ();
15921617 SmallVector<Value *, 8 > Args{castToCStr (Dest, B), castToCStr (Fmt, B)};
15931618 llvm::append_range (Args, VariadicArgs);
1594- return emitLibCall (LibFunc_sprintf, B. getInt32Ty () ,
1595- {B. getInt8PtrTy (), B. getInt8PtrTy () }, Args, B, TLI,
1619+ return emitLibCall (LibFunc_sprintf, IntTy ,
1620+ {I8Ptr, I8Ptr }, Args, B, TLI,
15961621 /* IsVaArgs=*/ true );
15971622}
15981623
@@ -1605,37 +1630,48 @@ Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
16051630
16061631Value *llvm::emitStrLCpy (Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16071632 const TargetLibraryInfo *TLI) {
1608- return emitLibCall (LibFunc_strlcpy, Size->getType (),
1609- {B.getInt8PtrTy (), B.getInt8PtrTy (), Size->getType ()},
1633+ Type *I8Ptr = B.getInt8PtrTy ();
1634+ Type *SizeTTy = Size->getType ();
1635+ return emitLibCall (LibFunc_strlcpy, SizeTTy,
1636+ {I8Ptr, I8Ptr, SizeTTy},
16101637 {castToCStr (Dest, B), castToCStr (Src, B), Size}, B, TLI);
16111638}
16121639
16131640Value *llvm::emitStrLCat (Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16141641 const TargetLibraryInfo *TLI) {
1615- return emitLibCall (LibFunc_strlcat, Size->getType (),
1616- {B.getInt8PtrTy (), B.getInt8PtrTy (), Size->getType ()},
1642+ Type *I8Ptr = B.getInt8PtrTy ();
1643+ Type *SizeTTy = Size->getType ();
1644+ return emitLibCall (LibFunc_strlcat, SizeTTy,
1645+ {I8Ptr, I8Ptr, SizeTTy},
16171646 {castToCStr (Dest, B), castToCStr (Src, B), Size}, B, TLI);
16181647}
16191648
16201649Value *llvm::emitStrNCat (Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16211650 const TargetLibraryInfo *TLI) {
1622- return emitLibCall (LibFunc_strncat, B.getInt8PtrTy (),
1623- {B.getInt8PtrTy (), B.getInt8PtrTy (), Size->getType ()},
1651+ Type *I8Ptr = B.getInt8PtrTy ();
1652+ Type *SizeTTy = Size->getType ();
1653+ return emitLibCall (LibFunc_strncat, I8Ptr,
1654+ {I8Ptr, I8Ptr, SizeTTy},
16241655 {castToCStr (Dest, B), castToCStr (Src, B), Size}, B, TLI);
16251656}
16261657
16271658Value *llvm::emitVSNPrintf (Value *Dest, Value *Size, Value *Fmt, Value *VAList,
16281659 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1660+ Type *I8Ptr = B.getInt8PtrTy ();
1661+ Type *IntTy = B.getInt32Ty ();
1662+ Type *SizeTTy = Size->getType ();
16291663 return emitLibCall (
1630- LibFunc_vsnprintf, B. getInt32Ty () ,
1631- {B. getInt8PtrTy (), Size-> getType (), B. getInt8PtrTy () , VAList->getType ()},
1664+ LibFunc_vsnprintf, IntTy ,
1665+ {I8Ptr, SizeTTy, I8Ptr , VAList->getType ()},
16321666 {castToCStr (Dest, B), Size, castToCStr (Fmt, B), VAList}, B, TLI);
16331667}
16341668
16351669Value *llvm::emitVSPrintf (Value *Dest, Value *Fmt, Value *VAList,
16361670 IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1637- return emitLibCall (LibFunc_vsprintf, B.getInt32Ty (),
1638- {B.getInt8PtrTy (), B.getInt8PtrTy (), VAList->getType ()},
1671+ Type *I8Ptr = B.getInt8PtrTy ();
1672+ Type *IntTy = B.getInt32Ty ();
1673+ return emitLibCall (LibFunc_vsprintf, IntTy,
1674+ {I8Ptr, I8Ptr, VAList->getType ()},
16391675 {castToCStr (Dest, B), castToCStr (Fmt, B), VAList}, B, TLI);
16401676}
16411677
@@ -1764,9 +1800,10 @@ Value *llvm::emitPutChar(Value *Char, IRBuilderBase &B,
17641800 if (!isLibFuncEmittable (M, TLI, LibFunc_putchar))
17651801 return nullptr ;
17661802
1767- Type *Ty = Char->getType ();
1803+ Type *IntTy = Char->getType ();
17681804 StringRef PutCharName = TLI->getName (LibFunc_putchar);
1769- FunctionCallee PutChar = getOrInsertLibFunc (M, *TLI, LibFunc_putchar, Ty, Ty);
1805+ FunctionCallee PutChar = getOrInsertLibFunc (M, *TLI, LibFunc_putchar,
1806+ IntTy, IntTy);
17701807 inferNonMandatoryLibFuncAttrs (M, PutCharName, *TLI);
17711808 CallInst *CI = B.CreateCall (PutChar, Char, PutCharName);
17721809
@@ -1782,8 +1819,9 @@ Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
17821819 if (!isLibFuncEmittable (M, TLI, LibFunc_puts))
17831820 return nullptr ;
17841821
1822+ Type *IntTy = B.getInt32Ty ();
17851823 StringRef PutsName = TLI->getName (LibFunc_puts);
1786- FunctionCallee PutS = getOrInsertLibFunc (M, *TLI, LibFunc_puts, B. getInt32Ty () ,
1824+ FunctionCallee PutS = getOrInsertLibFunc (M, *TLI, LibFunc_puts, IntTy ,
17871825 B.getInt8PtrTy ());
17881826 inferNonMandatoryLibFuncAttrs (M, PutsName, *TLI);
17891827 CallInst *CI = B.CreateCall (PutS, castToCStr (Str, B), PutsName);
@@ -1799,12 +1837,13 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
17991837 if (!isLibFuncEmittable (M, TLI, LibFunc_fputc))
18001838 return nullptr ;
18011839
1840+ Type *IntTy = B.getInt32Ty ();
18021841 StringRef FPutcName = TLI->getName (LibFunc_fputc);
1803- FunctionCallee F = getOrInsertLibFunc (M, *TLI, LibFunc_fputc, B. getInt32Ty () ,
1804- B. getInt32Ty () , File->getType ());
1842+ FunctionCallee F = getOrInsertLibFunc (M, *TLI, LibFunc_fputc, IntTy ,
1843+ IntTy , File->getType ());
18051844 if (File->getType ()->isPointerTy ())
18061845 inferNonMandatoryLibFuncAttrs (M, FPutcName, *TLI);
1807- Char = B.CreateIntCast (Char, B. getInt32Ty () , /* isSigned*/ true ,
1846+ Char = B.CreateIntCast (Char, IntTy , /* isSigned*/ true ,
18081847 " chari" );
18091848 CallInst *CI = B.CreateCall (F, {Char, File}, FPutcName);
18101849
@@ -1820,8 +1859,9 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
18201859 if (!isLibFuncEmittable (M, TLI, LibFunc_fputs))
18211860 return nullptr ;
18221861
1862+ Type *IntTy = B.getInt32Ty ();
18231863 StringRef FPutsName = TLI->getName (LibFunc_fputs);
1824- FunctionCallee F = getOrInsertLibFunc (M, *TLI, LibFunc_fputs, B. getInt32Ty () ,
1864+ FunctionCallee F = getOrInsertLibFunc (M, *TLI, LibFunc_fputs, IntTy ,
18251865 B.getInt8PtrTy (), File->getType ());
18261866 if (File->getType ()->isPointerTy ())
18271867 inferNonMandatoryLibFuncAttrs (M, FPutsName, *TLI);
@@ -1840,10 +1880,11 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
18401880 return nullptr ;
18411881
18421882 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1883+ Type *SizeTTy = DL.getIntPtrType (Context);
18431884 StringRef FWriteName = TLI->getName (LibFunc_fwrite);
18441885 FunctionCallee F = getOrInsertLibFunc (M, *TLI, LibFunc_fwrite,
1845- DL. getIntPtrType (Context) , B.getInt8PtrTy (), DL. getIntPtrType (Context) ,
1846- DL. getIntPtrType (Context) , File->getType ());
1886+ SizeTTy , B.getInt8PtrTy (), SizeTTy ,
1887+ SizeTTy , File->getType ());
18471888
18481889 if (File->getType ()->isPointerTy ())
18491890 inferNonMandatoryLibFuncAttrs (M, FWriteName, *TLI);
@@ -1865,8 +1906,9 @@ Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
18651906
18661907 StringRef MallocName = TLI->getName (LibFunc_malloc);
18671908 LLVMContext &Context = B.GetInsertBlock ()->getContext ();
1909+ Type *SizeTTy = DL.getIntPtrType (Context);
18681910 FunctionCallee Malloc = getOrInsertLibFunc (M, *TLI, LibFunc_malloc,
1869- B.getInt8PtrTy (), DL. getIntPtrType (Context) );
1911+ B.getInt8PtrTy (), SizeTTy );
18701912 inferNonMandatoryLibFuncAttrs (M, MallocName, *TLI);
18711913 CallInst *CI = B.CreateCall (Malloc, Num, MallocName);
18721914
@@ -1884,10 +1926,11 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
18841926 return nullptr ;
18851927
18861928 StringRef CallocName = TLI.getName (LibFunc_calloc);
1929+ LLVMContext &Context = B.GetInsertBlock ()->getContext ();
18871930 const DataLayout &DL = M->getDataLayout ();
1888- IntegerType *PtrType = DL.getIntPtrType ((B. GetInsertBlock ()-> getContext ()) );
1931+ Type *SizeTTy = DL.getIntPtrType (Context );
18891932 FunctionCallee Calloc = getOrInsertLibFunc (M, TLI, LibFunc_calloc,
1890- B.getInt8PtrTy (), PtrType, PtrType );
1933+ B.getInt8PtrTy (), SizeTTy, SizeTTy );
18911934 inferNonMandatoryLibFuncAttrs (M, CallocName, TLI);
18921935 CallInst *CI = B.CreateCall (Calloc, {Num, Size}, CallocName);
18931936
0 commit comments