[libc] Add restrict qualifiers to string library; give consistent naming scheme to TableGen files.

Reviewed By: sivachandra

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

GitOrigin-RevId: 79ce64ea0872b81ca73e26c4c8ec1680439064bd
diff --git a/spec/posix.td b/spec/posix.td
index 9463169..c20cbef 100644
--- a/spec/posix.td
+++ b/spec/posix.td
@@ -1,22 +1,22 @@
 def SigSetType : NamedType<"sigset_t">;
 def SigSetPtrType : PtrType<SigSetType>;
 def ConstSigSetPtrType : ConstType<SigSetPtrType>;
-def RestrictSigSetType : RestrictedPtrType<SigSetType>;
-def ConstRestrictSigSetType : ConstType<RestrictSigSetType>;
+def RestrictedSigSetType : RestrictedPtrType<SigSetType>;
+def ConstRestrictedSigSetType : ConstType<RestrictedSigSetType>;
 
 def StructSigaction : NamedType<"struct sigaction">;
 def StructSigactionPtr : PtrType<StructSigaction>;
 def ConstStructSigactionPtr : ConstType<StructSigactionPtr>;
-def RestrictStructSigactionPtr : RestrictedPtrType<StructSigaction>;
-def ConstRestrictStructSigactionPtr : ConstType<RestrictStructSigactionPtr>;
+def RestrictedStructSigactionPtr : RestrictedPtrType<StructSigaction>;
+def ConstRestrictedStructSigactionPtr : ConstType<RestrictedStructSigactionPtr>;
 
 def POSIX : StandardSpec<"POSIX"> {
-  // TODO: Change naming so that they're consistent with other files.
   PtrType CharPtr = PtrType<CharType>;
-  ConstType ConstCharPtr = ConstType<CharPtr>;
   RestrictedPtrType RestrictedCharPtr = RestrictedPtrType<CharType>;
-  ConstType ConstRestrictedCharPtr = ConstType<RestrictedCharPtr>;
   RestrictedPtrType CharRestrictedDoublePtr = RestrictedPtrType<CharPtr>;
+  ConstType ConstCharPtr = ConstType<CharPtr>;
+  ConstType ConstRestrictedCharPtr = ConstType<RestrictedCharPtr>;
+
   NamedType OffTType = NamedType<"off_t">;
   NamedType SSizeTType = NamedType<"ssize_t">;
 
@@ -160,8 +160,8 @@
           "sigaction",
           RetValSpec<IntType>,
           [ArgSpec<IntType>,
-           ArgSpec<ConstRestrictStructSigactionPtr>,
-           ArgSpec<RestrictStructSigactionPtr>]
+           ArgSpec<ConstRestrictedStructSigactionPtr>,
+           ArgSpec<RestrictedStructSigactionPtr>]
         >,
         FunctionSpec<
           "sigdelset",
@@ -172,7 +172,7 @@
         FunctionSpec<
           "sigprocmask",
           RetValSpec<IntType>,
-          [ArgSpec<IntType>, ArgSpec<ConstRestrictSigSetType>, ArgSpec<RestrictSigSetType>]
+          [ArgSpec<IntType>, ArgSpec<ConstRestrictedSigSetType>, ArgSpec<RestrictedSigSetType>]
         >,
         FunctionSpec<
           "sigemptyset",
