1 //===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements some functions that will create standard C libcalls.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Transforms/Utils/BuildLibCalls.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/Intrinsics.h"
21 #include "llvm/IR/LLVMContext.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Target/TargetLibraryInfo.h"
28 /// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
29 Value *llvm::CastToCStr(Value *V, IRBuilder<> &B) {
30 return B.CreateBitCast(V, B.getInt8PtrTy(), "cstr");
33 /// EmitStrLen - Emit a call to the strlen function to the builder, for the
34 /// specified pointer. This always returns an integer value of size intptr_t.
35 Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout *TD,
36 const TargetLibraryInfo *TLI) {
37 if (!TLI->has(LibFunc::strlen))
40 Module *M = B.GetInsertBlock()->getParent()->getParent();
42 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
43 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
44 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
45 ArrayRef<Attribute::AttrKind>(AVs, 2));
47 LLVMContext &Context = B.GetInsertBlock()->getContext();
48 Constant *StrLen = M->getOrInsertFunction("strlen",
49 AttributeSet::get(M->getContext(),
51 TD->getIntPtrType(Context),
54 CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
55 if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
56 CI->setCallingConv(F->getCallingConv());
61 /// EmitStrNLen - Emit a call to the strnlen function to the builder, for the
62 /// specified pointer. Ptr is required to be some pointer type, MaxLen must
63 /// be of size_t type, and the return value has 'intptr_t' type.
64 Value *llvm::EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
65 const DataLayout *TD, const TargetLibraryInfo *TLI) {
66 if (!TLI->has(LibFunc::strnlen))
69 Module *M = B.GetInsertBlock()->getParent()->getParent();
71 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
72 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
73 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
74 ArrayRef<Attribute::AttrKind>(AVs, 2));
76 LLVMContext &Context = B.GetInsertBlock()->getContext();
77 Constant *StrNLen = M->getOrInsertFunction("strnlen",
78 AttributeSet::get(M->getContext(),
80 TD->getIntPtrType(Context),
82 TD->getIntPtrType(Context),
84 CallInst *CI = B.CreateCall2(StrNLen, CastToCStr(Ptr, B), MaxLen, "strnlen");
85 if (const Function *F = dyn_cast<Function>(StrNLen->stripPointerCasts()))
86 CI->setCallingConv(F->getCallingConv());
91 /// EmitStrChr - Emit a call to the strchr function to the builder, for the
92 /// specified pointer and character. Ptr is required to be some pointer type,
93 /// and the return value has 'i8*' type.
94 Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B,
95 const DataLayout *TD, const TargetLibraryInfo *TLI) {
96 if (!TLI->has(LibFunc::strchr))
99 Module *M = B.GetInsertBlock()->getParent()->getParent();
100 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
102 AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
103 ArrayRef<Attribute::AttrKind>(AVs, 2));
105 Type *I8Ptr = B.getInt8PtrTy();
106 Type *I32Ty = B.getInt32Ty();
107 Constant *StrChr = M->getOrInsertFunction("strchr",
108 AttributeSet::get(M->getContext(),
110 I8Ptr, I8Ptr, I32Ty, NULL);
111 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B),
112 ConstantInt::get(I32Ty, C), "strchr");
113 if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
114 CI->setCallingConv(F->getCallingConv());
118 /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
119 Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len,
120 IRBuilder<> &B, const DataLayout *TD,
121 const TargetLibraryInfo *TLI) {
122 if (!TLI->has(LibFunc::strncmp))
125 Module *M = B.GetInsertBlock()->getParent()->getParent();
127 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
128 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
129 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
130 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
131 ArrayRef<Attribute::AttrKind>(AVs, 2));
133 LLVMContext &Context = B.GetInsertBlock()->getContext();
134 Value *StrNCmp = M->getOrInsertFunction("strncmp",
135 AttributeSet::get(M->getContext(),
140 TD->getIntPtrType(Context), NULL);
141 CallInst *CI = B.CreateCall3(StrNCmp, CastToCStr(Ptr1, B),
142 CastToCStr(Ptr2, B), Len, "strncmp");
144 if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
145 CI->setCallingConv(F->getCallingConv());
150 /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
151 /// specified pointer arguments.
152 Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
153 const DataLayout *TD, const TargetLibraryInfo *TLI,
155 if (!TLI->has(LibFunc::strcpy))
158 Module *M = B.GetInsertBlock()->getParent()->getParent();
160 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
161 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
162 Attribute::NoUnwind);
163 Type *I8Ptr = B.getInt8PtrTy();
164 Value *StrCpy = M->getOrInsertFunction(Name,
165 AttributeSet::get(M->getContext(), AS),
166 I8Ptr, I8Ptr, I8Ptr, NULL);
167 CallInst *CI = B.CreateCall2(StrCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
169 if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
170 CI->setCallingConv(F->getCallingConv());
174 /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
175 /// specified pointer arguments.
176 Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len,
177 IRBuilder<> &B, const DataLayout *TD,
178 const TargetLibraryInfo *TLI, StringRef Name) {
179 if (!TLI->has(LibFunc::strncpy))
182 Module *M = B.GetInsertBlock()->getParent()->getParent();
184 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
185 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
186 Attribute::NoUnwind);
187 Type *I8Ptr = B.getInt8PtrTy();
188 Value *StrNCpy = M->getOrInsertFunction(Name,
189 AttributeSet::get(M->getContext(),
192 Len->getType(), NULL);
193 CallInst *CI = B.CreateCall3(StrNCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
195 if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
196 CI->setCallingConv(F->getCallingConv());
200 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
201 /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
203 Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
204 IRBuilder<> &B, const DataLayout *TD,
205 const TargetLibraryInfo *TLI) {
206 if (!TLI->has(LibFunc::memcpy_chk))
209 Module *M = B.GetInsertBlock()->getParent()->getParent();
211 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
212 Attribute::NoUnwind);
213 LLVMContext &Context = B.GetInsertBlock()->getContext();
214 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
215 AttributeSet::get(M->getContext(), AS),
219 TD->getIntPtrType(Context),
220 TD->getIntPtrType(Context), NULL);
221 Dst = CastToCStr(Dst, B);
222 Src = CastToCStr(Src, B);
223 CallInst *CI = B.CreateCall4(MemCpy, Dst, Src, Len, ObjSize);
224 if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
225 CI->setCallingConv(F->getCallingConv());
229 /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
230 /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
231 Value *llvm::EmitMemChr(Value *Ptr, Value *Val,
232 Value *Len, IRBuilder<> &B, const DataLayout *TD,
233 const TargetLibraryInfo *TLI) {
234 if (!TLI->has(LibFunc::memchr))
237 Module *M = B.GetInsertBlock()->getParent()->getParent();
239 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
240 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
241 ArrayRef<Attribute::AttrKind>(AVs, 2));
242 LLVMContext &Context = B.GetInsertBlock()->getContext();
243 Value *MemChr = M->getOrInsertFunction("memchr",
244 AttributeSet::get(M->getContext(), AS),
248 TD->getIntPtrType(Context),
250 CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
252 if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
253 CI->setCallingConv(F->getCallingConv());
258 /// EmitMemCmp - Emit a call to the memcmp function.
259 Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2,
260 Value *Len, IRBuilder<> &B, const DataLayout *TD,
261 const TargetLibraryInfo *TLI) {
262 if (!TLI->has(LibFunc::memcmp))
265 Module *M = B.GetInsertBlock()->getParent()->getParent();
267 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
268 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
269 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
270 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
271 ArrayRef<Attribute::AttrKind>(AVs, 2));
273 LLVMContext &Context = B.GetInsertBlock()->getContext();
274 Value *MemCmp = M->getOrInsertFunction("memcmp",
275 AttributeSet::get(M->getContext(), AS),
279 TD->getIntPtrType(Context), NULL);
280 CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
283 if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
284 CI->setCallingConv(F->getCallingConv());
289 /// Append a suffix to the function name according to the type of 'Op'.
290 static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) {
291 if (!Op->getType()->isDoubleTy()) {
294 if (Op->getType()->isFloatTy())
304 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g.
305 /// 'floor'). This function is known to take a single of type matching 'Op' and
306 /// returns one value with the same type. If 'Op' is a long double, 'l' is
307 /// added as the suffix of name, if 'Op' is a float, we add a 'f' suffix.
308 Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
309 const AttributeSet &Attrs) {
310 SmallString<20> NameBuffer;
311 AppendTypeSuffix(Op, Name, NameBuffer);
313 Module *M = B.GetInsertBlock()->getParent()->getParent();
314 Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
315 Op->getType(), NULL);
316 CallInst *CI = B.CreateCall(Callee, Op, Name);
317 CI->setAttributes(Attrs);
318 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
319 CI->setCallingConv(F->getCallingConv());
324 /// EmitBinaryFloatFnCall - Emit a call to the binary function named 'Name'
325 /// (e.g. 'fmin'). This function is known to take type matching 'Op1' and 'Op2'
326 /// and return one value with the same type. If 'Op1/Op2' are long double, 'l'
327 /// is added as the suffix of name, if 'Op1/Op2' is a float, we add a 'f'
329 Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
330 IRBuilder<> &B, const AttributeSet &Attrs) {
331 SmallString<20> NameBuffer;
332 AppendTypeSuffix(Op1, Name, NameBuffer);
334 Module *M = B.GetInsertBlock()->getParent()->getParent();
335 Value *Callee = M->getOrInsertFunction(Name, Op1->getType(),
336 Op1->getType(), Op2->getType(), NULL);
337 CallInst *CI = B.CreateCall2(Callee, Op1, Op2, Name);
338 CI->setAttributes(Attrs);
339 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
340 CI->setCallingConv(F->getCallingConv());
345 /// EmitPutChar - Emit a call to the putchar function. This assumes that Char
347 Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B, const DataLayout *TD,
348 const TargetLibraryInfo *TLI) {
349 if (!TLI->has(LibFunc::putchar))
352 Module *M = B.GetInsertBlock()->getParent()->getParent();
353 Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
354 B.getInt32Ty(), NULL);
355 CallInst *CI = B.CreateCall(PutChar,
356 B.CreateIntCast(Char,
362 if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
363 CI->setCallingConv(F->getCallingConv());
367 /// EmitPutS - Emit a call to the puts function. This assumes that Str is
369 Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B, const DataLayout *TD,
370 const TargetLibraryInfo *TLI) {
371 if (!TLI->has(LibFunc::puts))
374 Module *M = B.GetInsertBlock()->getParent()->getParent();
376 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
377 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
378 Attribute::NoUnwind);
380 Value *PutS = M->getOrInsertFunction("puts",
381 AttributeSet::get(M->getContext(), AS),
385 CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
386 if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
387 CI->setCallingConv(F->getCallingConv());
391 /// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
392 /// an integer and File is a pointer to FILE.
393 Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
394 const DataLayout *TD, const TargetLibraryInfo *TLI) {
395 if (!TLI->has(LibFunc::fputc))
398 Module *M = B.GetInsertBlock()->getParent()->getParent();
400 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
401 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
402 Attribute::NoUnwind);
404 if (File->getType()->isPointerTy())
405 F = M->getOrInsertFunction("fputc",
406 AttributeSet::get(M->getContext(), AS),
408 B.getInt32Ty(), File->getType(),
411 F = M->getOrInsertFunction("fputc",
414 File->getType(), NULL);
415 Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
417 CallInst *CI = B.CreateCall2(F, Char, File, "fputc");
419 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
420 CI->setCallingConv(Fn->getCallingConv());
424 /// EmitFPutS - Emit a call to the puts function. Str is required to be a
425 /// pointer and File is a pointer to FILE.
426 Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B,
427 const DataLayout *TD, const TargetLibraryInfo *TLI) {
428 if (!TLI->has(LibFunc::fputs))
431 Module *M = B.GetInsertBlock()->getParent()->getParent();
433 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
434 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
435 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
436 Attribute::NoUnwind);
437 StringRef FPutsName = TLI->getName(LibFunc::fputs);
439 if (File->getType()->isPointerTy())
440 F = M->getOrInsertFunction(FPutsName,
441 AttributeSet::get(M->getContext(), AS),
444 File->getType(), NULL);
446 F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
448 File->getType(), NULL);
449 CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
451 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
452 CI->setCallingConv(Fn->getCallingConv());
456 /// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
457 /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
458 Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File,
459 IRBuilder<> &B, const DataLayout *TD,
460 const TargetLibraryInfo *TLI) {
461 if (!TLI->has(LibFunc::fwrite))
464 Module *M = B.GetInsertBlock()->getParent()->getParent();
466 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
467 AS[1] = AttributeSet::get(M->getContext(), 4, Attribute::NoCapture);
468 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
469 Attribute::NoUnwind);
470 LLVMContext &Context = B.GetInsertBlock()->getContext();
471 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
473 if (File->getType()->isPointerTy())
474 F = M->getOrInsertFunction(FWriteName,
475 AttributeSet::get(M->getContext(), AS),
476 TD->getIntPtrType(Context),
478 TD->getIntPtrType(Context),
479 TD->getIntPtrType(Context),
480 File->getType(), NULL);
482 F = M->getOrInsertFunction(FWriteName, TD->getIntPtrType(Context),
484 TD->getIntPtrType(Context),
485 TD->getIntPtrType(Context),
486 File->getType(), NULL);
487 CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
488 ConstantInt::get(TD->getIntPtrType(Context), 1), File);
490 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
491 CI->setCallingConv(Fn->getCallingConv());
495 SimplifyFortifiedLibCalls::~SimplifyFortifiedLibCalls() { }
497 bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const DataLayout *TD,
498 const TargetLibraryInfo *TLI) {
499 // We really need DataLayout for later.
500 if (!TD) return false;
503 Function *Callee = CI->getCalledFunction();
504 StringRef Name = Callee->getName();
505 FunctionType *FT = Callee->getFunctionType();
506 LLVMContext &Context = CI->getParent()->getContext();
509 if (Name == "__memcpy_chk") {
510 // Check if this has the right signature.
511 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
512 !FT->getParamType(0)->isPointerTy() ||
513 !FT->getParamType(1)->isPointerTy() ||
514 FT->getParamType(2) != TD->getIntPtrType(Context) ||
515 FT->getParamType(3) != TD->getIntPtrType(Context))
518 if (isFoldable(3, 2, false)) {
519 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
520 CI->getArgOperand(2), 1);
521 replaceCall(CI->getArgOperand(0));
527 // Should be similar to memcpy.
528 if (Name == "__mempcpy_chk") {
532 if (Name == "__memmove_chk") {
533 // Check if this has the right signature.
534 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
535 !FT->getParamType(0)->isPointerTy() ||
536 !FT->getParamType(1)->isPointerTy() ||
537 FT->getParamType(2) != TD->getIntPtrType(Context) ||
538 FT->getParamType(3) != TD->getIntPtrType(Context))
541 if (isFoldable(3, 2, false)) {
542 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
543 CI->getArgOperand(2), 1);
544 replaceCall(CI->getArgOperand(0));
550 if (Name == "__memset_chk") {
551 // Check if this has the right signature.
552 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
553 !FT->getParamType(0)->isPointerTy() ||
554 !FT->getParamType(1)->isIntegerTy() ||
555 FT->getParamType(2) != TD->getIntPtrType(Context) ||
556 FT->getParamType(3) != TD->getIntPtrType(Context))
559 if (isFoldable(3, 2, false)) {
560 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
562 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
563 replaceCall(CI->getArgOperand(0));
569 if (Name == "__strcpy_chk" || Name == "__stpcpy_chk") {
570 // Check if this has the right signature.
571 if (FT->getNumParams() != 3 ||
572 FT->getReturnType() != FT->getParamType(0) ||
573 FT->getParamType(0) != FT->getParamType(1) ||
574 FT->getParamType(0) != Type::getInt8PtrTy(Context) ||
575 FT->getParamType(2) != TD->getIntPtrType(Context))
579 // If a) we don't have any length information, or b) we know this will
580 // fit then just lower to a plain st[rp]cpy. Otherwise we'll keep our
581 // st[rp]cpy_chk call which may fail at runtime if the size is too long.
582 // TODO: It might be nice to get a maximum length out of the possible
583 // string lengths for varying.
584 if (isFoldable(2, 1, true)) {
585 Value *Ret = EmitStrCpy(CI->getArgOperand(0), CI->getArgOperand(1), B, TD,
586 TLI, Name.substr(2, 6));
595 if (Name == "__strncpy_chk" || Name == "__stpncpy_chk") {
596 // Check if this has the right signature.
597 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
598 FT->getParamType(0) != FT->getParamType(1) ||
599 FT->getParamType(0) != Type::getInt8PtrTy(Context) ||
600 !FT->getParamType(2)->isIntegerTy() ||
601 FT->getParamType(3) != TD->getIntPtrType(Context))
604 if (isFoldable(3, 2, false)) {
605 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
606 CI->getArgOperand(2), B, TD, TLI,
616 if (Name == "__strcat_chk") {
620 if (Name == "__strncat_chk") {