166d00febSPaula Toth //===-- Common definitions for LLVM-libc public header files --------------===// 24380647eSSiva Chandra // 34380647eSSiva Chandra // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 44380647eSSiva Chandra // See https://llvm.org/LICENSE.txt for license information. 54380647eSSiva Chandra // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 64380647eSSiva Chandra // 74380647eSSiva Chandra //===----------------------------------------------------------------------===// 84380647eSSiva Chandra 9330793c9SNick Desaulniers #ifndef LLVM_LIBC_COMMON_H 10330793c9SNick Desaulniers #define LLVM_LIBC_COMMON_H 114380647eSSiva Chandra 124380647eSSiva Chandra #ifdef __cplusplus 134380647eSSiva Chandra 144380647eSSiva Chandra #undef __BEGIN_C_DECLS 154380647eSSiva Chandra #define __BEGIN_C_DECLS extern "C" { 164380647eSSiva Chandra 174380647eSSiva Chandra #undef __END_C_DECLS 184380647eSSiva Chandra #define __END_C_DECLS } 194380647eSSiva Chandra 201c602c5fSRoland McGrath // Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling. 211c602c5fSRoland McGrath #undef __restrict 221c602c5fSRoland McGrath #ifndef __GNUC__ 231c602c5fSRoland McGrath #define __restrict 241c602c5fSRoland McGrath #endif 251c602c5fSRoland McGrath 26a499d680SAlex Brachet #undef _Noreturn 27a499d680SAlex Brachet #define _Noreturn [[noreturn]] 28a499d680SAlex Brachet 2911372555SSiva Chandra Reddy #undef _Alignas 3011372555SSiva Chandra Reddy #define _Alignas alignas 3111372555SSiva Chandra Reddy 3232a50c6bSSiva Chandra Reddy #undef _Static_assert 3332a50c6bSSiva Chandra Reddy #define _Static_assert static_assert 3432a50c6bSSiva Chandra Reddy 3511372555SSiva Chandra Reddy #undef _Alignof 3611372555SSiva Chandra Reddy #define _Alignof alignof 3711372555SSiva Chandra Reddy 38dd33f9cdSSiva Chandra Reddy #undef _Thread_local 39dd33f9cdSSiva Chandra Reddy #define _Thread_local thread_local 40dd33f9cdSSiva Chandra Reddy 419b8a64b8SMichael Jones #undef __NOEXCEPT 42*a4e87da9SRoland McGrath #if __cplusplus >= 201103L 439b8a64b8SMichael Jones #define __NOEXCEPT noexcept 44*a4e87da9SRoland McGrath #else 45*a4e87da9SRoland McGrath #define __NOEXCEPT throw() 46*a4e87da9SRoland McGrath #endif 479b8a64b8SMichael Jones 484380647eSSiva Chandra #else // not __cplusplus 494380647eSSiva Chandra 504380647eSSiva Chandra #undef __BEGIN_C_DECLS 514380647eSSiva Chandra #define __BEGIN_C_DECLS 524380647eSSiva Chandra 534380647eSSiva Chandra #undef __END_C_DECLS 544380647eSSiva Chandra #define __END_C_DECLS 554380647eSSiva Chandra 564380647eSSiva Chandra #undef __restrict 57ce33a48eSRoland McGrath #if __STDC_VERSION__ >= 199901L 58ce33a48eSRoland McGrath // C99 and above support the restrict keyword. 59ce33a48eSRoland McGrath #define __restrict restrict 60ce33a48eSRoland McGrath #elif !defined(__GNUC__) 61ce33a48eSRoland McGrath // GNU-compatible compilers accept the __ spelling in all modes. 62ce33a48eSRoland McGrath // Otherwise, omit the qualifier for pure C89 compatibility. 63ce33a48eSRoland McGrath #define __restrict 64ce33a48eSRoland McGrath #endif 654380647eSSiva Chandra 664010e0c4SRoland McGrath #undef _Noreturn 674010e0c4SRoland McGrath #if __STDC_VERSION__ >= 201112L 684010e0c4SRoland McGrath // In C11 and later, _Noreturn is a keyword. 694010e0c4SRoland McGrath #elif defined(__GNUC__) 704010e0c4SRoland McGrath // GNU-compatible compilers have an equivalent attribute. 714010e0c4SRoland McGrath #define _Noreturn __attribute__((__noreturn__)) 724010e0c4SRoland McGrath #else 734010e0c4SRoland McGrath #define _Noreturn 744010e0c4SRoland McGrath #endif 754010e0c4SRoland McGrath 769b8a64b8SMichael Jones #undef __NOEXCEPT 770b91d77bSRoland McGrath #ifdef __GNUC__ 780b91d77bSRoland McGrath #define __NOEXCEPT __attribute__((__nothrow__)) 790b91d77bSRoland McGrath #else 809b8a64b8SMichael Jones #define __NOEXCEPT 810b91d77bSRoland McGrath #endif 829b8a64b8SMichael Jones 834380647eSSiva Chandra #endif // __cplusplus 844380647eSSiva Chandra 85330793c9SNick Desaulniers #endif // LLVM_LIBC_COMMON_H 86