Skip to content

Commit aa1b64c

Browse files
committed
[BuildLibCalls] Use TLI to get 'int' and 'size_t' type sizes
Stop assuming that an 'int' is 32 bits in helpers that emit libcalls to lib functions that had 'int' in the signature. For most targets this is NFC. For a target with 16 bit 'int' type this could help out detecting if trying to emit a libcall with incorrect signature. Similarly we now derive the type mapping to 'size_t' by asking TLI about the size of 'size_t'. This should be NFC (at least for in-tree targets) since getSizeTSize(), in TLI, is deriving the size in the same way as DataLayout::getIntPtrType(). Differential Revision: https://reviews.llvm.org/D135065
1 parent 73e8d95 commit aa1b64c

File tree

6 files changed

+84
-79
lines changed

6 files changed

+84
-79
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ class IRBuilderBase {
558558
return Type::getInt8PtrTy(Context, AddrSpace);
559559
}
560560

561-
/// Fetch the type representing a pointer to an integer value.
561+
/// Fetch the type of an integer with size at least as big as that of a
562+
/// pointer in the given address space.
562563
IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
563564
return DL.getIntPtrType(Context, AddrSpace);
564565
}

llvm/include/llvm/Transforms/Utils/BuildLibCalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ namespace llvm {
237237
const TargetLibraryInfo *TLI);
238238

239239
/// Emit a call to the fwrite function. This assumes that Ptr is a pointer,
240-
/// Size is an 'intptr_t', and File is a pointer to FILE.
240+
/// Size is an 'size_t', and File is a pointer to FILE.
241241
Value *emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
242242
const DataLayout &DL, const TargetLibraryInfo *TLI);
243243

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,10 +1788,9 @@ struct DSEState {
17881788
!memoryIsNotModifiedBetween(Malloc, MemSet, BatchAA, DL, &DT))
17891789
return false;
17901790
IRBuilder<> IRB(Malloc);
1791-
const auto &DL = Malloc->getModule()->getDataLayout();
1792-
auto *Calloc =
1793-
emitCalloc(ConstantInt::get(IRB.getIntPtrTy(DL), 1),
1794-
Malloc->getArgOperand(0), IRB, TLI);
1791+
Type *SizeTTy = Malloc->getArgOperand(0)->getType();
1792+
auto *Calloc = emitCalloc(ConstantInt::get(SizeTTy, 1),
1793+
Malloc->getArgOperand(0), IRB, TLI);
17951794
if (!Calloc)
17961795
return false;
17971796
MemorySSAUpdater Updater(&MSSA);

llvm/lib/Transforms/Scalar/MergeICmps.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,14 +645,18 @@ static BasicBlock *mergeComparisons(ArrayRef<BCECmpBlock> Comparisons,
645645
Comparisons.begin(), Comparisons.end(), 0u,
646646
[](int Size, const BCECmpBlock &C) { return Size + C.SizeBits(); });
647647

648+
// memcmp expects a 'size_t' argument and returns 'int'.
649+
unsigned SizeTBits = TLI.getSizeTSize(*Phi.getModule());
650+
unsigned IntBits = TLI.getIntSize();
651+
648652
// Create memcmp() == 0.
649653
const auto &DL = Phi.getModule()->getDataLayout();
650654
Value *const MemCmpCall = emitMemCmp(
651655
Lhs, Rhs,
652-
ConstantInt::get(DL.getIntPtrType(Context), TotalSizeBits / 8), Builder,
653-
DL, &TLI);
656+
ConstantInt::get(Builder.getIntNTy(SizeTBits), TotalSizeBits / 8),
657+
Builder, DL, &TLI);
654658
IsEqual = Builder.CreateICmpEQ(
655-
MemCmpCall, ConstantInt::get(Type::getInt32Ty(Context), 0));
659+
MemCmpCall, ConstantInt::get(Builder.getIntNTy(IntBits), 0));
656660
}
657661

658662
BasicBlock *const PhiBB = Phi.getParent();

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,15 @@ Value *llvm::castToCStr(Value *V, IRBuilderBase &B) {
14211421
return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
14221422
}
14231423

