blob: 8d910b81a2fa98ec5b3067b5ade833c1a5db8f3e [file] [log] [blame]
Eric Christopher87abfc52010-03-05 22:25:30 +00001//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements some functions that will create standard C libcalls.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Transforms/Utils/BuildLibCalls.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/SmallString.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000016#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"
Eli Friedman489c0ff2011-11-17 01:27:36 +000024#include "llvm/Target/TargetLibraryInfo.h"
Eric Christopher87abfc52010-03-05 22:25:30 +000025
26using namespace llvm;
27
28/// CastToCStr - Return V if it is an i8*, otherwise cast it to i8*.
29Value *llvm::CastToCStr(Value *V, IRBuilder<> &B) {
Matt Arsenaultbe558882014-04-23 20:58:57 +000030 unsigned AS = V->getType()->getPointerAddressSpace();
31 return B.CreateBitCast(V, B.getInt8PtrTy(AS), "cstr");
Eric Christopher87abfc52010-03-05 22:25:30 +000032}
33
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.
Micah Villmowcdfe20b2012-10-08 16:38:25 +000036Value *llvm::EmitStrLen(Value *Ptr, IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +000037 const TargetLibraryInfo *TLI) {
38 if (!TLI->has(LibFunc::strlen))
Craig Topperf40110f2014-04-25 05:29:35 +000039 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +000040
Evan Chengad6efbf2014-03-12 18:09:37 +000041 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +000042 AttributeSet AS[2];
43 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
Bill Wendlingc79e42c2012-12-22 00:37:52 +000044 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Craig Toppere1d12942014-08-27 05:25:25 +000045 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Eric Christopher87abfc52010-03-05 22:25:30 +000046
Chandler Carruth7ec50852012-11-01 08:07:29 +000047 LLVMContext &Context = B.GetInsertBlock()->getContext();
Bill Wendlingf86efb92012-11-20 05:09:20 +000048 Constant *StrLen = M->getOrInsertFunction("strlen",
Bill Wendlinge94d8432012-12-07 23:16:57 +000049 AttributeSet::get(M->getContext(),
Bill Wendling201d7b22013-01-26 00:03:11 +000050 AS),
Chandler Carruth7ec50852012-11-01 08:07:29 +000051 TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +000052 B.getInt8PtrTy(),
53 NULL);
54 CallInst *CI = B.CreateCall(StrLen, CastToCStr(Ptr, B), "strlen");
Evan Chengad6efbf2014-03-12 18:09:37 +000055 if (const Function *F = dyn_cast<Function>(StrLen->stripPointerCasts()))
56 CI->setCallingConv(F->getCallingConv());
57
Eric Christopher87abfc52010-03-05 22:25:30 +000058 return CI;
59}
60
Nuno Lopes7ba5b982012-07-25 17:18:59 +000061/// 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.
64Value *llvm::EmitStrNLen(Value *Ptr, Value *MaxLen, IRBuilder<> &B,
Micah Villmowcdfe20b2012-10-08 16:38:25 +000065 const DataLayout *TD, const TargetLibraryInfo *TLI) {
Nuno Lopes7ba5b982012-07-25 17:18:59 +000066 if (!TLI->has(LibFunc::strnlen))
Craig Topperf40110f2014-04-25 05:29:35 +000067 return nullptr;
Nuno Lopes7ba5b982012-07-25 17:18:59 +000068
Evan Chengad6efbf2014-03-12 18:09:37 +000069 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +000070 AttributeSet AS[2];
71 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
Bill Wendlingc79e42c2012-12-22 00:37:52 +000072 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Craig Toppere1d12942014-08-27 05:25:25 +000073 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Nuno Lopes7ba5b982012-07-25 17:18:59 +000074
Chandler Carruth7ec50852012-11-01 08:07:29 +000075 LLVMContext &Context = B.GetInsertBlock()->getContext();
Bill Wendlingf86efb92012-11-20 05:09:20 +000076 Constant *StrNLen = M->getOrInsertFunction("strnlen",
Bill Wendlinge94d8432012-12-07 23:16:57 +000077 AttributeSet::get(M->getContext(),
Bill Wendling201d7b22013-01-26 00:03:11 +000078 AS),
Chandler Carruth7ec50852012-11-01 08:07:29 +000079 TD->getIntPtrType(Context),
Nuno Lopes7ba5b982012-07-25 17:18:59 +000080 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +000081 TD->getIntPtrType(Context),
Nuno Lopes7ba5b982012-07-25 17:18:59 +000082 NULL);
83 CallInst *CI = B.CreateCall2(StrNLen, CastToCStr(Ptr, B), MaxLen, "strnlen");
Evan Chengad6efbf2014-03-12 18:09:37 +000084 if (const Function *F = dyn_cast<Function>(StrNLen->stripPointerCasts()))
85 CI->setCallingConv(F->getCallingConv());
86
Nuno Lopes7ba5b982012-07-25 17:18:59 +000087 return CI;
88}
89
Eric Christopher87abfc52010-03-05 22:25:30 +000090/// 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.
93Value *llvm::EmitStrChr(Value *Ptr, char C, IRBuilder<> &B,
Micah Villmowcdfe20b2012-10-08 16:38:25 +000094 const DataLayout *TD, const TargetLibraryInfo *TLI) {
Nuno Lopes89702e92012-07-25 16:46:31 +000095 if (!TLI->has(LibFunc::strchr))
Craig Topperf40110f2014-04-25 05:29:35 +000096 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +000097
Evan Chengad6efbf2014-03-12 18:09:37 +000098 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendlingc79e42c2012-12-22 00:37:52 +000099 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Bill Wendling201d7b22013-01-26 00:03:11 +0000100 AttributeSet AS =
Craig Toppere1d12942014-08-27 05:25:25 +0000101 AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Eric Christopher87abfc52010-03-05 22:25:30 +0000102
Chris Lattner229907c2011-07-18 04:54:35 +0000103 Type *I8Ptr = B.getInt8PtrTy();
104 Type *I32Ty = B.getInt32Ty();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000105 Constant *StrChr = M->getOrInsertFunction("strchr",
Bill Wendlinge94d8432012-12-07 23:16:57 +0000106 AttributeSet::get(M->getContext(),
Bill Wendling201d7b22013-01-26 00:03:11 +0000107 AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000108 I8Ptr, I8Ptr, I32Ty, NULL);
109 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B),
110 ConstantInt::get(I32Ty, C), "strchr");
Evan Chengad6efbf2014-03-12 18:09:37 +0000111 if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts()))
112 CI->setCallingConv(F->getCallingConv());
Eric Christopher87abfc52010-03-05 22:25:30 +0000113 return CI;
114}
115
Benjamin Kramer11188602010-06-15 21:34:25 +0000116/// EmitStrNCmp - Emit a call to the strncmp function to the builder.
117Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000118 IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000119 const TargetLibraryInfo *TLI) {
120 if (!TLI->has(LibFunc::strncmp))
Craig Topperf40110f2014-04-25 05:29:35 +0000121 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000122
Evan Chengad6efbf2014-03-12 18:09:37 +0000123 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000124 AttributeSet AS[3];
125 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
126 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
Bill Wendlingc79e42c2012-12-22 00:37:52 +0000127 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Craig Toppere1d12942014-08-27 05:25:25 +0000128 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Benjamin Kramer11188602010-06-15 21:34:25 +0000129
Chandler Carruth7ec50852012-11-01 08:07:29 +0000130 LLVMContext &Context = B.GetInsertBlock()->getContext();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000131 Value *StrNCmp = M->getOrInsertFunction("strncmp",
Bill Wendlinge94d8432012-12-07 23:16:57 +0000132 AttributeSet::get(M->getContext(),
Bill Wendling201d7b22013-01-26 00:03:11 +0000133 AS),
Benjamin Kramer11188602010-06-15 21:34:25 +0000134 B.getInt32Ty(),
135 B.getInt8PtrTy(),
136 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000137 TD->getIntPtrType(Context), NULL);
Benjamin Kramer11188602010-06-15 21:34:25 +0000138 CallInst *CI = B.CreateCall3(StrNCmp, CastToCStr(Ptr1, B),
139 CastToCStr(Ptr2, B), Len, "strncmp");
Evan Chengad6efbf2014-03-12 18:09:37 +0000140
141 if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts()))
142 CI->setCallingConv(F->getCallingConv());
143
Benjamin Kramer11188602010-06-15 21:34:25 +0000144 return CI;
145}
146
Eric Christopher87abfc52010-03-05 22:25:30 +0000147/// EmitStrCpy - Emit a call to the strcpy function to the builder, for the
148/// specified pointer arguments.
149Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000150 const DataLayout *TD, const TargetLibraryInfo *TLI,
Nuno Lopes89702e92012-07-25 16:46:31 +0000151 StringRef Name) {
152 if (!TLI->has(LibFunc::strcpy))
Craig Topperf40110f2014-04-25 05:29:35 +0000153 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000154
Evan Chengad6efbf2014-03-12 18:09:37 +0000155 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000156 AttributeSet AS[2];
157 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
158 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
159 Attribute::NoUnwind);
Chris Lattner229907c2011-07-18 04:54:35 +0000160 Type *I8Ptr = B.getInt8PtrTy();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000161 Value *StrCpy = M->getOrInsertFunction(Name,
Bill Wendling201d7b22013-01-26 00:03:11 +0000162 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000163 I8Ptr, I8Ptr, I8Ptr, NULL);
164 CallInst *CI = B.CreateCall2(StrCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
Benjamin Kramer2fc39562010-03-11 20:45:13 +0000165 Name);
Evan Chengad6efbf2014-03-12 18:09:37 +0000166 if (const Function *F = dyn_cast<Function>(StrCpy->stripPointerCasts()))
167 CI->setCallingConv(F->getCallingConv());
Eric Christopher87abfc52010-03-05 22:25:30 +0000168 return CI;
169}
170
Eric Christopher103e3ef2010-03-11 17:45:38 +0000171/// EmitStrNCpy - Emit a call to the strncpy function to the builder, for the
Eric Christopher43dc11c2010-03-11 01:25:07 +0000172/// specified pointer arguments.
173Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000174 IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000175 const TargetLibraryInfo *TLI, StringRef Name) {
176 if (!TLI->has(LibFunc::strncpy))
Craig Topperf40110f2014-04-25 05:29:35 +0000177 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000178
Evan Chengad6efbf2014-03-12 18:09:37 +0000179 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000180 AttributeSet AS[2];
181 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
182 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
183 Attribute::NoUnwind);
Chris Lattner229907c2011-07-18 04:54:35 +0000184 Type *I8Ptr = B.getInt8PtrTy();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000185 Value *StrNCpy = M->getOrInsertFunction(Name,
Bill Wendlinge94d8432012-12-07 23:16:57 +0000186 AttributeSet::get(M->getContext(),
Bill Wendling201d7b22013-01-26 00:03:11 +0000187 AS),
Eric Christophere8b281c2010-04-07 23:00:07 +0000188 I8Ptr, I8Ptr, I8Ptr,
189 Len->getType(), NULL);
Eric Christopher43dc11c2010-03-11 01:25:07 +0000190 CallInst *CI = B.CreateCall3(StrNCpy, CastToCStr(Dst, B), CastToCStr(Src, B),
191 Len, "strncpy");
Evan Chengad6efbf2014-03-12 18:09:37 +0000192 if (const Function *F = dyn_cast<Function>(StrNCpy->stripPointerCasts()))
193 CI->setCallingConv(F->getCallingConv());
Eric Christopher43dc11c2010-03-11 01:25:07 +0000194 return CI;
195}
196
Evan Chengd9e82232010-03-23 15:48:04 +0000197/// 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
199/// are pointers.
200Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000201 IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000202 const TargetLibraryInfo *TLI) {
203 if (!TLI->has(LibFunc::memcpy_chk))
Craig Topperf40110f2014-04-25 05:29:35 +0000204 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000205
Evan Chengad6efbf2014-03-12 18:09:37 +0000206 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000207 AttributeSet AS;
208 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
209 Attribute::NoUnwind);
Chandler Carruth7ec50852012-11-01 08:07:29 +0000210 LLVMContext &Context = B.GetInsertBlock()->getContext();
Evan Chengd9e82232010-03-23 15:48:04 +0000211 Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
Bill Wendling201d7b22013-01-26 00:03:11 +0000212 AttributeSet::get(M->getContext(), AS),
Evan Chengd9e82232010-03-23 15:48:04 +0000213 B.getInt8PtrTy(),
214 B.getInt8PtrTy(),
215 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000216 TD->getIntPtrType(Context),
217 TD->getIntPtrType(Context), NULL);
Evan Chengd9e82232010-03-23 15:48:04 +0000218 Dst = CastToCStr(Dst, B);
219 Src = CastToCStr(Src, B);
220 CallInst *CI = B.CreateCall4(MemCpy, Dst, Src, Len, ObjSize);
Evan Chengad6efbf2014-03-12 18:09:37 +0000221 if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
222 CI->setCallingConv(F->getCallingConv());
Evan Chengd9e82232010-03-23 15:48:04 +0000223 return CI;
224}
225
Eric Christopher87abfc52010-03-05 22:25:30 +0000226/// 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.
228Value *llvm::EmitMemChr(Value *Ptr, Value *Val,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000229 Value *Len, IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000230 const TargetLibraryInfo *TLI) {
231 if (!TLI->has(LibFunc::memchr))
Craig Topperf40110f2014-04-25 05:29:35 +0000232 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000233
Evan Chengad6efbf2014-03-12 18:09:37 +0000234 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000235 AttributeSet AS;
Bill Wendlingc79e42c2012-12-22 00:37:52 +0000236 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Craig Toppere1d12942014-08-27 05:25:25 +0000237 AS = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Chandler Carruth7ec50852012-11-01 08:07:29 +0000238 LLVMContext &Context = B.GetInsertBlock()->getContext();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000239 Value *MemChr = M->getOrInsertFunction("memchr",
Bill Wendling201d7b22013-01-26 00:03:11 +0000240 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000241 B.getInt8PtrTy(),
242 B.getInt8PtrTy(),
243 B.getInt32Ty(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000244 TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +0000245 NULL);
246 CallInst *CI = B.CreateCall3(MemChr, CastToCStr(Ptr, B), Val, Len, "memchr");
Evan Chengad6efbf2014-03-12 18:09:37 +0000247
248 if (const Function *F = dyn_cast<Function>(MemChr->stripPointerCasts()))
249 CI->setCallingConv(F->getCallingConv());
250
Eric Christopher87abfc52010-03-05 22:25:30 +0000251 return CI;
252}
253
254/// EmitMemCmp - Emit a call to the memcmp function.
255Value *llvm::EmitMemCmp(Value *Ptr1, Value *Ptr2,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000256 Value *Len, IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000257 const TargetLibraryInfo *TLI) {
258 if (!TLI->has(LibFunc::memcmp))
Craig Topperf40110f2014-04-25 05:29:35 +0000259 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000260
Evan Chengad6efbf2014-03-12 18:09:37 +0000261 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000262 AttributeSet AS[3];
263 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
264 AS[1] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
Bill Wendlingc79e42c2012-12-22 00:37:52 +0000265 Attribute::AttrKind AVs[2] = { Attribute::ReadOnly, Attribute::NoUnwind };
Craig Toppere1d12942014-08-27 05:25:25 +0000266 AS[2] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex, AVs);
Eric Christopher87abfc52010-03-05 22:25:30 +0000267
Chandler Carruth7ec50852012-11-01 08:07:29 +0000268 LLVMContext &Context = B.GetInsertBlock()->getContext();
Bill Wendlingf86efb92012-11-20 05:09:20 +0000269 Value *MemCmp = M->getOrInsertFunction("memcmp",
Bill Wendling201d7b22013-01-26 00:03:11 +0000270 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000271 B.getInt32Ty(),
272 B.getInt8PtrTy(),
273 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000274 TD->getIntPtrType(Context), NULL);
Eric Christopher87abfc52010-03-05 22:25:30 +0000275 CallInst *CI = B.CreateCall3(MemCmp, CastToCStr(Ptr1, B), CastToCStr(Ptr2, B),
276 Len, "memcmp");
Evan Chengad6efbf2014-03-12 18:09:37 +0000277
278 if (const Function *F = dyn_cast<Function>(MemCmp->stripPointerCasts()))
279 CI->setCallingConv(F->getCallingConv());
280
Eric Christopher87abfc52010-03-05 22:25:30 +0000281 return CI;
282}
283
Yi Jiang6ab044e2013-12-16 22:42:40 +0000284/// Append a suffix to the function name according to the type of 'Op'.
285static void AppendTypeSuffix(Value *Op, StringRef &Name, SmallString<20> &NameBuffer) {
286 if (!Op->getType()->isDoubleTy()) {
287 NameBuffer += Name;
288
289 if (Op->getType()->isFloatTy())
290 NameBuffer += 'f';
291 else
292 NameBuffer += 'l';
293
294 Name = NameBuffer;
295 }
296 return;
297}
298
Eric Christopher87abfc52010-03-05 22:25:30 +0000299/// 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.
Benjamin Kramerb106bcc2011-11-15 19:12:09 +0000303Value *llvm::EmitUnaryFloatFnCall(Value *Op, StringRef Name, IRBuilder<> &B,
Bill Wendlinge94d8432012-12-07 23:16:57 +0000304 const AttributeSet &Attrs) {
Benjamin Kramerb106bcc2011-11-15 19:12:09 +0000305 SmallString<20> NameBuffer;
Yi Jiang6ab044e2013-12-16 22:42:40 +0000306 AppendTypeSuffix(Op, Name, NameBuffer);
Eric Christopher87abfc52010-03-05 22:25:30 +0000307
Evan Chengad6efbf2014-03-12 18:09:37 +0000308 Module *M = B.GetInsertBlock()->getParent()->getParent();
Eric Christopher87abfc52010-03-05 22:25:30 +0000309 Value *Callee = M->getOrInsertFunction(Name, Op->getType(),
310 Op->getType(), NULL);
311 CallInst *CI = B.CreateCall(Callee, Op, Name);
312 CI->setAttributes(Attrs);
Evan Chengad6efbf2014-03-12 18:09:37 +0000313 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
314 CI->setCallingConv(F->getCallingConv());
315
Eric Christopher87abfc52010-03-05 22:25:30 +0000316 return CI;
317}
318
Yi Jiang6ab044e2013-12-16 22:42:40 +0000319/// 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'
323/// suffix.
324Value *llvm::EmitBinaryFloatFnCall(Value *Op1, Value *Op2, StringRef Name,
325 IRBuilder<> &B, const AttributeSet &Attrs) {
326 SmallString<20> NameBuffer;
327 AppendTypeSuffix(Op1, Name, NameBuffer);
328
Evan Chengad6efbf2014-03-12 18:09:37 +0000329 Module *M = B.GetInsertBlock()->getParent()->getParent();
Yi Jiang6ab044e2013-12-16 22:42:40 +0000330 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);
Evan Chengad6efbf2014-03-12 18:09:37 +0000334 if (const Function *F = dyn_cast<Function>(Callee->stripPointerCasts()))
335 CI->setCallingConv(F->getCallingConv());
336
Yi Jiang6ab044e2013-12-16 22:42:40 +0000337 return CI;
338}
339
Eric Christopher87abfc52010-03-05 22:25:30 +0000340/// EmitPutChar - Emit a call to the putchar function. This assumes that Char
341/// is an integer.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000342Value *llvm::EmitPutChar(Value *Char, IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000343 const TargetLibraryInfo *TLI) {
344 if (!TLI->has(LibFunc::putchar))
Craig Topperf40110f2014-04-25 05:29:35 +0000345 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000346
Evan Chengad6efbf2014-03-12 18:09:37 +0000347 Module *M = B.GetInsertBlock()->getParent()->getParent();
Eric Christopher87abfc52010-03-05 22:25:30 +0000348 Value *PutChar = M->getOrInsertFunction("putchar", B.getInt32Ty(),
349 B.getInt32Ty(), NULL);
350 CallInst *CI = B.CreateCall(PutChar,
351 B.CreateIntCast(Char,
352 B.getInt32Ty(),
353 /*isSigned*/true,
354 "chari"),
355 "putchar");
Evan Chengad6efbf2014-03-12 18:09:37 +0000356
357 if (const Function *F = dyn_cast<Function>(PutChar->stripPointerCasts()))
358 CI->setCallingConv(F->getCallingConv());
Eric Christopher87abfc52010-03-05 22:25:30 +0000359 return CI;
360}
361
362/// EmitPutS - Emit a call to the puts function. This assumes that Str is
363/// some pointer.
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000364Value *llvm::EmitPutS(Value *Str, IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000365 const TargetLibraryInfo *TLI) {
366 if (!TLI->has(LibFunc::puts))
Craig Topperf40110f2014-04-25 05:29:35 +0000367 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000368
Evan Chengad6efbf2014-03-12 18:09:37 +0000369 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000370 AttributeSet AS[2];
371 AS[0] = AttributeSet::get(M->getContext(), 1, Attribute::NoCapture);
372 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
373 Attribute::NoUnwind);
Eric Christopher87abfc52010-03-05 22:25:30 +0000374
Bill Wendlingf86efb92012-11-20 05:09:20 +0000375 Value *PutS = M->getOrInsertFunction("puts",
Bill Wendling201d7b22013-01-26 00:03:11 +0000376 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000377 B.getInt32Ty(),
378 B.getInt8PtrTy(),
379 NULL);
380 CallInst *CI = B.CreateCall(PutS, CastToCStr(Str, B), "puts");
Evan Chengad6efbf2014-03-12 18:09:37 +0000381 if (const Function *F = dyn_cast<Function>(PutS->stripPointerCasts()))
382 CI->setCallingConv(F->getCallingConv());
Nuno Lopes89702e92012-07-25 16:46:31 +0000383 return CI;
Eric Christopher87abfc52010-03-05 22:25:30 +0000384}
385
386/// EmitFPutC - Emit a call to the fputc function. This assumes that Char is
387/// an integer and File is a pointer to FILE.
Nuno Lopes89702e92012-07-25 16:46:31 +0000388Value *llvm::EmitFPutC(Value *Char, Value *File, IRBuilder<> &B,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000389 const DataLayout *TD, const TargetLibraryInfo *TLI) {
Nuno Lopes89702e92012-07-25 16:46:31 +0000390 if (!TLI->has(LibFunc::fputc))
Craig Topperf40110f2014-04-25 05:29:35 +0000391 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000392
Evan Chengad6efbf2014-03-12 18:09:37 +0000393 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000394 AttributeSet AS[2];
395 AS[0] = AttributeSet::get(M->getContext(), 2, Attribute::NoCapture);
396 AS[1] = AttributeSet::get(M->getContext(), AttributeSet::FunctionIndex,
397 Attribute::NoUnwind);
Eric Christopher87abfc52010-03-05 22:25:30 +0000398 Constant *F;
399 if (File->getType()->isPointerTy())
Bill Wendlingf86efb92012-11-20 05:09:20 +0000400 F = M->getOrInsertFunction("fputc",
Bill Wendling201d7b22013-01-26 00:03:11 +0000401 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000402 B.getInt32Ty(),
403 B.getInt32Ty(), File->getType(),
404 NULL);
405 else
406 F = M->getOrInsertFunction("fputc",
407 B.getInt32Ty(),
408 B.getInt32Ty(),
409 File->getType(), NULL);
410 Char = B.CreateIntCast(Char, B.getInt32Ty(), /*isSigned*/true,
411 "chari");
412 CallInst *CI = B.CreateCall2(F, Char, File, "fputc");
Evan Chengad6efbf2014-03-12 18:09:37 +0000413
414 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
415 CI->setCallingConv(Fn->getCallingConv());
Nuno Lopes89702e92012-07-25 16:46:31 +0000416 return CI;
Eric Christopher87abfc52010-03-05 22:25:30 +0000417}
418
419/// EmitFPutS - Emit a call to the puts function. Str is required to be a
420/// pointer and File is a pointer to FILE.
Nuno Lopes89702e92012-07-25 16:46:31 +0000421Value *llvm::EmitFPutS(Value *Str, Value *File, IRBuilder<> &B,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000422 const DataLayout *TD, const TargetLibraryInfo *TLI) {
Nuno Lopes89702e92012-07-25 16:46:31 +0000423 if (!TLI->has(LibFunc::fputs))
Craig Topperf40110f2014-04-25 05:29:35 +0000424 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000425
Evan Chengad6efbf2014-03-12 18:09:37 +0000426 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000427 AttributeSet AS[3];
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);
Eli Friedman489c0ff2011-11-17 01:27:36 +0000432 StringRef FPutsName = TLI->getName(LibFunc::fputs);
Eric Christopher87abfc52010-03-05 22:25:30 +0000433 Constant *F;
434 if (File->getType()->isPointerTy())
Bill Wendlingf86efb92012-11-20 05:09:20 +0000435 F = M->getOrInsertFunction(FPutsName,
Bill Wendling201d7b22013-01-26 00:03:11 +0000436 AttributeSet::get(M->getContext(), AS),
Eric Christopher87abfc52010-03-05 22:25:30 +0000437 B.getInt32Ty(),
438 B.getInt8PtrTy(),
439 File->getType(), NULL);
440 else
Eli Friedman489c0ff2011-11-17 01:27:36 +0000441 F = M->getOrInsertFunction(FPutsName, B.getInt32Ty(),
Eric Christopher87abfc52010-03-05 22:25:30 +0000442 B.getInt8PtrTy(),
443 File->getType(), NULL);
444 CallInst *CI = B.CreateCall2(F, CastToCStr(Str, B), File, "fputs");
Evan Chengad6efbf2014-03-12 18:09:37 +0000445
446 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
447 CI->setCallingConv(Fn->getCallingConv());
Nuno Lopes89702e92012-07-25 16:46:31 +0000448 return CI;
Eric Christopher87abfc52010-03-05 22:25:30 +0000449}
450
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.
Nuno Lopes89702e92012-07-25 16:46:31 +0000453Value *llvm::EmitFWrite(Value *Ptr, Value *Size, Value *File,
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000454 IRBuilder<> &B, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000455 const TargetLibraryInfo *TLI) {
456 if (!TLI->has(LibFunc::fwrite))
Craig Topperf40110f2014-04-25 05:29:35 +0000457 return nullptr;
Nuno Lopes89702e92012-07-25 16:46:31 +0000458
Evan Chengad6efbf2014-03-12 18:09:37 +0000459 Module *M = B.GetInsertBlock()->getParent()->getParent();
Bill Wendling201d7b22013-01-26 00:03:11 +0000460 AttributeSet AS[3];
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);
Chandler Carruth7ec50852012-11-01 08:07:29 +0000465 LLVMContext &Context = B.GetInsertBlock()->getContext();
Eli Friedman489c0ff2011-11-17 01:27:36 +0000466 StringRef FWriteName = TLI->getName(LibFunc::fwrite);
Eric Christopher87abfc52010-03-05 22:25:30 +0000467 Constant *F;
468 if (File->getType()->isPointerTy())
Bill Wendlingf86efb92012-11-20 05:09:20 +0000469 F = M->getOrInsertFunction(FWriteName,
Bill Wendling201d7b22013-01-26 00:03:11 +0000470 AttributeSet::get(M->getContext(), AS),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000471 TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +0000472 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000473 TD->getIntPtrType(Context),
474 TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +0000475 File->getType(), NULL);
476 else
Chandler Carruth7ec50852012-11-01 08:07:29 +0000477 F = M->getOrInsertFunction(FWriteName, TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +0000478 B.getInt8PtrTy(),
Chandler Carruth7ec50852012-11-01 08:07:29 +0000479 TD->getIntPtrType(Context),
480 TD->getIntPtrType(Context),
Eric Christopher87abfc52010-03-05 22:25:30 +0000481 File->getType(), NULL);
482 CallInst *CI = B.CreateCall4(F, CastToCStr(Ptr, B), Size,
Chandler Carruth7ec50852012-11-01 08:07:29 +0000483 ConstantInt::get(TD->getIntPtrType(Context), 1), File);
Evan Chengad6efbf2014-03-12 18:09:37 +0000484
485 if (const Function *Fn = dyn_cast<Function>(F->stripPointerCasts()))
486 CI->setCallingConv(Fn->getCallingConv());
Nuno Lopes89702e92012-07-25 16:46:31 +0000487 return CI;
Eric Christopher87abfc52010-03-05 22:25:30 +0000488}
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000489
Benjamin Kramera9565272010-03-12 20:41:29 +0000490SimplifyFortifiedLibCalls::~SimplifyFortifiedLibCalls() { }
491
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000492bool SimplifyFortifiedLibCalls::fold(CallInst *CI, const DataLayout *TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000493 const TargetLibraryInfo *TLI) {
Micah Villmowcdfe20b2012-10-08 16:38:25 +0000494 // We really need DataLayout for later.
Eric Christopher1f272f72010-04-12 04:48:00 +0000495 if (!TD) return false;
496
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000497 this->CI = CI;
Eric Christopher1f272f72010-04-12 04:48:00 +0000498 Function *Callee = CI->getCalledFunction();
499 StringRef Name = Callee->getName();
Chris Lattner229907c2011-07-18 04:54:35 +0000500 FunctionType *FT = Callee->getFunctionType();
Eric Christopher1f272f72010-04-12 04:48:00 +0000501 LLVMContext &Context = CI->getParent()->getContext();
Eli Friedmane217f892011-05-27 01:00:36 +0000502 IRBuilder<> B(CI);
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000503
504 if (Name == "__memcpy_chk") {
Eric Christopher1f272f72010-04-12 04:48:00 +0000505 // 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() ||
Chandler Carruth7ec50852012-11-01 08:07:29 +0000509 FT->getParamType(2) != TD->getIntPtrType(Context) ||
510 FT->getParamType(3) != TD->getIntPtrType(Context))
Eric Christopher1f272f72010-04-12 04:48:00 +0000511 return false;
Gabor Greif2de43a72010-06-28 12:29:20 +0000512
Gabor Greif6d673952010-07-16 09:38:02 +0000513 if (isFoldable(3, 2, false)) {
Benjamin Kramer84bd73c2010-12-27 00:25:32 +0000514 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
515 CI->getArgOperand(2), 1);
Gabor Greif2de43a72010-06-28 12:29:20 +0000516 replaceCall(CI->getArgOperand(0));
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000517 return true;
518 }
519 return false;
520 }
521
522 // Should be similar to memcpy.
523 if (Name == "__mempcpy_chk") {
524 return false;
525 }
526
527 if (Name == "__memmove_chk") {
Eric Christopher1f272f72010-04-12 04:48:00 +0000528 // 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() ||
Chandler Carruth7ec50852012-11-01 08:07:29 +0000532 FT->getParamType(2) != TD->getIntPtrType(Context) ||
533 FT->getParamType(3) != TD->getIntPtrType(Context))
Eric Christopher1f272f72010-04-12 04:48:00 +0000534 return false;
Gabor Greif2de43a72010-06-28 12:29:20 +0000535
Gabor Greif6d673952010-07-16 09:38:02 +0000536 if (isFoldable(3, 2, false)) {
Benjamin Kramer84bd73c2010-12-27 00:25:32 +0000537 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
538 CI->getArgOperand(2), 1);
Gabor Greif2de43a72010-06-28 12:29:20 +0000539 replaceCall(CI->getArgOperand(0));
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000540 return true;
541 }
542 return false;
543 }
544
545 if (Name == "__memset_chk") {
Eric Christopher1f272f72010-04-12 04:48:00 +0000546 // 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() ||
Chandler Carruth7ec50852012-11-01 08:07:29 +0000550 FT->getParamType(2) != TD->getIntPtrType(Context) ||
551 FT->getParamType(3) != TD->getIntPtrType(Context))
Eric Christopher1f272f72010-04-12 04:48:00 +0000552 return false;
Gabor Greif2de43a72010-06-28 12:29:20 +0000553
Gabor Greif6d673952010-07-16 09:38:02 +0000554 if (isFoldable(3, 2, false)) {
Gabor Greif2de43a72010-06-28 12:29:20 +0000555 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000556 false);
Benjamin Kramer84bd73c2010-12-27 00:25:32 +0000557 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
Gabor Greife3ba4862010-06-25 07:58:41 +0000558 replaceCall(CI->getArgOperand(0));
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000559 return true;
560 }
561 return false;
562 }
563
564 if (Name == "__strcpy_chk" || Name == "__stpcpy_chk") {
Eric Christopher1f272f72010-04-12 04:48:00 +0000565 // 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) ||
Chandler Carruth7ec50852012-11-01 08:07:29 +0000570 FT->getParamType(2) != TD->getIntPtrType(Context))
Eric Christopher1f272f72010-04-12 04:48:00 +0000571 return 0;
572
573
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000574 // 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.
Gabor Greif6d673952010-07-16 09:38:02 +0000579 if (isFoldable(2, 1, true)) {
Gabor Greif2de43a72010-06-28 12:29:20 +0000580 Value *Ret = EmitStrCpy(CI->getArgOperand(0), CI->getArgOperand(1), B, TD,
Nuno Lopes89702e92012-07-25 16:46:31 +0000581 TLI, Name.substr(2, 6));
Nuno Lopese7220312012-08-01 16:58:51 +0000582 if (!Ret)
Nuno Lopesa9a8c622012-08-01 17:13:28 +0000583 return false;
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000584 replaceCall(Ret);
585 return true;
586 }
587 return false;
588 }
589
Eric Christophere8b281c2010-04-07 23:00:07 +0000590 if (Name == "__strncpy_chk" || Name == "__stpncpy_chk") {
Eric Christopher1f272f72010-04-12 04:48:00 +0000591 // 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() ||
Chandler Carruth7ec50852012-11-01 08:07:29 +0000596 FT->getParamType(3) != TD->getIntPtrType(Context))
Eric Christopher4016dcd2010-04-13 16:41:29 +0000597 return false;
Gabor Greif2de43a72010-06-28 12:29:20 +0000598
Gabor Greif6d673952010-07-16 09:38:02 +0000599 if (isFoldable(3, 2, false)) {
Gabor Greif2de43a72010-06-28 12:29:20 +0000600 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
Nuno Lopes89702e92012-07-25 16:46:31 +0000601 CI->getArgOperand(2), B, TD, TLI,
602 Name.substr(2, 7));
Nuno Lopese7220312012-08-01 16:58:51 +0000603 if (!Ret)
Nuno Lopesa9a8c622012-08-01 17:13:28 +0000604 return false;
Benjamin Kramer7b88a492010-03-12 09:27:41 +0000605 replaceCall(Ret);
606 return true;
607 }
608 return false;
609 }
610
611 if (Name == "__strcat_chk") {
612 return false;
613 }
614
615 if (Name == "__strncat_chk") {
616 return false;
617 }
618
619 return false;
620}