95 lines · c
1//===-- Portable attributes -------------------------------------*- C++ -*-===//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// This header file defines macros for declaring attributes for functions,9// types, and variables.10//11// These macros are used within llvm-libc and allow the compiler to optimize,12// where applicable, certain function calls.13//14// Most macros here are exposing GCC or Clang features, and are stubbed out for15// other compilers.16 17#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H18#define LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H19 20#include "config.h"21#include "properties/architectures.h"22 23#ifndef __has_attribute24#define __has_attribute(x) 025#endif26 27#define LIBC_INLINE inline28#define LIBC_INLINE_VAR inline29#define LIBC_INLINE_ASM __asm__ __volatile__30#define LIBC_UNUSED __attribute__((unused))31 32// Uses the platform specific specialization33#define LIBC_THREAD_MODE_PLATFORM 034 35// Mutex guards nothing, used in single-threaded implementations36#define LIBC_THREAD_MODE_SINGLE 137 38// Vendor provides implementation39#define LIBC_THREAD_MODE_EXTERNAL 240 41// libcxx doesn't define LIBC_THREAD_MODE, unless that is passed in the command42// line in the CMake invocation. This defaults to the original implementation43// (before changes in https://github.com/llvm/llvm-project/pull/145358)44#ifndef LIBC_THREAD_MODE45#define LIBC_THREAD_MODE LIBC_THREAD_MODE_PLATFORM46#endif // LIBC_THREAD_MODE47 48#if LIBC_THREAD_MODE != LIBC_THREAD_MODE_PLATFORM && \49 LIBC_THREAD_MODE != LIBC_THREAD_MODE_SINGLE && \50 LIBC_THREAD_MODE != LIBC_THREAD_MODE_EXTERNAL51#error LIBC_THREAD_MODE must be one of the following values: \52LIBC_THREAD_MODE_PLATFORM, \53LIBC_THREAD_MODE_SINGLE, \54LIBC_THREAD_MODE_EXTERNAL.55#endif56 57#if LIBC_THREAD_MODE == LIBC_THREAD_MODE_SINGLE58#define LIBC_THREAD_LOCAL59#else60#define LIBC_THREAD_LOCAL thread_local61#endif62 63#if __cplusplus >= 202002L64#define LIBC_CONSTINIT constinit65#elif __has_attribute(__require_constant_initialization__)66#define LIBC_CONSTINIT __attribute__((__require_constant_initialization__))67#else68#define LIBC_CONSTINIT69#endif70 71#if defined(__clang__) && __has_attribute(preferred_type)72#define LIBC_PREFERED_TYPE(TYPE) [[clang::preferred_type(TYPE)]]73#else74#define LIBC_PREFERED_TYPE(TYPE)75#endif76 77#if __has_attribute(ext_vector_type) && \78 LIBC_HAS_FEATURE(ext_vector_type_boolean)79#define LIBC_HAS_VECTOR_TYPE 180#else81#define LIBC_HAS_VECTOR_TYPE 082#endif83 84#if __has_attribute(no_sanitize)85// Disable regular and hardware-supported ASan for functions that may86// intentionally make out-of-bounds access. Disable TSan as well, as it detects87// out-of-bounds accesses to heap memory.88#define LIBC_NO_SANITIZE_OOB_ACCESS \89 __attribute__((no_sanitize("address", "hwaddress", "thread")))90#else91#define LIBC_NO_SANITIZE_OOB_ACCESS92#endif93 94#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_ATTRIBUTES_H95