Skip to content

Commit 83c660b

Browse files
committed
Merge branch 'release_70' of github.com:llvm-mirror/llvm into release_70
2 parents 07c635b + 2e8411d commit 83c660b

File tree

5 files changed

+119
-52
lines changed

5 files changed

+119
-52
lines changed

include/llvm/Transforms/Utils/BuildLibCalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace llvm {
2929
///
3030
/// Returns true if any attributes were set and false otherwise.
3131
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI);
32+
bool inferLibFuncAttributes(Module *M, StringRef Name, const TargetLibraryInfo &TLI);
3233

3334
/// Check whether the overloaded unary floating point function
3435
/// corresponding to \a Ty is available.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,7 +2237,7 @@ void DwarfDebug::emitDebugRanges() {
22372237

22382238
auto NoRangesPresent = [this]() {
22392239
return llvm::all_of(
2240-
CUMap, [](const decltype(CUMap)::const_iterator::value_type &Pair) {
2240+
CUMap, [](const decltype(CUMap)::value_type &Pair) {
22412241
return Pair.second->getRangeLists().empty();
22422242
});
22432243
};

lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,11 @@ bool LoopIdiomRecognize::processLoopStridedStore(
921921
Type *Int8PtrTy = DestInt8PtrTy;
922922

923923
Module *M = TheStore->getModule();
924+
StringRef FuncName = "memset_pattern16";
924925
Value *MSP =
925-
M->getOrInsertFunction("memset_pattern16", Builder.getVoidTy(),
926+
M->getOrInsertFunction(FuncName, Builder.getVoidTy(),
926927
Int8PtrTy, Int8PtrTy, IntPtr);
927-
inferLibFuncAttributes(*M->getFunction("memset_pattern16"), *TLI);
928+
inferLibFuncAttributes(M, FuncName, *TLI);
928929

929930
// Otherwise we should form a memset_pattern16. PatternValue is known to be
930931
// an constant array of 16-bytes. Plop the value into a mergable global.

lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 70 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ static bool setNonLazyBind(Function &F) {
112112
return true;
113113
}
114114

115+
bool llvm::inferLibFuncAttributes(Module *M, StringRef Name,
116+
const TargetLibraryInfo &TLI) {
117+
Function *F = M->getFunction(Name);
118+
if (!F)
119+
return false;
120+
return inferLibFuncAttributes(*F, TLI);
121+
}
122+
115123
bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
116124
LibFunc TheLibFunc;
117125
if (!(TLI.getLibFunc(F, TheLibFunc) && TLI.has(TheLibFunc)))
@@ -755,11 +763,12 @@ Value *llvm::emitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout &DL,
755763
return nullptr;
756764

757765
Module *M = B.GetInsertBlock()->getModule();
766+
StringRef StrlenName = TLI->getName(LibFunc_strlen);
758767
LLVMContext &Context = B.GetInsertBlock()->getContext();
759-
Constant *StrLen = M->getOrInsertFunction("strlen", DL.getIntPtrType(Context),
768+
Constant *StrLen = M->getOrInsertFunction(StrlenName, DL.getIntPtrType(Context),
760769
B.getInt8PtrTy());
761-
inferLibFuncAttributes(*M->getFunction("strlen"), *TLI);
762-
CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), "strlen");
770+
inferLibFuncAttributes(M, StrlenName, *TLI);
771+
CallInst *CI = B.CreateCall(StrLen, castToCStr(Ptr, B), StrlenName);
763772
if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
764773
CI->setCallingConv(F->getCallingConv());
765774

@@ -772,13 +781,14 @@ Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilder<> &B,
772781
return nullptr;
773782

774783
Module *M = B.GetInsertBlock()->getModule();
784+
StringRef StrChrName = TLI->getName(LibFunc_strchr);
775785
Type *I8Ptr = B.getInt8PtrTy();
776786
Type *I32Ty = B.getInt32Ty();
777787
Constant *StrChr =
778-
M->getOrInsertFunction("strchr", I8Ptr, I8Ptr, I32Ty);
779-
inferLibFuncAttributes(*M->getFunction("strchr"), *TLI);
788+
M->getOrInsertFunction(StrChrName, I8Ptr, I8Ptr, I32Ty);
789+
inferLibFuncAttributes(M, StrChrName, *TLI);
780790
CallInst *CI = B.CreateCall(
781-
StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, "strchr");
791+
StrChr, {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, StrChrName);
782792
if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
783793
CI->setCallingConv(F->getCallingConv());
784794
return CI;
@@ -790,13 +800,14 @@ Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
790800
return nullptr;
791801

792802
Module *M = B.GetInsertBlock()->getModule();
803+
StringRef StrNCmpName = TLI->getName(LibFunc_strncmp);
793804
LLVMContext &Context = B.GetInsertBlock()->getContext();
794-
Value *StrNCmp = M->getOrInsertFunction("strncmp", B.getInt32Ty(),
805+
Value *StrNCmp = M->getOrInsertFunction(StrNCmpName, B.getInt32Ty(),
795806
B.getInt8PtrTy(), B.getInt8PtrTy(),
796807
DL.getIntPtrType(Context));
797-
inferLibFuncAttributes(*M->getFunction("strncmp"), *TLI);
808+
inferLibFuncAttributes(M, StrNCmpName, *TLI);
798809
CallInst *CI = B.CreateCall(
799-
StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "strncmp");
810+
StrNCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, StrNCmpName);
800811

801812
if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
802813
CI->setCallingConv(F->getCallingConv());
@@ -812,7 +823,7 @@ Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
812823
Module *M = B.GetInsertBlock()->getModule();
813824
Type *I8Ptr = B.getInt8PtrTy();
814825
Value *StrCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr);
815-
inferLibFuncAttributes(*M->getFunction(Name), *TLI);
826+
inferLibFuncAttributes(M, Name, *TLI);
816827
CallInst *CI =
817828
B.CreateCall(StrCpy, {castToCStr(Dst, B), castToCStr(Src, B)}, Name);
818829
if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
@@ -829,9 +840,9 @@ Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilder<> &B,
829840
Type *I8Ptr = B.getInt8PtrTy();
830841
Value *StrNCpy = M->getOrInsertFunction(Name, I8Ptr, I8Ptr, I8Ptr,
831842
Len->getType());
832-
inferLibFuncAttributes(*M->getFunction(Name), *TLI);
843+
inferLibFuncAttributes(M, Name, *TLI);
833844
CallInst *CI = B.CreateCall(
834-
StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, "strncpy");
845+
StrNCpy, {castToCStr(Dst, B), castToCStr(Src, B), Len}, Name);
835846
if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
836847
CI->setCallingConv(F->getCallingConv());
837848
return CI;
@@ -866,12 +877,13 @@ Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<> &B,
866877
return nullptr;
867878

