[libc-commits] [libc] 79ce64e - [libc] Add restrict qualifiers to string library; give consistent naming scheme to TableGen files.
via libc-commits
libc-commits at lists.llvm.org
Fri Aug 14 12:41:36 PDT 2020
Author: cgyurgyik
Date: 2020-08-14T15:41:02-04:00
New Revision: 79ce64ea0872b81ca73e26c4c8ec1680439064bd
URL: https://github.com/llvm/llvm-project/commit/79ce64ea0872b81ca73e26c4c8ec1680439064bd
DIFF: https://github.com/llvm/llvm-project/commit/79ce64ea0872b81ca73e26c4c8ec1680439064bd.diff
LOG: [libc] Add restrict qualifiers to string library; give consistent naming scheme to TableGen files.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D85945
Added:
Modified:
libc/spec/posix.td
libc/src/string/strcat.cpp
libc/src/string/strcat.h
libc/src/string/strcpy.cpp
libc/src/string/strcpy.h
libc/src/string/string_utils.h
libc/src/string/strtok.cpp
libc/src/string/strtok.h
libc/src/string/strtok_r.cpp
libc/src/string/strtok_r.h
Removed:
################################################################################
diff --git a/libc/spec/posix.td b/libc/spec/posix.td
index 9463169b6a65..c20cbefe42ce 100644
--- a/libc/spec/posix.td
+++ b/libc/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 @@ def POSIX : StandardSpec<"POSIX"> {
"sigaction",
RetValSpec<IntType>,
[ArgSpec<IntType>,
- ArgSpec<ConstRestrictStructSigactionPtr>,
- ArgSpec<RestrictStructSigactionPtr>]
+ ArgSpec<ConstRestrictedStructSigactionPtr>,
+ ArgSpec<RestrictedStructSigactionPtr>]
>,
FunctionSpec<
"sigdelset",
@@ -172,7 +172,7 @@ def POSIX : StandardSpec<"POSIX"> {
FunctionSpec<
"sigprocmask",
RetValSpec<IntType>,
- [ArgSpec<IntType>, ArgSpec<ConstRestrictSigSetType>, ArgSpec<RestrictSigSetType>]
+ [ArgSpec<IntType>, ArgSpec<ConstRestrictedSigSetType>, ArgSpec<RestrictedSigSetType>]
>,
FunctionSpec<
"sigemptyset",
diff --git a/libc/src/string/strcat.cpp b/libc/src/string/strcat.cpp
index 8392d23cda03..c02de2d21b93 100644
--- a/libc/src/string/strcat.cpp
+++ b/libc/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/libc/src/string/strcat.h b/libc/src/string/strcat.h
index e068199fc6b9..517088af8ef0 100644
--- a/libc/src/string/strcat.h
+++ b/libc/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/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp
index 33f9417e083a..6927d9d3ec89 100644
--- a/libc/src/string/strcpy.cpp
+++ b/libc/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/libc/src/string/strcpy.h b/libc/src/string/strcpy.h
index 033c2a3e734a..03de39dfac42 100644
--- a/libc/src/string/strcpy.h
+++ b/libc/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/libc/src/string/string_utils.h b/libc/src/string/string_utils.h
index 93a26c8fda6a..234246c10b06 100644
--- a/libc/src/string/string_utils.h
+++ b/libc/src/string/string_utils.h
@@ -37,8 +37,9 @@ static inline size_t complementary_span(const char *src, const char *segment) {
// 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/libc/src/string/strtok.cpp b/libc/src/string/strtok.cpp
index 6bd02e24c9a4..3a8ab9919334 100644
--- a/libc/src/string/strtok.cpp
+++ b/libc/src/string/strtok.cpp
@@ -15,9 +15,8 @@ namespace __llvm_libc {
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/libc/src/string/strtok.h b/libc/src/string/strtok.h
index c16e764d393c..33ac68184a33 100644
--- a/libc/src/string/strtok.h
+++ b/libc/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/libc/src/string/strtok_r.cpp b/libc/src/string/strtok_r.cpp
index 61f39a0f647b..4f9ab34ee4f5 100644
--- a/libc/src/string/strtok_r.cpp
+++ b/libc/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/libc/src/string/strtok_r.h b/libc/src/string/strtok_r.h
index 28fc40f1e5ff..f1aff3e3176a 100644
--- a/libc/src/string/strtok_r.h
+++ b/libc/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
More information about the libc-commits
mailing list