1424+
static IntegerType *getIntTy(IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1425+
return B.getIntNTy(TLI->getIntSize());
1426+
}
1427+
1428+
static IntegerType *getSizeTTy(IRBuilderBase &B, const TargetLibraryInfo *TLI) {
1429+
const Module *M = B.GetInsertBlock()->getModule();
1430+
return B.getIntNTy(TLI->getSizeTSize(*M));
1431+
}
1432+
14241433
static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
14251434
ArrayRef<Type *> ParamTypes,
14261435
ArrayRef<Value *> Operands, IRBuilderBase &B,
@@ -1443,8 +1452,7 @@ static Value *emitLibCall(LibFunc TheLibFunc, Type *ReturnType,
14431452

14441453
Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL,
14451454
const TargetLibraryInfo *TLI) {
1446-
LLVMContext &Context = B.GetInsertBlock()->getContext();
1447-
Type *SizeTTy = DL.getIntPtrType(Context);
1455+
Type *SizeTTy = getSizeTTy(B, TLI);
14481456
return emitLibCall(LibFunc_strlen, SizeTTy,
14491457
B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI);
14501458
}
@@ -1458,16 +1466,15 @@ Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B,
14581466
Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B,
14591467
const TargetLibraryInfo *TLI) {
14601468
Type *I8Ptr = B.getInt8PtrTy();
1461-
Type *IntTy = B.getInt32Ty();
1469+
Type *IntTy = getIntTy(B, TLI);
14621470
return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, IntTy},
14631471
{castToCStr(Ptr, B), ConstantInt::get(IntTy, C)}, B, TLI);
14641472
}
14651473

14661474
Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
14671475
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1468-
LLVMContext &Context = B.GetInsertBlock()->getContext();
1469-
Type *SizeTTy = DL.getIntPtrType(Context);
1470-
Type *IntTy = B.getInt32Ty();
1476+
Type *IntTy = getIntTy(B, TLI);
1477+
Type *SizeTTy = getSizeTTy(B, TLI);
14711478
return emitLibCall(
14721479
LibFunc_strncmp, IntTy,
14731480
{B.getInt8PtrTy(), B.getInt8PtrTy(), SizeTTy},
@@ -1491,15 +1498,15 @@ Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B,
14911498
Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
14921499
const TargetLibraryInfo *TLI) {
14931500
Type *I8Ptr = B.getInt8PtrTy();
1494-
Type *SizeTTy = Len->getType();
1501+
Type *SizeTTy = getSizeTTy(B, TLI);
14951502
return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
14961503
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
14971504
}
14981505

14991506
Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15001507
const TargetLibraryInfo *TLI) {
15011508
Type *I8Ptr = B.getInt8PtrTy();
1502-
Type *SizeTTy = Len->getType();
1509+
Type *SizeTTy = getSizeTTy(B, TLI);
15031510
return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, SizeTTy},
15041511
{castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI);
15051512
}
@@ -1514,9 +1521,8 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15141521
AttributeList AS;
15151522
AS = AttributeList::get(M->getContext(), AttributeList::FunctionIndex,
15161523
Attribute::NoUnwind);
1517-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15181524
Type *I8Ptr = B.getInt8PtrTy();
1519-
Type *SizeTTy = DL.getIntPtrType(Context);
1525+
Type *SizeTTy = getSizeTTy(B, TLI);
15201526
FunctionCallee MemCpy = getOrInsertLibFunc(M, *TLI, LibFunc_memcpy_chk,
15211527
AttributeList::get(M->getContext(), AS), I8Ptr,
15221528
I8Ptr, I8Ptr, SizeTTy, SizeTTy);
@@ -1531,77 +1537,69 @@ Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
15311537

15321538
Value *llvm::emitMemPCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B,
15331539
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1534-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15351540
Type *I8Ptr = B.getInt8PtrTy();
1536-
Type *SizeTTy = DL.getIntPtrType(Context);
1541+
Type *SizeTTy = getSizeTTy(B, TLI);
15371542
return emitLibCall(LibFunc_mempcpy, I8Ptr,
15381543
{I8Ptr, I8Ptr, SizeTTy},
15391544
{Dst, Src, Len}, B, TLI);
15401545
}
15411546