868879
Module *M = B.GetInsertBlock()->getModule();
880+
StringRef MemChrName = TLI->getName(LibFunc_memchr);
869881
LLVMContext &Context = B.GetInsertBlock()->getContext();
870-
Value *MemChr = M->getOrInsertFunction("memchr", B.getInt8PtrTy(),
882+
Value *MemChr = M->getOrInsertFunction(MemChrName, B.getInt8PtrTy(),
871883
B.getInt8PtrTy(), B.getInt32Ty(),
872884
DL.getIntPtrType(Context));
873-
inferLibFuncAttributes(*M->getFunction("memchr"), *TLI);
874-
CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, "memchr");
885+
inferLibFuncAttributes(M, MemChrName, *TLI);
886+
CallInst *CI = B.CreateCall(MemChr, {castToCStr(Ptr, B), Val, Len}, MemChrName);
875887

876888
if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
877889
CI->setCallingConv(F->getCallingConv());
@@ -885,13 +897,14 @@ Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilder<> &B,
885897
return nullptr;
886898

887899
Module *M = B.GetInsertBlock()->getModule();
900+
StringRef MemCmpName = TLI->getName(LibFunc_memcmp);
888901
LLVMContext &Context = B.GetInsertBlock()->getContext();
889-
Value *MemCmp = M->getOrInsertFunction("memcmp", B.getInt32Ty(),
902+
Value *MemCmp = M->getOrInsertFunction(MemCmpName, B.getInt32Ty(),
890903
B.getInt8PtrTy(), B.getInt8PtrTy(),
891904
DL.getIntPtrType(Context));
892-
inferLibFuncAttributes(*M->getFunction("memcmp"), *TLI);
905+
inferLibFuncAttributes(M, MemCmpName, *TLI);
893906
CallInst *CI = B.CreateCall(
894-
MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, "memcmp");
907+
MemCmp, {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, MemCmpName);
895908

896909
if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
897910
CI->setCallingConv(F->getCallingConv());
@@ -958,14 +971,15 @@ Value *llvm::emitPutChar(Value *Char, IRBuilder<> &B,
958971
return nullptr;
959972

960973
Module *M = B.GetInsertBlock()->getModule();
961-
Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(), B.getInt32Ty());
962-
inferLibFuncAttributes(*M->getFunction("putchar"), *TLI);
974+
StringRef PutCharName = TLI->getName(LibFunc_putchar);
975+
Value *PutChar = M->getOrInsertFunction(PutCharName, B.getInt32Ty(), B.getInt32Ty());
976+
inferLibFuncAttributes(M, PutCharName, *TLI);
963977
CallInst *CI = B.CreateCall(PutChar,
964978
B.CreateIntCast(Char,
965979
B.getInt32Ty(),
966980
/*isSigned*/true,
967981
"chari"),
968-
"putchar");
982+
PutCharName);
969983

