[llvm] r221817 - Add fortified (__*_chk) library functions to TLI (NFC)

Ahmed Bougacha ahmed.bougacha at gmail.com
Wed Nov 12 13:23:35 PST 2014


Author: ab
Date: Wed Nov 12 15:23:34 2014
New Revision: 221817

URL: http://llvm.org/viewvc/llvm-project?rev=221817&view=rev
Log:
Add fortified (__*_chk) library functions to TLI (NFC)

One of them (__memcpy_chk) was already there, the others were checked
by comparing function names.
Note that the fortified libfuncs are now part of TLI, but are always
available, because they aren't generated, only optimized into the
non-checking versions.

Differential Revision: http://reviews.llvm.org/D6179

Modified:
    llvm/trunk/include/llvm/Target/TargetLibraryInfo.h
    llvm/trunk/lib/Target/TargetLibraryInfo.cpp
    llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp

Modified: llvm/trunk/include/llvm/Target/TargetLibraryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLibraryInfo.h?rev=221817&r1=221816&r2=221817&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLibraryInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLibraryInfo.h Wed Nov 12 15:23:34 2014
@@ -73,6 +73,11 @@ namespace llvm {
       dunder_isoc99_sscanf,
       /// void *__memcpy_chk(void *s1, const void *s2, size_t n, size_t s1size);
       memcpy_chk,
+      /// void *__memmove_chk(void *s1, const void *s2, size_t n,
+      ///                     size_t s1size);
+      memmove_chk,
+      /// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
+      memset_chk,
       /// double __sincospi_stret(double x);
       sincospi_stret,
       /// float __sincospif_stret(float x);
@@ -87,8 +92,18 @@ namespace llvm {
       sqrtf_finite,
       /// long double __sqrt_finite(long double x);
       sqrtl_finite,
+      /// char *__stpcpy_chk(char *s1, const char *s2, size_t s1size);
+      stpcpy_chk,
+      /// char *__stpncpy_chk(char *s1, const char *s2, size_t n,
+      ///                     size_t s1size);
+      stpncpy_chk,
+      /// char *__strcpy_chk(char *s1, const char *s2, size_t s1size);
+      strcpy_chk,
       /// char * __strdup(const char *s);
       dunder_strdup,
+      /// char *__strncpy_chk(char *s1, const char *s2, size_t n,
+      ///                     size_t s1size);
+      strncpy_chk,
       /// char *__strndup(const char *s, size_t n);
       dunder_strndup,
       /// char * __strtok_r(char *s, const char *delim, char **save_ptr);

Modified: llvm/trunk/lib/Target/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLibraryInfo.cpp?rev=221817&r1=221816&r2=221817&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetLibraryInfo.cpp Wed Nov 12 15:23:34 2014
@@ -51,6 +51,8 @@ const char* TargetLibraryInfo::StandardN
     "__isoc99_scanf",
     "__isoc99_sscanf",
     "__memcpy_chk",
+    "__memmove_chk",
+    "__memset_chk",
     "__sincospi_stret",
     "__sincospif_stret",
     "__sinpi",
@@ -58,7 +60,11 @@ const char* TargetLibraryInfo::StandardN
     "__sqrt_finite",
     "__sqrtf_finite",
     "__sqrtl_finite",
+    "__stpcpy_chk",
+    "__stpncpy_chk",
+    "__strcpy_chk",
     "__strdup",
+    "__strncpy_chk",
     "__strndup",
     "__strtok_r",
     "abs",

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=221817&r1=221816&r2=221817&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyLibCalls.cpp Wed Nov 12 15:23:34 2014
@@ -2184,28 +2184,20 @@ Value *LibCallSimplifier::optimizeCall(C
       return nullptr;
     case LibFunc::memcpy_chk:
       return optimizeMemCpyChk(CI, Builder);
-    default:
-      return nullptr;
-    }
-  }
-
-  if (!isCallingConvC)
-    return nullptr;
-
-  // Finally check for fortified library calls.
-  if (FuncName.endswith("_chk")) {
-    if (FuncName == "__memmove_chk")
+    case LibFunc::memmove_chk:
       return optimizeMemMoveChk(CI, Builder);
-    else if (FuncName == "__memset_chk")
+    case LibFunc::memset_chk:
       return optimizeMemSetChk(CI, Builder);
-    else if (FuncName == "__strcpy_chk")
+    case LibFunc::strcpy_chk:
       return optimizeStrCpyChk(CI, Builder);
-    else if (FuncName == "__stpcpy_chk")
+    case LibFunc::stpcpy_chk:
       return optimizeStpCpyChk(CI, Builder);
-    else if (FuncName == "__strncpy_chk")
-      return optimizeStrNCpyChk(CI, Builder);
-    else if (FuncName == "__stpncpy_chk")
+    case LibFunc::stpncpy_chk:
+    case LibFunc::strncpy_chk:
       return optimizeStrNCpyChk(CI, Builder);
+    default:
+      return nullptr;
+    }
   }
 
   return nullptr;





More information about the llvm-commits mailing list