diff --git a/src/string/strcat.cpp b/src/string/strcat.cpp
index 8392d23..c02de2d 100644
--- a/src/string/strcat.cpp
+++ b/src/string/strcat.cpp
@@ -14,7 +14,8 @@
 
 namespace __llvm_libc {
 
-char *LLVM_LIBC_ENTRYPOINT(strcat)(char *dest, const char *src) {
+char *LLVM_LIBC_ENTRYPOINT(strcat)(char *__restrict dest,
+                                   const char *__restrict src) {
   __llvm_libc::strcpy(dest + __llvm_libc::strlen(dest), src);
   return dest;
 }
diff --git a/src/string/strcat.h b/src/string/strcat.h
index e068199..517088a 100644
--- a/src/string/strcat.h
+++ b/src/string/strcat.h
@@ -13,7 +13,7 @@
 
 namespace __llvm_libc {
 
-char *strcat(char *dest, const char *src);
+char *strcat(char *__restrict dest, const char *__restrict src);
 
 } // namespace __llvm_libc
 
diff --git a/src/string/strcpy.cpp b/src/string/strcpy.cpp
index 33f9417..6927d9d 100644
--- a/src/string/strcpy.cpp
+++ b/src/string/strcpy.cpp
@@ -14,7 +14,8 @@
 
 namespace __llvm_libc {
 
-char *LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {
+char *LLVM_LIBC_ENTRYPOINT(strcpy)(char *__restrict dest,
+                                   const char *__restrict src) {
   return reinterpret_cast<char *>(
       __llvm_libc::memcpy(dest, src, __llvm_libc::strlen(src) + 1));
 }
diff --git a/src/string/strcpy.h b/src/string/strcpy.h
index 033c2a3..03de39d 100644
--- a/src/string/strcpy.h
+++ b/src/string/strcpy.h
@@ -13,7 +13,7 @@
 
 namespace __llvm_libc {
 
-char *strcpy(char *dest, const char *src);
+char *strcpy(char *__restrict dest, const char *__restrict src);
 
 } // namespace __llvm_libc
 
diff --git a/src/string/string_utils.h b/src/string/string_utils.h
index 93a26c8..234246c 100644
--- a/src/string/string_utils.h
+++ b/src/string/string_utils.h
@@ -37,8 +37,9 @@
 // is found is then stored within 'context' for subsequent calls. Subsequent
 // calls will use 'context' when a nullptr is passed in for 'src'. Once the null
 // terminating character is reached, returns a nullptr.
-static inline char *string_token(char *src, const char *delimiter_string,
-                                 char **saveptr) {
+static inline char *string_token(char *__restrict src,
+                                 const char *__restrict delimiter_string,
+                                 char **__restrict saveptr) {
   cpp::Bitset<256> delimiter_set;
   for (; *delimiter_string; ++delimiter_string)
     delimiter_set.set(*delimiter_string);
diff --git a/src/string/strtok.cpp b/src/string/strtok.cpp
index 6bd02e2..3a8ab99 100644
--- a/src/string/strtok.cpp
+++ b/src/string/strtok.cpp
@@ -15,9 +15,8 @@
 
 static char *strtok_str = nullptr;
 
-// TODO: Place restrict qualifier where necessary for this and other function
-// arguments.
-char *LLVM_LIBC_ENTRYPOINT(strtok)(char *src, const char *delimiter_string) {
+char *LLVM_LIBC_ENTRYPOINT(strtok)(char *__restrict src,
+                                   const char *__restrict delimiter_string) {
   return internal::string_token(src, delimiter_string, &strtok_str);
 }
 
diff --git a/src/string/strtok.h b/src/string/strtok.h
index c16e764..33ac681 100644
--- a/src/string/strtok.h
+++ b/src/string/strtok.h
@@ -11,7 +11,7 @@
 
 namespace __llvm_libc {
 
-char *strtok(char *src, const char *delimiter_string);
+char *strtok(char *__restrict src, const char *__restrict delimiter_string);
 
 } // namespace __llvm_libc
 
diff --git a/src/string/strtok_r.cpp b/src/string/strtok_r.cpp
index 61f39a0..4f9ab34 100644
--- a/src/string/strtok_r.cpp
+++ b/src/string/strtok_r.cpp
@@ -13,8 +13,9 @@
 
 namespace __llvm_libc {
 
-char *LLVM_LIBC_ENTRYPOINT(strtok_r)(char *src, const char *delimiter_string,
-                                     char **saveptr) {
+char *LLVM_LIBC_ENTRYPOINT(strtok_r)(char *__restrict src,
+                                     const char *__restrict delimiter_string,
+                                     char **__restrict saveptr) {
   return internal::string_token(src, delimiter_string, saveptr);
 }
 
diff --git a/src/string/strtok_r.h b/src/string/strtok_r.h
index 28fc40f..f1aff3e 100644
--- a/src/string/strtok_r.h
+++ b/src/string/strtok_r.h
@@ -11,7 +11,8 @@
 
 namespace __llvm_libc {
 
-char *strtok_r(char *src, const char *delimiter_string, char **saveptr);
+char *strtok_r(char *__restrict src, const char *__restrict delimiter_string,
+               char **__restrict saveptr);
 
 } // namespace __llvm_libc