970984
if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
971985
CI->setCallingConv(F->getCallingConv());
@@ -978,10 +992,11 @@ Value *llvm::emitPutS(Value *Str, IRBuilder<> &B,
978992
return nullptr;
979993

980994
Module *M = B.GetInsertBlock()->getModule();
995+
StringRef PutsName = TLI->getName(LibFunc_puts);
981996
Value *PutS =
982-
M->getOrInsertFunction("puts", B.getInt32Ty(), B.getInt8PtrTy());
983-
inferLibFuncAttributes(*M->getFunction("puts"), *TLI);
984-
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), "puts");
997+
M->getOrInsertFunction(PutsName, B.getInt32Ty(), B.getInt8PtrTy());
998+
inferLibFuncAttributes(M, PutsName, *TLI);
999+
CallInst *CI = B.CreateCall(PutS, castToCStr(Str, B), PutsName);
9851000
if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
9861001
CI->setCallingConv(F->getCallingConv());
9871002
return CI;
@@ -993,13 +1008,14 @@ Value *llvm::emitFPutC(Value *Char, Value *File, IRBuilder<> &B,
9931008
return nullptr;
9941009

9951010
Module *M = B.GetInsertBlock()->getModule();
996-
Constant *F = M->getOrInsertFunction("fputc", B.getInt32Ty(), B.getInt32Ty(),
1011+
StringRef FPutcName = TLI->getName(LibFunc_fputc);
1012+
Constant *F = M->getOrInsertFunction(FPutcName, B.getInt32Ty(), B.getInt32Ty(),
9971013
File->getType());
9981014
if (File->getType()->isPointerTy())
999-
inferLibFuncAttributes(*M->getFunction("fputc"), *TLI);
1015+
inferLibFuncAttributes(M, FPutcName, *TLI);
10001016
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
10011017
"chari");
1002-
CallInst *CI = B.CreateCall(F, {Char, File}, "fputc");
1018+
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcName);
10031019

