[libc++] Use builtins when redeclaring <string.h> functions

When we define the const-correct overloads of <string.h> functions in
libc++ itself, use builtins whenever possible. This avoids depending on
the presence of these functions in the C library headers.

Also, as a fly-by, improve the tests for these functions since we
basically didn't check anything but their signature. We could have
used the wrong builtin (as long as the signature matched) without ever
noticing, which was quite scary.

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

NOKEYCHECK=True
GitOrigin-RevId: f62d4135c5cd1ec0656d097be0931021de8b7ae9
diff --git a/include/string.h b/include/string.h
index 627cbae..3ec877b 100644
--- a/include/string.h
+++ b/include/string.h
@@ -71,41 +71,41 @@
 
 #if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && defined(_LIBCPP_PREFERRED_OVERLOAD)
 extern "C++" {
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strpbrk(const char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strpbrk(      char* __s1, const char* __s2) {return __libcpp_strpbrk(__s1, __s2);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strrchr(const char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strrchr(      char* __s, int __c) {return __libcpp_strrchr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
-
-inline _LIBCPP_INLINE_VISIBILITY
-char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-const char* strstr(const char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD
-      char* strstr(      char* __s1, const char* __s2) {return __libcpp_strstr(__s1, __s2);}
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strchr(const char* __s, int __c) {
+  return __builtin_strchr(__s, __c);
 }
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strchr(char* __s, int __c) {
+  return __builtin_strchr(__s, __c);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strpbrk(const char* __s1, const char* __s2) {
+  return __builtin_strpbrk(__s1, __s2);
+}
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strpbrk(char* __s1, const char* __s2) {
+  return __builtin_strpbrk(__s1, __s2);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strrchr(const char* __s, int __c) {
+  return __builtin_strrchr(__s, __c);
+}
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strrchr(char* __s, int __c) {
+  return __builtin_strrchr(__s, __c);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
+  return __builtin_memchr(__s, __c, __n);
+}
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
+  return __builtin_memchr(__s, __c, __n);
+}
+
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const char* strstr(const char* __s1, const char* __s2) {
+  return __builtin_strstr(__s1, __s2);
+}
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD char* strstr(char* __s1, const char* __s2) {
+  return __builtin_strstr(__s1, __s2);
+}
+} // extern "C++"
 #endif
 
 #endif // _LIBCPP_STRING_H