1*bb722a7dSDimitry Andric //===-- Portable attributes -------------------------------------*- C++ -*-===// 2*bb722a7dSDimitry Andric // 3*bb722a7dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*bb722a7dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*bb722a7dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*bb722a7dSDimitry Andric // 7*bb722a7dSDimitry Andric //===----------------------------------------------------------------------===// 8*bb722a7dSDimitry Andric // This header file defines a set of macros for checking the presence of 9*bb722a7dSDimitry Andric // important compiler and platform features. Such macros can be used to 10*bb722a7dSDimitry Andric // produce portable code by parameterizing compilation based on the presence or 11*bb722a7dSDimitry Andric // lack of a given feature. 12*bb722a7dSDimitry Andric 13*bb722a7dSDimitry Andric #ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H 14*bb722a7dSDimitry Andric #define LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H 15*bb722a7dSDimitry Andric 16*bb722a7dSDimitry Andric // Workaround for compilers that do not support builtin detection. 17*bb722a7dSDimitry Andric // FIXME: This is only required for the GPU portion which should be moved. 18*bb722a7dSDimitry Andric #ifndef __has_builtin 19*bb722a7dSDimitry Andric #define __has_builtin(b) 0 20*bb722a7dSDimitry Andric #endif 21*bb722a7dSDimitry Andric 22*bb722a7dSDimitry Andric // Compiler feature-detection. 23*bb722a7dSDimitry Andric // clang.llvm.org/docs/LanguageExtensions.html#has-feature-and-has-extension 24*bb722a7dSDimitry Andric #ifdef __has_feature 25*bb722a7dSDimitry Andric #define LIBC_HAS_FEATURE(f) __has_feature(f) 26*bb722a7dSDimitry Andric #else 27*bb722a7dSDimitry Andric #define LIBC_HAS_FEATURE(f) 0 28*bb722a7dSDimitry Andric #endif 29*bb722a7dSDimitry Andric 30*bb722a7dSDimitry Andric #ifdef __clang__ 31*bb722a7dSDimitry Andric // Declare a LIBC_NAMESPACE with hidden visibility. `namespace 32*bb722a7dSDimitry Andric // LIBC_NAMESPACE_DECL {` should be used around all declarations and definitions 33*bb722a7dSDimitry Andric // for libc internals as opposed to just `namespace LIBC_NAMESPACE {`. This 34*bb722a7dSDimitry Andric // ensures that all declarations within this namespace have hidden 35*bb722a7dSDimitry Andric // visibility, which optimizes codegen for uses of symbols defined in other 36*bb722a7dSDimitry Andric // translation units in ways that can be necessary for correctness by avoiding 37*bb722a7dSDimitry Andric // dynamic relocations. This does not affect the public C symbols which are 38*bb722a7dSDimitry Andric // controlled independently via `LLVM_LIBC_FUNCTION_ATTR`. 39*bb722a7dSDimitry Andric #define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] LIBC_NAMESPACE 40*bb722a7dSDimitry Andric #else 41*bb722a7dSDimitry Andric // TODO(#98548): GCC emits a warning when using the visibility attribute which 42*bb722a7dSDimitry Andric // needs to be diagnosed and addressed. 43*bb722a7dSDimitry Andric #define LIBC_NAMESPACE_DECL LIBC_NAMESPACE 44*bb722a7dSDimitry Andric #endif 45*bb722a7dSDimitry Andric 46*bb722a7dSDimitry Andric #endif // LLVM_LIBC_SRC___SUPPORT_MACROS_CONFIG_H 47