]> granicus.if.org Git - llvm/commitdiff
TargetLibraryInfo: Introduce wcslen
authorMatthias Braun <matze@braunis.de>
Fri, 5 May 2017 20:25:50 +0000 (20:25 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 5 May 2017 20:25:50 +0000 (20:25 +0000)
wcslen is part of the C99 and C++98 standards.

- This introduces the function to TargetLibraryInfo.
- Also set attributes for wcslen in llvm::inferLibFuncAttributes().

Differential Revision: https://reviews.llvm.org/D32837

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302278 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/TargetLibraryInfo.def
lib/Analysis/TargetLibraryInfo.cpp
lib/Transforms/Utils/BuildLibCalls.cpp
unittests/Analysis/TargetLibraryInfoTest.cpp

index 637fc7ed30ddeb0c188ad15a50780ac543067f52..099a3c7cf2acb3fcbb64756ea759820e75db6d07 100644 (file)
@@ -1115,6 +1115,9 @@ TLI_DEFINE_STRING_INTERNAL("vsprintf")
 /// int vsscanf(const char *s, const char *format, va_list arg);
 TLI_DEFINE_ENUM_INTERNAL(vsscanf)
 TLI_DEFINE_STRING_INTERNAL("vsscanf")
+/// size_t wcslen (const wchar_t* wcs);
+TLI_DEFINE_ENUM_INTERNAL(wcslen)
+TLI_DEFINE_STRING_INTERNAL("wcslen")
 /// ssize_t write(int fildes, const void *buf, size_t nbyte);
 TLI_DEFINE_ENUM_INTERNAL(write)
 TLI_DEFINE_STRING_INTERNAL("write")
index be734fa91425d2653543740a67053eea566eb72e..848e1b4717b59b3ec05ca415a1f92e7ba65fa648 100644 (file)
@@ -1176,6 +1176,10 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
             FTy.getParamType(0)->isPointerTy() &&
             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
 
+  case LibFunc_wcslen:
+    return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
+            FTy.getReturnType()->isIntegerTy());
+
   case LibFunc::NumLibFuncs:
     break;
   }
index 1956697ccb8bf48f555600d8867429aa36065e47..ebde1f9a17dd6b0e459c795a5f967843ee2b32a2 100644 (file)
@@ -113,6 +113,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
   bool Changed = false;
   switch (TheLibFunc) {
   case LibFunc_strlen:
+  case LibFunc_wcslen:
     Changed |= setOnlyReadsMemory(F);
     Changed |= setDoesNotThrow(F);
     Changed |= setDoesNotCapture(F, 0);
index 598429c968aa998351d58f63f25b8f0965bc8309..44c141d6a1e9f0f6d6bdbd8f724b2cb9e64d6dd2 100644 (file)
@@ -334,6 +334,7 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
     "declare i32 @vsnprintf(i8*, i64, i8*, %struct*)\n"
     "declare i32 @vsprintf(i8*, i8*, %struct*)\n"
     "declare i32 @vsscanf(i8*, i8*, %struct*)\n"
+    "declare i64 @wcslen(i32*)\n"
 
     // These functions were also extracted from the OS X headers, but they are
     // available with a special name on darwin.