Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- Common definitions for LLVM-libc public header files --------------===//
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 _LLVM_LIBC_COMMON_H
10#define _LLVM_LIBC_COMMON_H
11
12#define __LLVM_LIBC__ 1
13
14#ifdef __cplusplus
15
16#undef __BEGIN_C_DECLS
17#define __BEGIN_C_DECLS extern "C" {
18
19#undef __END_C_DECLS
20#define __END_C_DECLS }
21
22// Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling.
23#undef __restrict
24#ifndef __GNUC__
25#define __restrict
26#endif
27
28#undef _Noreturn
29#define _Noreturn [[noreturn]]
30
31#undef _Alignas
32#define _Alignas alignas
33
34#undef _Static_assert
35#define _Static_assert static_assert
36
37#undef _Alignof
38#define _Alignof alignof
39
40#undef _Thread_local
41#define _Thread_local thread_local
42
43#undef __NOEXCEPT
44#if __cplusplus >= 201103L
45#define __NOEXCEPT noexcept
46#else
47#define __NOEXCEPT throw()
48#endif
49
50// This macro serves as a generic cast implementation for use in both C and C++,
51// similar to `__BIONIC_CAST` in Android.
52#undef __LLVM_LIBC_CAST
53#define __LLVM_LIBC_CAST(cast, type, value) (cast<type>(value))
54
55#else // not __cplusplus
56
57#undef __BEGIN_C_DECLS
58#define __BEGIN_C_DECLS
59
60#undef __END_C_DECLS
61#define __END_C_DECLS
62
63#undef __restrict
64#if __STDC_VERSION__ >= 199901L
65// C99 and above support the restrict keyword.
66#define __restrict restrict
67#elif !defined(__GNUC__)
68// GNU-compatible compilers accept the __ spelling in all modes.
69// Otherwise, omit the qualifier for pure C89 compatibility.
70#define __restrict
71#endif
72
73#undef _Noreturn
74#if __STDC_VERSION__ >= 201112L
75// In C11 and later, _Noreturn is a keyword.
76#elif defined(__GNUC__)
77// GNU-compatible compilers have an equivalent attribute.
78#define _Noreturn __attribute__((__noreturn__))
79#else
80#define _Noreturn
81#endif
82
83#undef __NOEXCEPT
84#ifdef __GNUC__
85#define __NOEXCEPT __attribute__((__nothrow__))
86#else
87#define __NOEXCEPT
88#endif
89
90#undef _Returns_twice
91#define _Returns_twice __attribute__((returns_twice))
92
93#undef __LLVM_LIBC_CAST
94#define __LLVM_LIBC_CAST(cast, type, value) ((type)(value))
95
96#endif // __cplusplus
97
98#endif // _LLVM_LIBC_COMMON_H
99

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libc/include/__llvm-libc-common.h