15421547
Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15431548
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1544-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15451549
Type *I8Ptr = B.getInt8PtrTy();
1546-
Type *IntTy = B.getInt32Ty();
1547-
Type *SizeTTy = DL.getIntPtrType(Context);
1550+
Type *IntTy = getIntTy(B, TLI);
1551+
Type *SizeTTy = getSizeTTy(B, TLI);
15481552
return emitLibCall(LibFunc_memchr, I8Ptr,
15491553
{I8Ptr, IntTy, SizeTTy},
15501554
{castToCStr(Ptr, B), Val, Len}, B, TLI);
15511555
}
15521556

15531557
Value *llvm::emitMemRChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B,
15541558
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1555-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15561559
Type *I8Ptr = B.getInt8PtrTy();
1557-
Type *IntTy = B.getInt32Ty();
1558-
Type *SizeTTy = DL.getIntPtrType(Context);
1560+
Type *IntTy = getIntTy(B, TLI);
1561+
Type *SizeTTy = getSizeTTy(B, TLI);
15591562
return emitLibCall(LibFunc_memrchr, I8Ptr,
15601563
{I8Ptr, IntTy, SizeTTy},
15611564
{castToCStr(Ptr, B), Val, Len}, B, TLI);
15621565
}
15631566

15641567
Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15651568
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1566-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15671569
Type *I8Ptr = B.getInt8PtrTy();
1568-
Type *IntTy = B.getInt32Ty();
1569-
Type *SizeTTy = DL.getIntPtrType(Context);
1570-
return emitLibCall(
1571-
LibFunc_memcmp, IntTy,
1572-
{I8Ptr, I8Ptr, SizeTTy},
1573-
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1570+
Type *IntTy = getIntTy(B, TLI);
1571+
Type *SizeTTy = getSizeTTy(B, TLI);
1572+
return emitLibCall(LibFunc_memcmp, IntTy,
1573+
{I8Ptr, I8Ptr, SizeTTy},
1574+
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
15741575
}
15751576

15761577
Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B,
15771578
const DataLayout &DL, const TargetLibraryInfo *TLI) {
1578-
LLVMContext &Context = B.GetInsertBlock()->getContext();
15791579
Type *I8Ptr = B.getInt8PtrTy();
1580-
Type *IntTy = B.getInt32Ty();
1581-
Type *SizeTTy = DL.getIntPtrType(Context);
1582-
return emitLibCall(
1583-
LibFunc_bcmp, IntTy,
1584-
{I8Ptr, I8Ptr, SizeTTy},
1585-
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
1580+
Type *IntTy = getIntTy(B, TLI);
1581+
Type *SizeTTy = getSizeTTy(B, TLI);
1582+
return emitLibCall(LibFunc_bcmp, IntTy,
1583+
{I8Ptr, I8Ptr, SizeTTy},
1584+
{castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI);
15861585
}
15871586

15881587
Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len,
15891588
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
15901589
Type *I8Ptr = B.getInt8PtrTy();
1591-
Type *IntTy = B.getInt32Ty();
1592-
Type *SizeTTy = Len->getType();
1593-
return emitLibCall(
1594-
LibFunc_memccpy, I8Ptr,
1595-
{I8Ptr, I8Ptr, IntTy, SizeTTy},
1596-
{Ptr1, Ptr2, Val, Len}, B, TLI);
1590+
Type *IntTy = getIntTy(B, TLI);
1591+
Type *SizeTTy = getSizeTTy(B, TLI);
1592+
return emitLibCall(LibFunc_memccpy, I8Ptr,
1593+
{I8Ptr, I8Ptr, IntTy, SizeTTy},
1594+
{Ptr1, Ptr2, Val, Len}, B, TLI);
15971595
}
15981596

15991597
Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt,
16001598
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
16011599
const TargetLibraryInfo *TLI) {
16021600
Type *I8Ptr = B.getInt8PtrTy();
1603-
Type *IntTy = B.getInt32Ty();
1604-
Type *SizeTTy = Size->getType();
1601+
Type *IntTy = getIntTy(B, TLI);
1602+
Type *SizeTTy = getSizeTTy(B, TLI);
16051603
SmallVector<Value *, 8> Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)};
16061604
llvm::append_range(Args, VariadicArgs);
16071605
return emitLibCall(LibFunc_snprintf, IntTy,
@@ -1613,7 +1611,7 @@ Value *llvm::emitSPrintf(Value *Dest, Value *Fmt,
16131611
ArrayRef<Value *> VariadicArgs, IRBuilderBase &B,
16141612
const TargetLibraryInfo *TLI) {
16151613
Type *I8Ptr = B.getInt8PtrTy();
1616-
Type *IntTy = B.getInt32Ty();
1614+
Type *IntTy = getIntTy(B, TLI);
16171615
SmallVector<Value *, 8> Args{castToCStr(Dest, B), castToCStr(Fmt, B)};
16181616
llvm::append_range(Args, VariadicArgs);
16191617
return emitLibCall(LibFunc_sprintf, IntTy,
@@ -1631,7 +1629,7 @@ Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B,
16311629
Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16321630
const TargetLibraryInfo *TLI) {
16331631
Type *I8Ptr = B.getInt8PtrTy();
1634-
Type *SizeTTy = Size->getType();
1632+
Type *SizeTTy = getSizeTTy(B, TLI);
16351633
return emitLibCall(LibFunc_strlcpy, SizeTTy,
16361634
{I8Ptr, I8Ptr, SizeTTy},
16371635
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
@@ -1640,7 +1638,7 @@ Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16401638
Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16411639
const TargetLibraryInfo *TLI) {
16421640
Type *I8Ptr = B.getInt8PtrTy();
1643-
Type *SizeTTy = Size->getType();
1641+
Type *SizeTTy = getSizeTTy(B, TLI);
16441642
return emitLibCall(LibFunc_strlcat, SizeTTy,
16451643
{I8Ptr, I8Ptr, SizeTTy},
16461644
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
@@ -1649,7 +1647,7 @@ Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16491647
Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16501648
const TargetLibraryInfo *TLI) {
16511649
Type *I8Ptr = B.getInt8PtrTy();
1652-
Type *SizeTTy = Size->getType();
1650+
Type *SizeTTy = getSizeTTy(B, TLI);
16531651
return emitLibCall(LibFunc_strncat, I8Ptr,
16541652
{I8Ptr, I8Ptr, SizeTTy},
16551653
{castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI);
@@ -1658,8 +1656,8 @@ Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B,
16581656
Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
16591657
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
16601658
Type *I8Ptr = B.getInt8PtrTy();
1661-
Type *IntTy = B.getInt32Ty();
1662-
Type *SizeTTy = Size->getType();
1659+
Type *IntTy = getIntTy(B, TLI);
1660+
Type *SizeTTy = getSizeTTy(B, TLI);
16631661
return emitLibCall(
16641662
LibFunc_vsnprintf, IntTy,
16651663
{I8Ptr, SizeTTy, I8Ptr, VAList->getType()},
@@ -1669,7 +1667,7 @@ Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList,
16691667
Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList,
16701668
IRBuilderBase &B, const TargetLibraryInfo *TLI) {
16711669
Type *I8Ptr = B.getInt8PtrTy();
1672-
Type *IntTy = B.getInt32Ty();
1670+
Type *IntTy = getIntTy(B, TLI);
16731671
return emitLibCall(LibFunc_vsprintf, IntTy,
16741672
{I8Ptr, I8Ptr, VAList->getType()},
16751673
{castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI);
@@ -1800,7 +1798,7 @@ Value *llvm::emitPutChar(Value *Char, IRBuilderBase &B,
18001798
if (!isLibFuncEmittable(M, TLI, LibFunc_putchar))
18011799
return nullptr;
18021800

1803-
Type *IntTy = Char->getType();
1801+
Type *IntTy = getIntTy(B, TLI);
18041802
StringRef PutCharName = TLI->getName(LibFunc_putchar);
18051803
FunctionCallee PutChar = getOrInsertLibFunc(M, *TLI, LibFunc_putchar,
18061804
IntTy, IntTy);
@@ -1819,7 +1817,7 @@ Value *llvm::emitPutS(Value *Str, IRBuilderBase &B,
18191817
if (!isLibFuncEmittable(M, TLI, LibFunc_puts))
18201818
return nullptr;
18211819

1822-
Type *IntTy = B.getInt32Ty();
1820+
Type *IntTy = getIntTy(B, TLI);
18231821
StringRef PutsName = TLI->getName(LibFunc_puts);
18241822
FunctionCallee PutS = getOrInsertLibFunc(M, *TLI, LibFunc_puts, IntTy,
18251823
B.getInt8PtrTy());
@@ -1837,7 +1835,7 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilderBase &B,
18371835
if (!isLibFuncEmittable(M, TLI, LibFunc_fputc))
18381836
return nullptr;
18391837

1840-
Type *IntTy = B.getInt32Ty();
1838+
Type *IntTy = getIntTy(B, TLI);
18411839
StringRef FPutcName = TLI->getName(LibFunc_fputc);
18421840
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputc, IntTy,
18431841
IntTy, File->getType());
@@ -1859,7 +1857,7 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilderBase &B,
18591857
if (!isLibFuncEmittable(M, TLI, LibFunc_fputs))
18601858
return nullptr;
18611859

1862-
Type *IntTy = B.getInt32Ty();
1860+
Type *IntTy = getIntTy(B, TLI);
18631861
StringRef FPutsName = TLI->getName(LibFunc_fputs);
18641862
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fputs, IntTy,
18651863
B.getInt8PtrTy(), File->getType());
@@ -1879,8 +1877,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
18791877
if (!isLibFuncEmittable(M, TLI, LibFunc_fwrite))
18801878
return nullptr;
18811879

1882-
LLVMContext &Context = B.GetInsertBlock()->getContext();
1883-
Type *SizeTTy = DL.getIntPtrType(Context);
1880+
Type *SizeTTy = getSizeTTy(B, TLI);
18841881
StringRef FWriteName = TLI->getName(LibFunc_fwrite);
18851882
FunctionCallee F = getOrInsertLibFunc(M, *TLI, LibFunc_fwrite,
18861883
SizeTTy, B.getInt8PtrTy(), SizeTTy,
@@ -1890,7 +1887,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilderBase &B,
18901887
inferNonMandatoryLibFuncAttrs(M, FWriteName, *TLI);
18911888
CallInst *CI =
18921889
B.CreateCall(F, {castToCStr(Ptr, B), Size,
1893-
ConstantInt::get(DL.getIntPtrType(Context), 1), File});
1890+
ConstantInt::get(SizeTTy, 1), File});
18941891

18951892
if (const Function *Fn =
18961893
dyn_cast<Function>(F.getCallee()->stripPointerCasts()))
@@ -1905,8 +1902,7 @@ Value *llvm::emitMalloc(Value *Num, IRBuilderBase &B, const DataLayout &DL,
19051902
return nullptr;
19061903

19071904
StringRef MallocName = TLI->getName(LibFunc_malloc);
1908-
LLVMContext &Context = B.GetInsertBlock()->getContext();
1909-
Type *SizeTTy = DL.getIntPtrType(Context);
1905+
Type *SizeTTy = getSizeTTy(B, TLI);
19101906
FunctionCallee Malloc = getOrInsertLibFunc(M, *TLI, LibFunc_malloc,
19111907
B.getInt8PtrTy(), SizeTTy);
19121908
inferNonMandatoryLibFuncAttrs(M, MallocName, *TLI);
@@ -1926,9 +1922,7 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, IRBuilderBase &B,
19261922
return nullptr;
19271923

19281924
StringRef CallocName = TLI.getName(LibFunc_calloc);
1929-
LLVMContext &Context = B.GetInsertBlock()->getContext();
1930-
const DataLayout &DL = M->getDataLayout();
1931-
Type *SizeTTy = DL.getIntPtrType(Context);
1925+
Type *SizeTTy = getSizeTTy(B, &TLI);
19321926
FunctionCallee Calloc = getOrInsertLibFunc(M, TLI, LibFunc_calloc,
19331927
B.getInt8PtrTy(), SizeTTy, SizeTTy);
19341928
inferNonMandatoryLibFuncAttrs(M, CallocName, TLI);

0 commit comments

Comments
 (0)