103 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LLVM_LIBC_COMMON_H10#define _LLVM_LIBC_COMMON_H11 12#define __LLVM_LIBC__ 113 14#ifdef __cplusplus15 16#undef __BEGIN_C_DECLS17#define __BEGIN_C_DECLS extern "C" {18 19#undef __END_C_DECLS20#define __END_C_DECLS }21 22// Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling.23#undef __restrict24#ifndef __GNUC__25#define __restrict26#endif27 28#undef _Noreturn29#define _Noreturn [[noreturn]]30 31#undef _Alignas32#define _Alignas alignas33 34#undef _Static_assert35#define _Static_assert static_assert36 37#undef _Alignof38#define _Alignof alignof39 40#undef __NOEXCEPT41#if __cplusplus >= 201103L42#define __NOEXCEPT noexcept43#else44#define __NOEXCEPT throw()45#endif46 47#undef _Returns_twice48#if __cplusplus >= 201103L49#define _Returns_twice [[gnu::returns_twice]]50#else51#define _Returns_twice __attribute__((returns_twice))52#endif53 54// This macro serves as a generic cast implementation for use in both C and C++,55// similar to `__BIONIC_CAST` in Android.56#undef __LLVM_LIBC_CAST57#define __LLVM_LIBC_CAST(cast, type, value) (cast<type>(value))58 59#else // not __cplusplus60 61#undef __BEGIN_C_DECLS62#define __BEGIN_C_DECLS63 64#undef __END_C_DECLS65#define __END_C_DECLS66 67#undef __restrict68#if __STDC_VERSION__ >= 199901L69// C99 and above support the restrict keyword.70#define __restrict restrict71#elif !defined(__GNUC__)72// GNU-compatible compilers accept the __ spelling in all modes.73// Otherwise, omit the qualifier for pure C89 compatibility.74#define __restrict75#endif76 77#undef _Noreturn78#if __STDC_VERSION__ >= 201112L79// In C11 and later, _Noreturn is a keyword.80#elif defined(__GNUC__)81// GNU-compatible compilers have an equivalent attribute.82#define _Noreturn __attribute__((__noreturn__))83#else84#define _Noreturn85#endif86 87#undef __NOEXCEPT88#ifdef __GNUC__89#define __NOEXCEPT __attribute__((__nothrow__))90#else91#define __NOEXCEPT92#endif93 94#undef _Returns_twice95#define _Returns_twice __attribute__((returns_twice))96 97#undef __LLVM_LIBC_CAST98#define __LLVM_LIBC_CAST(cast, type, value) ((type)(value))99 100#endif // __cplusplus101 102#endif // _LLVM_LIBC_COMMON_H103