10041020
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
10051021
CI->setCallingConv(Fn->getCallingConv());
@@ -1012,12 +1028,13 @@ Value *llvm::emitFPutCUnlocked(Value *Char, Value *File, IRBuilder<> &B,
10121028
return nullptr;
10131029

10141030
Module *M = B.GetInsertBlock()->getModule();
1015-
Constant *F = M->getOrInsertFunction("fputc_unlocked", B.getInt32Ty(),
1031+
StringRef FPutcUnlockedName = TLI->getName(LibFunc_fputc_unlocked);
1032+
Constant *F = M->getOrInsertFunction(FPutcUnlockedName, B.getInt32Ty(),
10161033
B.getInt32Ty(), File->getType());
10171034
if (File->getType()->isPointerTy())
1018-
inferLibFuncAttributes(*M->getFunction("fputc_unlocked"), *TLI);
1035+
inferLibFuncAttributes(M, FPutcUnlockedName, *TLI);
10191036
Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/ true, "chari");
1020-
CallInst *CI = B.CreateCall(F, {Char, File}, "fputc_unlocked");
1037+
CallInst *CI = B.CreateCall(F, {Char, File}, FPutcUnlockedName);
10211038

10221039
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
10231040
CI->setCallingConv(Fn->getCallingConv());
@@ -1034,8 +1051,8 @@ Value *llvm::emitFPutS(Value *Str, Value *File, IRBuilder<> &B,
10341051
Constant *F = M->getOrInsertFunction(
10351052
FPutsName, B.getInt32Ty(), B.getInt8PtrTy(), File->getType());
10361053
if (File->getType()->isPointerTy())
1037-
inferLibFuncAttributes(*M->getFunction(FPutsName), *TLI);
1038-
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs");
1054+
inferLibFuncAttributes(M, FPutsName, *TLI);
1055+
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsName);
10391056

10401057
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
10411058
CI->setCallingConv(Fn->getCallingConv());
@@ -1052,8 +1069,8 @@ Value *llvm::emitFPutSUnlocked(Value *Str, Value *File, IRBuilder<> &B,
10521069
Constant *F = M->getOrInsertFunction(FPutsUnlockedName, B.getInt32Ty(),
10531070
B.getInt8PtrTy(), File->getType());
10541071
if (File->getType()->isPointerTy())
1055-
inferLibFuncAttributes(*M->getFunction(FPutsUnlockedName), *TLI);
1056-
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, "fputs_unlocked");
1072+
inferLibFuncAttributes(M, FPutsUnlockedName, *TLI);
1073+
CallInst *CI = B.CreateCall(F, {castToCStr(Str, B), File}, FPutsUnlockedName);
10571074

10581075
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
10591076
CI->setCallingConv(Fn->getCallingConv());
@@ -1073,7 +1090,7 @@ Value *llvm::emitFWrite(Value *Ptr, Value *Size, Value *File, IRBuilder<> &B,
10731090
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
10741091

10751092
if (File->getType()->isPointerTy())
1076-
inferLibFuncAttributes(*M->getFunction(FWriteName), *TLI);
1093+
inferLibFuncAttributes(M, FWriteName, *TLI);
10771094
CallInst *CI =
10781095
B.CreateCall(F, {castToCStr(Ptr, B), Size,
10791096
ConstantInt::get(DL.getIntPtrType(Context), 1), File});
@@ -1089,11 +1106,12 @@ Value *llvm::emitMalloc(Value *Num, IRBuilder<> &B, const DataLayout &DL,
10891106
return nullptr;
10901107

10911108
Module *M = B.GetInsertBlock()->getModule();
1109+
StringRef MallocName = TLI->getName(LibFunc_malloc);
10921110
LLVMContext &Context = B.GetInsertBlock()->getContext();
1093-
Value *Malloc = M->getOrInsertFunction("malloc", B.getInt8PtrTy(),
1111+
Value *Malloc = M->getOrInsertFunction(MallocName, B.getInt8PtrTy(),
10941112
DL.getIntPtrType(Context));
1095-
inferLibFuncAttributes(*M->getFunction("malloc"), *TLI);
1096-
CallInst *CI = B.CreateCall(Malloc, Num, "malloc");
1113+
inferLibFuncAttributes(M, MallocName, *TLI);
1114+
CallInst *CI = B.CreateCall(Malloc, Num, MallocName);
10971115

10981116
if (const Function *F = dyn_cast<Function>(Malloc->stripPointerCasts()))
10991117
CI->setCallingConv(F->getCallingConv());
@@ -1107,12 +1125,13 @@ Value *llvm::emitCalloc(Value *Num, Value *Size, const AttributeList &Attrs,
11071125
return nullptr;
11081126

11091127
Module *M = B.GetInsertBlock()->getModule();
1128+
StringRef CallocName = TLI.getName(LibFunc_calloc);
11101129
const DataLayout &DL = M->getDataLayout();
11111130
IntegerType *PtrType = DL.getIntPtrType((B.GetInsertBlock()->getContext()));
1112-
Value *Calloc = M->getOrInsertFunction("calloc", Attrs, B.getInt8PtrTy(),
1131+
Value *Calloc = M->getOrInsertFunction(CallocName, Attrs, B.getInt8PtrTy(),
11131132
PtrType, PtrType);
1114-
inferLibFuncAttributes(*M->getFunction("calloc"), TLI);
1115-
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, "calloc");
1133+
inferLibFuncAttributes(M, CallocName, TLI);
1134+
CallInst *CI = B.CreateCall(Calloc, {Num, Size}, CallocName);
11161135

11171136
if (const auto *F = dyn_cast<Function>(Calloc->stripPointerCasts()))
11181137
CI->setCallingConv(F->getCallingConv());
@@ -1134,7 +1153,7 @@ Value *llvm::emitFWriteUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
11341153
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
11351154

11361155
if (File->getType()->isPointerTy())
1137-
inferLibFuncAttributes(*M->getFunction(FWriteUnlockedName), *TLI);
1156+
inferLibFuncAttributes(M, FWriteUnlockedName, *TLI);
11381157
CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
11391158

11401159
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
@@ -1148,11 +1167,12 @@ Value *llvm::emitFGetCUnlocked(Value *File, IRBuilder<> &B,
11481167
return nullptr;
11491168

11501169
Module *M = B.GetInsertBlock()->getModule();
1170+
StringRef FGetCUnlockedName = TLI->getName(LibFunc_fgetc_unlocked);
11511171
Constant *F =
1152-
M->getOrInsertFunction("fgetc_unlocked", B.getInt32Ty(), File->getType());
1172+
M->getOrInsertFunction(FGetCUnlockedName, B.getInt32Ty(), File->getType());
11531173
if (File->getType()->isPointerTy())
1154-
inferLibFuncAttributes(*M->getFunction("fgetc_unlocked"), *TLI);
1155-
CallInst *CI = B.CreateCall(F, File, "fgetc_unlocked");
1174+
inferLibFuncAttributes(M, FGetCUnlockedName, *TLI);
1175+
CallInst *CI = B.CreateCall(F, File, FGetCUnlockedName);
11561176

11571177
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
11581178
CI->setCallingConv(Fn->getCallingConv());
@@ -1165,12 +1185,13 @@ Value *llvm::emitFGetSUnlocked(Value *Str, Value *Size, Value *File,
11651185
return nullptr;
11661186

11671187
Module *M = B.GetInsertBlock()->getModule();
1188+
StringRef FGetSUnlockedName = TLI->getName(LibFunc_fgets_unlocked);
11681189
Constant *F =
1169-
M->getOrInsertFunction("fgets_unlocked", B.getInt8PtrTy(),
1190+
M->getOrInsertFunction(FGetSUnlockedName, B.getInt8PtrTy(),
11701191
B.getInt8PtrTy(), B.getInt32Ty(), File->getType());
1171-
inferLibFuncAttributes(*M->getFunction("fgets_unlocked"), *TLI);
1192+
inferLibFuncAttributes(M, FGetSUnlockedName, *TLI);
11721193
CallInst *CI =
1173-
B.CreateCall(F, {castToCStr(Str, B), Size, File}, "fgets_unlocked");
1194+
B.CreateCall(F, {castToCStr(Str, B), Size, File}, FGetSUnlockedName);
11741195

11751196
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
11761197
CI->setCallingConv(Fn->getCallingConv());
@@ -1191,7 +1212,7 @@ Value *llvm::emitFReadUnlocked(Value *Ptr, Value *Size, Value *N, Value *File,
11911212
DL.getIntPtrType(Context), DL.getIntPtrType(Context), File->getType());
11921213

11931214
if (File->getType()->isPointerTy())
1194-
inferLibFuncAttributes(*M->getFunction(FReadUnlockedName), *TLI);
1215+
inferLibFuncAttributes(M, FReadUnlockedName, *TLI);
11951216
CallInst *CI = B.CreateCall(F, {castToCStr(Ptr, B), Size, N, File});
11961217

11971218
if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -instcombine -S | FileCheck %s
3+
4+
%struct._IO_FILE = type { i32, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, %struct._IO_marker*, %struct._IO_FILE*, i32, i32, i64, i16, i8, [1 x i8], i8*, i64, i8*, i8*, i8*, i8*, i64, i32, [20 x i8] }
5+
%struct._IO_marker = type { %struct._IO_marker*, %struct._IO_FILE*, i32 }
6+
7+
@stderr = external global %struct._IO_FILE*, align 8
8+
@.str = private constant [8 x i8] c"crash!\0A\00", align 1
9+
10+
@fwrite = alias i64 (i8*, i64, i64, %struct._IO_FILE*), i64 (i8*, i64, i64, %struct._IO_FILE*)* @__fwrite_alias
11+
12+
define i64 @__fwrite_alias(i8* %ptr, i64 %size, i64 %n, %struct._IO_FILE* %s) {
13+
; CHECK-LABEL: @__fwrite_alias(
14+
; CHECK-NEXT: entry:
15+
; CHECK-NEXT: ret i64 0
16+
;
17+
entry:
18+
%ptr.addr = alloca i8*, align 8
19+
%size.addr = alloca i64, align 8
20+
%n.addr = alloca i64, align 8
21+
%s.addr = alloca %struct._IO_FILE*, align 8
22+
store i8* %ptr, i8** %ptr.addr, align 8
23+
store i64 %size, i64* %size.addr, align 8
24+
store i64 %n, i64* %n.addr, align 8
25+
store %struct._IO_FILE* %s, %struct._IO_FILE** %s.addr, align 8
26+
ret i64 0
27+
}
28+
29+
define void @foo() {
30+
; CHECK-LABEL: @foo(
31+
; CHECK-NEXT: entry:
32+
; CHECK-NEXT: [[TMP0:%.*]] = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8
33+
; CHECK-NEXT: [[TMP1:%.*]] = call i64 @__fwrite_alias(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 7, i64 1, %struct._IO_FILE* [[TMP0]])
34+
; CHECK-NEXT: ret void
35+
;
36+
entry:
37+
%retval = alloca i32, align 4
38+
store i32 0, i32* %retval, align 4
39+
%0 = load %struct._IO_FILE*, %struct._IO_FILE** @stderr, align 8
40+
%call = call i32 (%struct._IO_FILE*, i8*, ...) @fprintf(%struct._IO_FILE* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0))
41+
ret void
42+
}
43+
44+
declare i32 @fprintf(%struct._IO_FILE*, i8*, ...)

0 commit comments

Comments
 (0)