[libc] [llvm] [compiler-rt] [clang] [Libc] Give more functions restrict qualifiers (PR #78061)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 13 21:36:47 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 49138d97c0d8a6d1c6935da414a1f3fea839263b d281918249db16549b5a8c8bdd61c90007cbeab0 -- clang/lib/Headers/llvm_libc_wrappers/string.h clang/test/Analysis/Inputs/system-header-simulator.h clang/test/Analysis/string.c compiler-rt/lib/sanitizer_common/sanitizer_libc.h libc/src/string/strsep.cpp libc/src/string/strsep.h llvm/lib/Support/regex_impl.h llvm/lib/Support/regstrlcpy.c
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
index bf52f50231..a639c610c9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h
@@ -41,10 +41,12 @@ s64 internal_atoll(const char *nptr);
 void *internal_memchr(const void *s, int c, uptr n);
 void *internal_memrchr(const void *s, int c, uptr n);
 int internal_memcmp(const void* s1, const void* s2, uptr n);
-ALWAYS_INLINE void *internal_memcpy(void *__restrict dest, const void *__restrict src, uptr n) {
+ALWAYS_INLINE void *internal_memcpy(void *__restrict dest,
+                                    const void *__restrict src, uptr n) {
   return __sanitizer_internal_memcpy(dest, src, n);
 }
-ALWAYS_INLINE void *internal_memmove(void *__restrict dest, const void *__restrict src, uptr n) {
+ALWAYS_INLINE void *internal_memmove(void *__restrict dest,
+                                     const void *__restrict src, uptr n) {
   return __sanitizer_internal_memmove(dest, src, n);
 }
 // Should not be used in performance-critical places.
@@ -57,11 +59,15 @@ int internal_strcmp(const char *s1, const char *s2);
 uptr internal_strcspn(const char *s, const char *reject);
 char *internal_strdup(const char *s);
 uptr internal_strlen(const char *s);
-uptr internal_strlcat(char *__restrict dst, const char *__restrict src, uptr maxlen);
-char *internal_strncat(char *__restrict dst, const char *__restrict src, uptr n);
+uptr internal_strlcat(char *__restrict dst, const char *__restrict src,
+                      uptr maxlen);
+char *internal_strncat(char *__restrict dst, const char *__restrict src,
+                       uptr n);
 int internal_strncmp(const char *s1, const char *s2, uptr n);
-uptr internal_strlcpy(char *__restrict dst, const char *__restrict src, uptr maxlen);
-char *internal_strncpy(char *__restrict dst, const char *__restrict src, uptr n);
+uptr internal_strlcpy(char *__restrict dst, const char *__restrict src,
+                      uptr maxlen);
+char *internal_strncpy(char *__restrict dst, const char *__restrict src,
+                       uptr n);
 uptr internal_strnlen(const char *s, uptr maxlen);
 char *internal_strrchr(const char *s, int c);
 char *internal_strstr(const char *haystack, const char *needle);
@@ -71,8 +77,10 @@ int internal_snprintf(char *buffer, uptr length, const char *format, ...)
     FORMAT(3, 4);
 uptr internal_wcslen(const wchar_t *s);
 uptr internal_wcsnlen(const wchar_t *s, uptr maxlen);
-wchar_t *internal_wcscpy(wchar_t *__restrict dst, const wchar_t *__restrict src);
-wchar_t *internal_wcsncpy(wchar_t *__restrict dst, const wchar_t *__restrict src, uptr maxlen);
+wchar_t *internal_wcscpy(wchar_t *__restrict dst,
+                         const wchar_t *__restrict src);
+wchar_t *internal_wcsncpy(wchar_t *__restrict dst,
+                          const wchar_t *__restrict src, uptr maxlen);
 // Return true if all bytes in [mem, mem+size) are zero.
 // Optimized for the case when the result is true.
 bool mem_is_zero(const char *mem, uptr size);
diff --git a/llvm/lib/Support/regex_impl.h b/llvm/lib/Support/regex_impl.h
index ab7a21b1d7..1d98964b9f 100644
--- a/llvm/lib/Support/regex_impl.h
+++ b/llvm/lib/Support/regex_impl.h
@@ -99,7 +99,8 @@ size_t	llvm_regerror(int, const llvm_regex_t *, char *, size_t);
 int	llvm_regexec(const llvm_regex_t *, const char *, size_t,
                      llvm_regmatch_t [], int);
 void	llvm_regfree(llvm_regex_t *);
-size_t  llvm_strlcpy(char * __restrict dst, const char *__restrict src, size_t siz);
+size_t llvm_strlcpy(char *__restrict dst, const char *__restrict src,
+                    size_t siz);
 
 #ifdef __cplusplus
 }
diff --git a/llvm/lib/Support/regstrlcpy.c b/llvm/lib/Support/regstrlcpy.c
index 1e55c4f36a..0f3b5e6517 100644
--- a/llvm/lib/Support/regstrlcpy.c
+++ b/llvm/lib/Support/regstrlcpy.c
@@ -25,28 +25,27 @@
  * will be copied.  Always NUL terminates (unless siz == 0).
  * Returns strlen(src); if retval >= siz, truncation occurred.
  */
-size_t
-llvm_strlcpy(char *__restrict dst, const char *__restrict src, size_t siz)
-{
-	char *d = dst;
-	const char *s = src;
-	size_t n = siz;
+size_t llvm_strlcpy(char *__restrict dst, const char *__restrict src,
+                    size_t siz) {
+  char *d = dst;
+  const char *s = src;
+  size_t n = siz;
 
-	/* Copy as many bytes as will fit */
-	if (n != 0) {
-		while (--n != 0) {
-			if ((*d++ = *s++) == '\0')
-				break;
-		}
-	}
+  /* Copy as many bytes as will fit */
+  if (n != 0) {
+    while (--n != 0) {
+      if ((*d++ = *s++) == '\0')
+        break;
+    }
+  }
 
-	/* Not enough room in dst, add NUL and traverse rest of src */
-	if (n == 0) {
-		if (siz != 0)
-			*d = '\0';		/* NUL-terminate dst */
-		while (*s++)
-			;
-	}
+  /* Not enough room in dst, add NUL and traverse rest of src */
+  if (n == 0) {
+    if (siz != 0)
+      *d = '\0'; /* NUL-terminate dst */
+    while (*s++)
+      ;
+  }
 
-	return(s - src - 1);	/* count does not include NUL */
+  return (s - src - 1); /* count does not include NUL */
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/78061


More information about the cfe-commits mailing list