xref: /freebsd/contrib/llvm-project/clang/lib/Headers/llvm_libc_wrappers/string.h (revision 7a6dacaca14b62ca4b74406814becb87a3fefac0)
106c3fb27SDimitry Andric //===-- Wrapper for C standard string.h declarations on the GPU -----------===//
206c3fb27SDimitry Andric //
306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
606c3fb27SDimitry Andric //
706c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
806c3fb27SDimitry Andric 
906c3fb27SDimitry Andric #ifndef __CLANG_LLVM_LIBC_WRAPPERS_STRING_H__
1006c3fb27SDimitry Andric #define __CLANG_LLVM_LIBC_WRAPPERS_STRING_H__
1106c3fb27SDimitry Andric 
1206c3fb27SDimitry Andric #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)
1306c3fb27SDimitry Andric #error "This file is for GPU offloading compilation only"
1406c3fb27SDimitry Andric #endif
1506c3fb27SDimitry Andric 
1606c3fb27SDimitry Andric #include_next <string.h>
1706c3fb27SDimitry Andric 
1806c3fb27SDimitry Andric #if __has_include(<llvm-libc-decls/string.h>)
1906c3fb27SDimitry Andric 
2006c3fb27SDimitry Andric #if defined(__HIP__) || defined(__CUDA__)
2106c3fb27SDimitry Andric #define __LIBC_ATTRS __attribute__((device))
2206c3fb27SDimitry Andric #endif
2306c3fb27SDimitry Andric 
2406c3fb27SDimitry Andric #pragma omp begin declare target
2506c3fb27SDimitry Andric 
265f757f3fSDimitry Andric // The GNU headers provide C++ standard compliant headers when in C++ mode and
275f757f3fSDimitry Andric // the LLVM libc does not. We need to manually provide the definitions using the
285f757f3fSDimitry Andric // same prototypes.
295f757f3fSDimitry Andric #if defined(__cplusplus) && defined(__GLIBC__) &&                              \
305f757f3fSDimitry Andric     defined(__CORRECT_ISO_CPP_STRING_H_PROTO)
315f757f3fSDimitry Andric 
325f757f3fSDimitry Andric #ifndef __LIBC_ATTRS
335f757f3fSDimitry Andric #define __LIBC_ATTRS
345f757f3fSDimitry Andric #endif
355f757f3fSDimitry Andric 
365f757f3fSDimitry Andric extern "C" {
375f757f3fSDimitry Andric void *memccpy(void *__restrict, const void *__restrict, int,
385f757f3fSDimitry Andric               size_t) __LIBC_ATTRS;
395f757f3fSDimitry Andric int memcmp(const void *, const void *, size_t) __LIBC_ATTRS;
405f757f3fSDimitry Andric void *memcpy(void *__restrict, const void *__restrict, size_t) __LIBC_ATTRS;
415f757f3fSDimitry Andric void *memmem(const void *, size_t, const void *, size_t) __LIBC_ATTRS;
425f757f3fSDimitry Andric void *memmove(void *, const void *, size_t) __LIBC_ATTRS;
435f757f3fSDimitry Andric void *mempcpy(void *__restrict, const void *__restrict, size_t) __LIBC_ATTRS;
445f757f3fSDimitry Andric void *memset(void *, int, size_t) __LIBC_ATTRS;
455f757f3fSDimitry Andric char *stpcpy(char *__restrict, const char *__restrict) __LIBC_ATTRS;
465f757f3fSDimitry Andric char *stpncpy(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
475f757f3fSDimitry Andric char *strcat(char *__restrict, const char *__restrict) __LIBC_ATTRS;
485f757f3fSDimitry Andric int strcmp(const char *, const char *) __LIBC_ATTRS;
495f757f3fSDimitry Andric int strcoll(const char *, const char *) __LIBC_ATTRS;
505f757f3fSDimitry Andric char *strcpy(char *__restrict, const char *__restrict) __LIBC_ATTRS;
515f757f3fSDimitry Andric size_t strcspn(const char *, const char *) __LIBC_ATTRS;
525f757f3fSDimitry Andric char *strdup(const char *) __LIBC_ATTRS;
535f757f3fSDimitry Andric size_t strlen(const char *) __LIBC_ATTRS;
54*7a6dacacSDimitry Andric char *strncat(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
555f757f3fSDimitry Andric int strncmp(const char *, const char *, size_t) __LIBC_ATTRS;
565f757f3fSDimitry Andric char *strncpy(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
575f757f3fSDimitry Andric char *strndup(const char *, size_t) __LIBC_ATTRS;
585f757f3fSDimitry Andric size_t strnlen(const char *, size_t) __LIBC_ATTRS;
595f757f3fSDimitry Andric size_t strspn(const char *, const char *) __LIBC_ATTRS;
60*7a6dacacSDimitry Andric char *strtok(char *__restrict, const char *__restrict) __LIBC_ATTRS;
615f757f3fSDimitry Andric char *strtok_r(char *__restrict, const char *__restrict,
625f757f3fSDimitry Andric                char **__restrict) __LIBC_ATTRS;
635f757f3fSDimitry Andric size_t strxfrm(char *__restrict, const char *__restrict, size_t) __LIBC_ATTRS;
645f757f3fSDimitry Andric }
655f757f3fSDimitry Andric 
665f757f3fSDimitry Andric extern "C++" {
675f757f3fSDimitry Andric char *strstr(char *, const char *) noexcept __LIBC_ATTRS;
685f757f3fSDimitry Andric const char *strstr(const char *, const char *) noexcept __LIBC_ATTRS;
695f757f3fSDimitry Andric char *strpbrk(char *, const char *) noexcept __LIBC_ATTRS;
705f757f3fSDimitry Andric const char *strpbrk(const char *, const char *) noexcept __LIBC_ATTRS;
715f757f3fSDimitry Andric char *strrchr(char *, int) noexcept __LIBC_ATTRS;
725f757f3fSDimitry Andric const char *strrchr(const char *, int) noexcept __LIBC_ATTRS;
735f757f3fSDimitry Andric char *strchr(char *, int) noexcept __LIBC_ATTRS;
745f757f3fSDimitry Andric const char *strchr(const char *, int) noexcept __LIBC_ATTRS;
755f757f3fSDimitry Andric char *strchrnul(char *, int) noexcept __LIBC_ATTRS;
765f757f3fSDimitry Andric const char *strchrnul(const char *, int) noexcept __LIBC_ATTRS;
775f757f3fSDimitry Andric char *strcasestr(char *, const char *) noexcept __LIBC_ATTRS;
785f757f3fSDimitry Andric const char *strcasestr(const char *, const char *) noexcept __LIBC_ATTRS;
795f757f3fSDimitry Andric void *memrchr(void *__s, int __c, size_t __n) noexcept __LIBC_ATTRS;
805f757f3fSDimitry Andric const void *memrchr(const void *__s, int __c, size_t __n) noexcept __LIBC_ATTRS;
815f757f3fSDimitry Andric void *memchr(void *__s, int __c, size_t __n) noexcept __LIBC_ATTRS;
825f757f3fSDimitry Andric const void *memchr(const void *__s, int __c, size_t __n) noexcept __LIBC_ATTRS;
835f757f3fSDimitry Andric }
845f757f3fSDimitry Andric 
855f757f3fSDimitry Andric #else
8606c3fb27SDimitry Andric #include <llvm-libc-decls/string.h>
8706c3fb27SDimitry Andric 
885f757f3fSDimitry Andric #endif
895f757f3fSDimitry Andric 
9006c3fb27SDimitry Andric #pragma omp end declare target
9106c3fb27SDimitry Andric 
9206c3fb27SDimitry Andric #undef __LIBC_ATTRS
9306c3fb27SDimitry Andric 
9406c3fb27SDimitry Andric #endif
9506c3fb27SDimitry Andric 
9606c3fb27SDimitry Andric #endif // __CLANG_LLVM_LIBC_WRAPPERS_STRING_H__
97