zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

stdlib.h (1706B) - Raw


      1 //===-- Wrapper for C standard stdlib.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_STDLIB_H__
     10 #define __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
     11 
     12 #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__)
     13 #error "This file is for GPU offloading compilation only"
     14 #endif
     15 
     16 #include_next <stdlib.h>
     17 
     18 #if __has_include(<llvm-libc-decls/stdlib.h>)
     19 
     20 #if defined(__HIP__) || defined(__CUDA__)
     21 #define __LIBC_ATTRS __attribute__((device))
     22 #endif
     23 
     24 #pragma omp begin declare target
     25 
     26 // The LLVM C library uses these named types so we forward declare them.
     27 typedef void (*__atexithandler_t)(void);
     28 typedef int (*__bsearchcompare_t)(const void *, const void *);
     29 typedef int (*__qsortcompare_t)(const void *, const void *);
     30 typedef int (*__qsortrcompare_t)(const void *, const void *, void *);
     31 
     32 // Enforce ABI compatibility with the structs used by the LLVM C library.
     33 _Static_assert(__builtin_offsetof(div_t, quot) == 0, "ABI mismatch!");
     34 _Static_assert(__builtin_offsetof(ldiv_t, quot) == 0, "ABI mismatch!");
     35 _Static_assert(__builtin_offsetof(lldiv_t, quot) == 0, "ABI mismatch!");
     36 
     37 #if defined(__GLIBC__) && __cplusplus >= 201703L
     38 #define at_quick_exit atexit
     39 #endif
     40 
     41 #include <llvm-libc-decls/stdlib.h>
     42 
     43 #if defined(__GLIBC__) && __cplusplus >= 201703L
     44 #undef at_quick_exit
     45 #endif
     46 
     47 #pragma omp end declare target
     48 
     49 #undef __LIBC_ATTRS
     50 
     51 #endif
     52 
     53 #endif // __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__