xref: /freebsd/contrib/llvm-project/clang/lib/Headers/llvm_libc_wrappers/stdlib.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1 06c3fb27SDimitry Andric //===-- Wrapper for C standard stdlib.h declarations on the GPU -----------===//
2 06c3fb27SDimitry Andric //
3 06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5 06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 06c3fb27SDimitry Andric //
7 06c3fb27SDimitry Andric //===----------------------------------------------------------------------===//
8 06c3fb27SDimitry Andric 
9 06c3fb27SDimitry Andric #ifndef __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
10 06c3fb27SDimitry Andric #define __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
11 06c3fb27SDimitry Andric 
12 06c3fb27SDimitry Andric #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)
13 06c3fb27SDimitry Andric #error "This file is for GPU offloading compilation only"
14 06c3fb27SDimitry Andric #endif
15 06c3fb27SDimitry Andric 
16 06c3fb27SDimitry Andric #include_next <stdlib.h>
17 06c3fb27SDimitry Andric 
18 06c3fb27SDimitry Andric #if __has_include(<llvm-libc-decls/stdlib.h>)
19 06c3fb27SDimitry Andric 
20 06c3fb27SDimitry Andric #if defined(__HIP__) || defined(__CUDA__)
21 06c3fb27SDimitry Andric #define __LIBC_ATTRS __attribute__((device))
22 06c3fb27SDimitry Andric #endif
23 06c3fb27SDimitry Andric 
24 06c3fb27SDimitry Andric #pragma omp begin declare target
25 06c3fb27SDimitry Andric 
26 *5f757f3fSDimitry Andric // The LLVM C library uses these named types so we forward declare them.
27 06c3fb27SDimitry Andric typedef void (*__atexithandler_t)(void);
28 *5f757f3fSDimitry Andric typedef int (*__bsearchcompare_t)(const void *, const void *);
29 *5f757f3fSDimitry Andric typedef int (*__qsortcompare_t)(const void *, const void *);
30 *5f757f3fSDimitry Andric typedef int (*__qsortrcompare_t)(const void *, const void *, void *);
31 06c3fb27SDimitry Andric 
32 06c3fb27SDimitry Andric // Enforce ABI compatibility with the structs used by the LLVM C library.
33 06c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(div_t, quot) == 0, "ABI mismatch!");
34 06c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(ldiv_t, quot) == 0, "ABI mismatch!");
35 06c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(lldiv_t, quot) == 0, "ABI mismatch!");
36 06c3fb27SDimitry Andric 
37 06c3fb27SDimitry Andric #include <llvm-libc-decls/stdlib.h>
38 06c3fb27SDimitry Andric 
39 06c3fb27SDimitry Andric #pragma omp end declare target
40 06c3fb27SDimitry Andric 
41 06c3fb27SDimitry Andric #undef __LIBC_ATTRS
42 06c3fb27SDimitry Andric 
43 06c3fb27SDimitry Andric #endif
44 06c3fb27SDimitry Andric 
45 06c3fb27SDimitry Andric #endif // __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
46