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 unsigned AS = V->getType()->getPointerAddressSpace();
31 return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
34 /// EmitStrLen - Emit a call to the strlen function to the builder, for the
35 /// specified pointer. This always returns an integer value of size intptr_t.
36 Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout *TD,
37 const TargetLibraryInfo *TLI) {
38 if (!TLI->has(LibFunc::strlen))
41 Module *M = B.GetInsertBlock()->getParent()->getParent();
43 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
44 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
45 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
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, AVs);
75 LLVMContext &Context = B.GetInsertBlock()->getContext();
76 Constant *StrNLen = M->getOrInsertFunction("strnlen",
77 AttributeSet::get(M->getContext(),
79 TD->getIntPtrType(Context),
81 TD->getIntPtrType(Context),
83 CallInst *CI = B.CreateCall2(StrNLen, CastToCStr(Ptr, B), MaxLen, "strnlen");
84 if (const Function *F = dyn_cast<Function>(StrNLen->stripPointerCasts()))
85 CI->setCallingConv(F->getCallingConv());
90 /// EmitStrChr - Emit a call to the strchr function to the builder, for the
91 /// specified pointer and character. Ptr is required to be some pointer type,
92 /// and the return value has 'i8*' type.
93 Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B,
94 const DataLayout *TD, const TargetLibraryInfo *TLI) {
95 if (!TLI->has(LibFunc::strchr))
98 Module *M = B.GetInsertBlock()->getParent()->getParent();
99 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
101 AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
103 Type *I8Ptr = B.getInt8PtrTy();
104 Type *I32Ty = B.getInt32Ty();
105 Constant *StrChr = M->getOrInsertFunction("strchr",
106 AttributeSet::get(M->getContext(),
108 I8Ptr, I8Ptr, I32Ty, NULL);
109 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B),
110 ConstantInt::get(I32Ty, C), "strchr");
111 if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
112 CI->setCallingConv(F->getCallingConv());
116 /// EmitStrNCmp - Emit a call to the strncmp function to the builder.
117 Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len,
118 IRBuilder<> &B, const DataLayout *TD,
119 const TargetLibraryInfo *TLI) {
120 if (!TLI->has(LibFunc::strncmp))
123 Module *M = B.GetInsertBlock()->getParent()->getParent();
125 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
126 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
127 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
128 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
130 LLVMContext &Context = B.GetInsertBlock()->getContext();
131 Value *StrNCmp = M->getOrInsertFunction("strncmp",
132 AttributeSet::get(M->getContext(),
137 TD->getIntPtrType(Context), NULL);
138 CallInst *CI = B.CreateCall3(StrNCmp, CastToCStr(Ptr1, B),
139 CastToCStr(Ptr2, B), Len, "strncmp");
141 if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
142 CI->setCallingConv(F->getCallingConv());
147 /// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
148 /// specified pointer arguments.
149 Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
150 const DataLayout *TD, const TargetLibraryInfo *TLI,
152 if (!TLI->has(LibFunc::strcpy))
155 Module *M = B.GetInsertBlock()->getParent()->getParent();
157 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
158 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
159 Attribute::NoUnwind);
160 Type *I8Ptr = B.getInt8PtrTy();
161 Value *StrCpy = M->getOrInsertFunction(Name,
162 AttributeSet::get(M->getContext(), AS),
163 I8Ptr, I8Ptr, I8Ptr, NULL);
164 CallInst *CI = B.CreateCall2(StrCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
166 if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
167 CI->setCallingConv(F->getCallingConv());
171 /// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
172 /// specified pointer arguments.
173 Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len,
174 IRBuilder<> &B, const DataLayout *TD,
175 const TargetLibraryInfo *TLI, StringRef Name) {
176 if (!TLI->has(LibFunc::strncpy))
179 Module *M = B.GetInsertBlock()->getParent()->getParent();
181 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
182 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
183 Attribute::NoUnwind);
184 Type *I8Ptr = B.getInt8PtrTy();
185 Value *StrNCpy = M->getOrInsertFunction(Name,
186 AttributeSet::get(M->getContext(),
189 Len->getType(), NULL);
190 CallInst *CI = B.CreateCall3(StrNCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
192 if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
193 CI->setCallingConv(F->getCallingConv());
197 /// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
198 /// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
200 Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
201 IRBuilder<> &B, const DataLayout *TD,
202 const TargetLibraryInfo *TLI) {
203 if (!TLI->has(LibFunc::memcpy_chk))
206 Module *M = B.GetInsertBlock()->getParent()->getParent();
208 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
209 Attribute::NoUnwind);
210 LLVMContext &Context = B.GetInsertBlock()->getContext();
211 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
212 AttributeSet::get(M->getContext(), AS),
216 TD->getIntPtrType(Context),
217 TD->getIntPtrType(Context), NULL);
218 Dst = CastToCStr(Dst, B);
219 Src = CastToCStr(Src, B);
220 CallInst *CI = B.CreateCall4(MemCpy, Dst, Src, Len, ObjSize);
221 if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
222 CI->setCallingConv(F->getCallingConv());
226 /// EmitMemChr - Emit a call to the memchr function. This assumes that Ptr is
227 /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
228 Value *llvm::EmitMemChr(Value *Ptr, Value *Val,
229 Value *Len, IRBuilder<> &B, const DataLayout *TD,
230 const TargetLibraryInfo *TLI) {
231 if (!TLI->has(LibFunc::memchr))
234 Module *M = B.GetInsertBlock()->getParent()->getParent();
236 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
237 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
238 LLVMContext &Context = B.GetInsertBlock()->getContext();
239 Value *MemChr = M->getOrInsertFunction("memchr",
240 AttributeSet::get(M->getContext(), AS),
244 TD->getIntPtrType(Context),
246 CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
248 if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
249 CI->setCallingConv(F->getCallingConv());
254 /// EmitMemCmp - Emit a call to the memcmp function.
255 Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2,
256 Value *Len, IRBuilder<> &B, const DataLayout *TD,
257 const TargetLibraryInfo *TLI) {
258 if (!TLI->has(LibFunc::memcmp))
261 Module *M = B.GetInsertBlock()->getParent()->getParent();
263 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
264 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
265 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
266 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
268 LLVMContext &Context = B.GetInsertBlock()->getContext();
269 Value *MemCmp = M->getOrInsertFunction("memcmp",
270 AttributeSet::get(M->getContext(), AS),
274 TD->getIntPtrType(Context), NULL);
275 CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
278 if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
279 CI->setCallingConv(F->getCallingConv());
284 /// Append a suffix to the function name according to the type of 'Op'.
285 static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) {
286 if (!Op->getType()->isDoubleTy()) {
289 if (Op->getType()->isFloatTy())
299 /// EmitUnaryFloatFnCall - Emit a call to the unary function named 'Name' (e.g.
300 /// 'floor'). This function is known to take a single of type matching 'Op' and
301 /// returns one value with the same type. If 'Op' is a long double, 'l' is
302 /// added as the suffix of name, if 'Op' is a float, we add a 'f' suffix.
303 Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
304 const AttributeSet &Attrs) {
305 SmallString<20> NameBuffer;
306 AppendTypeSuffix(Op, Name, NameBuffer);
308 Module *M = B.GetInsertBlock()->getParent()->getParent();
309 Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
310 Op->getType(), NULL);
311 CallInst *CI = B.CreateCall(Callee, Op, Name);
312 CI->setAttributes(Attrs);
313 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
314 CI->setCallingConv(F->getCallingConv());
319 /// EmitBinaryFloatFnCall - Emit a call to the binary function named 'Name'
320 /// (e.g. 'fmin'). This function is known to take type matching 'Op1' and 'Op2'
321 /// and return one value with the same type. If 'Op1/Op2' are long double, 'l'
322 /// is added as the suffix of name, if 'Op1/Op2' is a float, we add a 'f'
324 Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
325 IRBuilder<> &B, const AttributeSet &Attrs) {
326 SmallString<20> NameBuffer;
327 AppendTypeSuffix(Op1, Name, NameBuffer);
329 Module *M = B.GetInsertBlock()->getParent()->getParent();
330 Value *Callee = M->getOrInsertFunction(Name, Op1->getType(),
331 Op1->getType(), Op2->getType(), NULL);
332 CallInst *CI = B.CreateCall2(Callee, Op1, Op2, Name);
333 CI->setAttributes(Attrs);
334 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
335 CI->setCallingConv(F->getCallingConv());
340 /// EmitPutChar - Emit a call to the putchar function. This assumes that Char
342 Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B, const DataLayout *TD,
343 const TargetLibraryInfo *TLI) {
344 if (!TLI->has(LibFunc::putchar))
347 Module *M = B.GetInsertBlock()->getParent()->getParent();
348 Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
349 B.getInt32Ty(), NULL);
350 CallInst *CI = B.CreateCall(PutChar,
351 B.CreateIntCast(Char,
357 if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
358 CI->setCallingConv(F->getCallingConv());
362 /// EmitPutS - Emit a call to the puts function. This assumes that Str is
364 Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B, const DataLayout *TD,
365 const TargetLibraryInfo *TLI) {
366 if (!TLI->has(LibFunc::puts))
369 Module *M = B.GetInsertBlock()->getParent()->getParent();
371 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
372 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
373 Attribute::NoUnwind);
375 Value *PutS = M->getOrInsertFunction("puts",
376 AttributeSet::get(M->getContext(), AS),
380 CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
381 if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
382 CI->setCallingConv(F->getCallingConv());
386 /// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
387 /// an integer and File is a pointer to FILE.
388 Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
389 const DataLayout *TD, const TargetLibraryInfo *TLI) {
390 if (!TLI->has(LibFunc::fputc))
393 Module *M = B.GetInsertBlock()->getParent()->getParent();
395 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
396 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
397 Attribute::NoUnwind);
399 if (File->getType()->isPointerTy())
400 F = M->getOrInsertFunction("fputc",
401 AttributeSet::get(M->getContext(), AS),
403 B.getInt32Ty(), File->getType(),
406 F = M->getOrInsertFunction("fputc",
409 File->getType(), NULL);
410 Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
412 CallInst *CI = B.CreateCall2(F, Char, File, "fputc");
414 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
415 CI->setCallingConv(Fn->getCallingConv());
419 /// EmitFPutS - Emit a call to the puts function. Str is required to be a
420 /// pointer and File is a pointer to FILE.
421 Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B,
422 const DataLayout *TD, const TargetLibraryInfo *TLI) {
423 if (!TLI->has(LibFunc::fputs))
426 Module *M = B.GetInsertBlock()->getParent()->getParent();
428 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
429 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
430 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
431 Attribute::NoUnwind);
432 StringRef FPutsName = TLI->getName(LibFunc::fputs);
434 if (File->getType()->isPointerTy())
435 F = M->getOrInsertFunction(FPutsName,
436 AttributeSet::get(M->getContext(), AS),
439 File->getType(), NULL);
441 F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
443 File->getType(), NULL);
444 CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
446 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
447 CI->setCallingConv(Fn->getCallingConv());
451 /// EmitFWrite - Emit a call to the fwrite function. This assumes that Ptr is
452 /// a pointer, Size is an 'intptr_t', and File is a pointer to FILE.
453 Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File,
454 IRBuilder<> &B, const DataLayout *TD,
455 const TargetLibraryInfo *TLI) {
456 if (!TLI->has(LibFunc::fwrite))
459 Module *M = B.GetInsertBlock()->getParent()->getParent();
461 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
462 AS[1] = AttributeSet::get(M->getContext(), 4, Attribute::NoCapture);
463 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
464 Attribute::NoUnwind);
465 LLVMContext &Context = B.GetInsertBlock()->getContext();
466 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
468 if (File->getType()->isPointerTy())
469 F = M->getOrInsertFunction(FWriteName,
470 AttributeSet::get(M->getContext(), AS),
471 TD->getIntPtrType(Context),
473 TD->getIntPtrType(Context),
474 TD->getIntPtrType(Context),
475 File->getType(), NULL);
477 F = M->getOrInsertFunction(FWriteName, TD->getIntPtrType(Context),
479 TD->getIntPtrType(Context),
480 TD->getIntPtrType(Context),
481 File->getType(), NULL);
482 CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
483 ConstantInt::get(TD->getIntPtrType(Context), 1), File);
485 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
486 CI->setCallingConv(Fn->getCallingConv());
490 SimplifyFortifiedLibCalls::~SimplifyFortifiedLibCalls() { }
492 bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const DataLayout *TD,
493 const TargetLibraryInfo *TLI) {
494 // We really need DataLayout for later.
495 if (!TD) return false;
498 Function *Callee = CI->getCalledFunction();
499 StringRef Name = Callee->getName();
500 FunctionType *FT = Callee->getFunctionType();
501 LLVMContext &Context = CI->getParent()->getContext();
504 if (Name == "__memcpy_chk") {
505 // Check if this has the right signature.
506 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
507 !FT->getParamType(0)->isPointerTy() ||
508 !FT->getParamType(1)->isPointerTy() ||
509 FT->getParamType(2) != TD->getIntPtrType(Context) ||
510 FT->getParamType(3) != TD->getIntPtrType(Context))
513 if (isFoldable(3, 2, false)) {
514 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
515 CI->getArgOperand(2), 1);
516 replaceCall(CI->getArgOperand(0));
522 // Should be similar to memcpy.
523 if (Name == "__mempcpy_chk") {
527 if (Name == "__memmove_chk") {
528 // Check if this has the right signature.
529 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
530 !FT->getParamType(0)->isPointerTy() ||
531 !FT->getParamType(1)->isPointerTy() ||
532 FT->getParamType(2) != TD->getIntPtrType(Context) ||
533 FT->getParamType(3) != TD->getIntPtrType(Context))
536 if (isFoldable(3, 2, false)) {
537 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
538 CI->getArgOperand(2), 1);
539 replaceCall(CI->getArgOperand(0));
545 if (Name == "__memset_chk") {
546 // Check if this has the right signature.
547 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
548 !FT->getParamType(0)->isPointerTy() ||
549 !FT->getParamType(1)->isIntegerTy() ||
550 FT->getParamType(2) != TD->getIntPtrType(Context) ||
551 FT->getParamType(3) != TD->getIntPtrType(Context))
554 if (isFoldable(3, 2, false)) {
555 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
557 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
558 replaceCall(CI->getArgOperand(0));
564 if (Name == "__strcpy_chk" || Name == "__stpcpy_chk") {
565 // Check if this has the right signature.
566 if (FT->getNumParams() != 3 ||
567 FT->getReturnType() != FT->getParamType(0) ||
568 FT->getParamType(0) != FT->getParamType(1) ||
569 FT->getParamType(0) != Type::getInt8PtrTy(Context) ||
570 FT->getParamType(2) != TD->getIntPtrType(Context))
574 // If a) we don't have any length information, or b) we know this will
575 // fit then just lower to a plain st[rp]cpy. Otherwise we'll keep our
576 // st[rp]cpy_chk call which may fail at runtime if the size is too long.
577 // TODO: It might be nice to get a maximum length out of the possible
578 // string lengths for varying.
579 if (isFoldable(2, 1, true)) {
580 Value *Ret = EmitStrCpy(CI->getArgOperand(0), CI->getArgOperand(1), B, TD,
581 TLI, Name.substr(2, 6));
590 if (Name == "__strncpy_chk" || Name == "__stpncpy_chk") {
591 // Check if this has the right signature.
592 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) ||
593 FT->getParamType(0) != FT->getParamType(1) ||
594 FT->getParamType(0) != Type::getInt8PtrTy(Context) ||
595 !FT->getParamType(2)->isIntegerTy() ||
596 FT->getParamType(3) != TD->getIntPtrType(Context))
599 if (isFoldable(3, 2, false)) {
600 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
601 CI->getArgOperand(2), B, TD, TLI,
611 if (Name == "__strcat_chk") {
615 if (Name == "__strncat_chk") {