clang  19.0.0git
ctype.h
Go to the documentation of this file.
1 //===-- Wrapper for C standard ctype.h declarations on the GPU ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__
10 #define __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__
11 
12 #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)
13 #error "This file is for GPU offloading compilation only"
14 #endif
15 
16 // The GNU headers like to define 'toupper' and 'tolower' redundantly. This is
17 // necessary to prevent it from doing that and remapping our implementation.
18 #if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__)
19 #pragma push_macro("__USE_EXTERN_INLINES")
20 #undef __USE_EXTERN_INLINES
21 #endif
22 
23 #include_next <ctype.h>
24 
25 #if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__)
26 #pragma pop_macro("__USE_EXTERN_INLINES")
27 #endif
28 
29 #if __has_include(<llvm-libc-decls/ctype.h>)
30 
31 #if defined(__HIP__) || defined(__CUDA__)
32 #define __LIBC_ATTRS __attribute__((device))
33 #endif
34 
35 // The GNU headers like to provide these as macros, we need to undefine them so
36 // they do not conflict with the following definitions for the GPU.
37 
38 #pragma push_macro("isalnum")
39 #pragma push_macro("isalpha")
40 #pragma push_macro("isascii")
41 #pragma push_macro("isblank")
42 #pragma push_macro("iscntrl")
43 #pragma push_macro("isdigit")
44 #pragma push_macro("isgraph")
45 #pragma push_macro("islower")
46 #pragma push_macro("isprint")
47 #pragma push_macro("ispunct")
48 #pragma push_macro("isspace")
49 #pragma push_macro("isupper")
50 #pragma push_macro("isxdigit")
51 #pragma push_macro("toascii")
52 #pragma push_macro("tolower")
53 #pragma push_macro("toupper")
54 
55 #undef isalnum
56 #undef isalpha
57 #undef isascii
58 #undef iscntrl
59 #undef isdigit
60 #undef islower
61 #undef isgraph
62 #undef isprint
63 #undef ispunct
64 #undef isspace
65 #undef isupper
66 #undef isblank
67 #undef isxdigit
68 #undef toascii
69 #undef tolower
70 #undef toupper
71 
72 #pragma omp begin declare target
73 
74 #include <llvm-libc-decls/ctype.h>
75 
76 #pragma omp end declare target
77 
78 // Restore the original macros when compiling on the host.
79 #if !defined(__NVPTX__) && !defined(__AMDGPU__)
80 #pragma pop_macro("isalnum")
81 #pragma pop_macro("isalpha")
82 #pragma pop_macro("isascii")
83 #pragma pop_macro("isblank")
84 #pragma pop_macro("iscntrl")
85 #pragma pop_macro("isdigit")
86 #pragma pop_macro("isgraph")
87 #pragma pop_macro("islower")
88 #pragma pop_macro("isprint")
89 #pragma pop_macro("ispunct")
90 #pragma pop_macro("isspace")
91 #pragma pop_macro("isupper")
92 #pragma pop_macro("isxdigit")
93 #pragma pop_macro("toascii")
94 #pragma pop_macro("tolower")
95 #pragma pop_macro("toupper")
96 #endif
97 
98 #undef __LIBC_ATTRS
99 
100 #endif
101 
102 #endif // __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__