Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:29

0001 //===-- llvm/Support/Compiler.h - Compiler abstraction support --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines several macros, based on the current compiler.  This allows
0010 // use of compiler-specific features in a way that remains portable. This header
0011 // can be included from either C or C++.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_SUPPORT_COMPILER_H
0016 #define LLVM_SUPPORT_COMPILER_H
0017 
0018 #include "llvm/Config/llvm-config.h"
0019 
0020 #include <stddef.h>
0021 
0022 #if defined(_MSC_VER)
0023 #include <sal.h>
0024 #endif
0025 
0026 #ifndef __has_feature
0027 # define __has_feature(x) 0
0028 #endif
0029 
0030 #ifndef __has_extension
0031 # define __has_extension(x) 0
0032 #endif
0033 
0034 #ifndef __has_attribute
0035 # define __has_attribute(x) 0
0036 #endif
0037 
0038 #ifndef __has_builtin
0039 # define __has_builtin(x) 0
0040 #endif
0041 
0042 // Only use __has_cpp_attribute in C++ mode. GCC defines __has_cpp_attribute in
0043 // C mode, but the :: in __has_cpp_attribute(scoped::attribute) is invalid.
0044 #ifndef LLVM_HAS_CPP_ATTRIBUTE
0045 #if defined(__cplusplus) && defined(__has_cpp_attribute)
0046 # define LLVM_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
0047 #else
0048 # define LLVM_HAS_CPP_ATTRIBUTE(x) 0
0049 #endif
0050 #endif
0051 
0052 /// \macro LLVM_GNUC_PREREQ
0053 /// Extend the default __GNUC_PREREQ even if glibc's features.h isn't
0054 /// available.
0055 #ifndef LLVM_GNUC_PREREQ
0056 # if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
0057 #  define LLVM_GNUC_PREREQ(maj, min, patch) \
0058     ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
0059      ((maj) << 20) + ((min) << 10) + (patch))
0060 # elif defined(__GNUC__) && defined(__GNUC_MINOR__)
0061 #  define LLVM_GNUC_PREREQ(maj, min, patch) \
0062     ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
0063 # else
0064 #  define LLVM_GNUC_PREREQ(maj, min, patch) 0
0065 # endif
0066 #endif
0067 
0068 /// \macro LLVM_MSC_PREREQ
0069 /// Is the compiler MSVC of at least the specified version?
0070 /// The common \param version values to check for are:
0071 /// * 1910: VS2017, version 15.1 & 15.2
0072 /// * 1911: VS2017, version 15.3 & 15.4
0073 /// * 1912: VS2017, version 15.5
0074 /// * 1913: VS2017, version 15.6
0075 /// * 1914: VS2017, version 15.7
0076 /// * 1915: VS2017, version 15.8
0077 /// * 1916: VS2017, version 15.9
0078 /// * 1920: VS2019, version 16.0
0079 /// * 1921: VS2019, version 16.1
0080 /// * 1922: VS2019, version 16.2
0081 /// * 1923: VS2019, version 16.3
0082 /// * 1924: VS2019, version 16.4
0083 /// * 1925: VS2019, version 16.5
0084 /// * 1926: VS2019, version 16.6
0085 /// * 1927: VS2019, version 16.7
0086 /// * 1928: VS2019, version 16.8 + 16.9
0087 /// * 1929: VS2019, version 16.10 + 16.11
0088 /// * 1930: VS2022, version 17.0
0089 #ifdef _MSC_VER
0090 #define LLVM_MSC_PREREQ(version) (_MSC_VER >= (version))
0091 
0092 // We require at least VS 2019.
0093 #if !defined(LLVM_FORCE_USE_OLD_TOOLCHAIN)
0094 #if !LLVM_MSC_PREREQ(1920)
0095 #error LLVM requires at least VS 2019.
0096 #endif
0097 #endif
0098 
0099 #else
0100 #define LLVM_MSC_PREREQ(version) 0
0101 #endif
0102 
0103 /// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked
0104 /// into a shared library, then the class should be private to the library and
0105 /// not accessible from outside it.  Can also be used to mark variables and
0106 /// functions, making them private to any shared library they are linked into.
0107 /// On PE/COFF targets, library visibility is the default, so this isn't needed.
0108 ///
0109 /// LLVM_EXTERNAL_VISIBILITY - classes, functions, and variables marked with
0110 /// this attribute will be made public and visible outside of any shared library
0111 /// they are linked in to.
0112 
0113 #if LLVM_HAS_CPP_ATTRIBUTE(gnu::visibility) && defined(__GNUC__) &&            \
0114     !defined(__clang__)
0115 #define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN [[gnu::visibility("hidden")]]
0116 #define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT [[gnu::visibility("default")]]
0117 #elif __has_attribute(visibility)
0118 #define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
0119 #define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT __attribute__((visibility("default")))
0120 #else
0121 #define LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
0122 #define LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0123 #endif
0124 
0125 #if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS)
0126 #define LLVM_EXTERNAL_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0127 #else
0128 #define LLVM_EXTERNAL_VISIBILITY
0129 #endif
0130 
0131 #if (!(defined(_WIN32) || defined(__CYGWIN__)) ||                              \
0132      (defined(__MINGW32__) && defined(__clang__)))
0133 #define LLVM_LIBRARY_VISIBILITY LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
0134 // Clang compilers older then 15 do not support gnu style attributes on
0135 // namespaces.
0136 #if defined(__clang__) && __clang_major__ < 15
0137 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE [[gnu::visibility("hidden")]]
0138 #else
0139 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE LLVM_ATTRIBUTE_VISIBILITY_HIDDEN
0140 #endif
0141 #define LLVM_ALWAYS_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0142 #elif defined(_WIN32)
0143 #define LLVM_ALWAYS_EXPORT __declspec(dllexport)
0144 #define LLVM_LIBRARY_VISIBILITY
0145 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE
0146 #else
0147 #define LLVM_LIBRARY_VISIBILITY
0148 #define LLVM_ALWAYS_EXPORT
0149 #define LLVM_LIBRARY_VISIBILITY_NAMESPACE
0150 #endif
0151 
0152 /// LLVM_ABI is the main export/visibility macro to mark something as explicitly
0153 /// exported when llvm is built as a shared library with everything else that is
0154 /// unannotated will have internal visibility.
0155 ///
0156 /// LLVM_ABI_EXPORT is for the special case for things like plugin symbol
0157 /// declarations or definitions where we don't want the macro to be switching
0158 /// between dllexport and dllimport on windows based on what codebase is being
0159 /// built, it will only be dllexport. For non windows platforms this macro
0160 /// behaves the same as LLVM_ABI.
0161 ///
0162 /// LLVM_EXPORT_TEMPLATE is used on explicit template instantiations in source
0163 /// files that were declared extern in a header. This macro is only set as a
0164 /// compiler export attribute on windows, on other platforms it does nothing.
0165 ///
0166 /// LLVM_TEMPLATE_ABI is for annotating extern template declarations in headers
0167 /// for both functions and classes. On windows its turned in to dllimport for
0168 /// library consumers, for other platforms its a default visibility attribute.
0169 ///
0170 /// LLVM_C_ABI is used to annotated functions and data that need to be exported
0171 /// for the libllvm-c API. This used both for the llvm-c headers and for the
0172 /// functions declared in the different Target's c++ source files that don't
0173 /// include the header forward declaring them.
0174 #ifndef LLVM_ABI_GENERATING_ANNOTATIONS
0175 // Marker to add to classes or functions in public headers that should not have
0176 // export macros added to them by the clang tool
0177 #define LLVM_ABI_NOT_EXPORTED
0178 #if defined(LLVM_BUILD_LLVM_DYLIB) || defined(LLVM_BUILD_SHARED_LIBS) ||       \
0179     defined(LLVM_ENABLE_PLUGINS)
0180 // Some libraries like those for tablegen are linked in to tools that used
0181 // in the build so can't depend on the llvm shared library. If export macros
0182 // were left enabled when building these we would get duplicate or
0183 // missing symbol linker errors on windows.
0184 #if defined(LLVM_BUILD_STATIC)
0185 #define LLVM_ABI
0186 #define LLVM_TEMPLATE_ABI
0187 #define LLVM_EXPORT_TEMPLATE
0188 #define LLVM_ABI_EXPORT
0189 #elif defined(_WIN32) && !defined(__MINGW32__)
0190 #if defined(LLVM_EXPORTS)
0191 #define LLVM_ABI __declspec(dllexport)
0192 #define LLVM_TEMPLATE_ABI
0193 #define LLVM_EXPORT_TEMPLATE __declspec(dllexport)
0194 #else
0195 #define LLVM_ABI __declspec(dllimport)
0196 #define LLVM_TEMPLATE_ABI __declspec(dllimport)
0197 #define LLVM_EXPORT_TEMPLATE
0198 #endif
0199 #define LLVM_ABI_EXPORT __declspec(dllexport)
0200 #elif defined(__ELF__) || defined(__MINGW32__) || defined(_AIX) ||             \
0201     defined(__MVS__)
0202 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0203 #define LLVM_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0204 #define LLVM_EXPORT_TEMPLATE
0205 #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0206 #elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
0207 #define LLVM_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0208 #define LLVM_TEMPLATE_ABI
0209 #define LLVM_EXPORT_TEMPLATE
0210 #define LLVM_ABI_EXPORT LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
0211 #endif
0212 #else
0213 #define LLVM_ABI
0214 #define LLVM_TEMPLATE_ABI
0215 #define LLVM_EXPORT_TEMPLATE
0216 #define LLVM_ABI_EXPORT
0217 #endif
0218 #define LLVM_C_ABI LLVM_ABI
0219 #endif
0220 
0221 #if defined(__GNUC__)
0222 #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
0223 #else
0224 #define LLVM_PREFETCH(addr, rw, locality)
0225 #endif
0226 
0227 #if __has_attribute(used)
0228 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
0229 #else
0230 #define LLVM_ATTRIBUTE_USED
0231 #endif
0232 
0233 #if defined(__clang__)
0234 #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
0235 #else
0236 #define LLVM_DEPRECATED(MSG, FIX) [[deprecated(MSG)]]
0237 #endif
0238 
0239 // clang-format off
0240 #if defined(__clang__) || defined(__GNUC__)
0241 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH                             \
0242   _Pragma("GCC diagnostic push")                                               \
0243   _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0244 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP                              \
0245   _Pragma("GCC diagnostic pop")
0246 #elif defined(_MSC_VER)
0247 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH                             \
0248   _Pragma("warning(push)")                                                     \
0249   _Pragma("warning(disable : 4996)")
0250 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP                              \
0251   _Pragma("warning(pop)")
0252 #else
0253 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
0254 #define LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
0255 #endif
0256 // clang-format on
0257 
0258 // Indicate that a non-static, non-const C++ member function reinitializes
0259 // the entire object to a known state, independent of the previous state of
0260 // the object.
0261 //
0262 // The clang-tidy check bugprone-use-after-move recognizes this attribute as a
0263 // marker that a moved-from object has left the indeterminate state and can be
0264 // reused.
0265 #if LLVM_HAS_CPP_ATTRIBUTE(clang::reinitializes)
0266 #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]]
0267 #else
0268 #define LLVM_ATTRIBUTE_REINITIALIZES
0269 #endif
0270 
0271 // Some compilers warn about unused functions. When a function is sometimes
0272 // used or not depending on build settings (e.g. a function only called from
0273 // within "assert"), this attribute can be used to suppress such warnings.
0274 //
0275 // However, it shouldn't be used for unused *variables*, as those have a much
0276 // more portable solution:
0277 //   (void)unused_var_name;
0278 // Prefer cast-to-void wherever it is sufficient.
0279 #if __has_attribute(unused)
0280 #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__))
0281 #else
0282 #define LLVM_ATTRIBUTE_UNUSED
0283 #endif
0284 
0285 // FIXME: Provide this for PE/COFF targets.
0286 #if __has_attribute(weak) && !defined(__MINGW32__) && !defined(__CYGWIN__) &&  \
0287     !defined(_WIN32)
0288 #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__))
0289 #else
0290 #define LLVM_ATTRIBUTE_WEAK
0291 #endif
0292 
0293 // Prior to clang 3.2, clang did not accept any spelling of
0294 // __has_attribute(const), so assume it is supported.
0295 #if defined(__clang__) || defined(__GNUC__)
0296 // aka 'CONST' but following LLVM Conventions.
0297 #define LLVM_READNONE __attribute__((__const__))
0298 #else
0299 #define LLVM_READNONE
0300 #endif
0301 
0302 #if __has_attribute(pure) || defined(__GNUC__)
0303 // aka 'PURE' but following LLVM Conventions.
0304 #define LLVM_READONLY __attribute__((__pure__))
0305 #else
0306 #define LLVM_READONLY
0307 #endif
0308 
0309 #if __has_attribute(minsize)
0310 #define LLVM_ATTRIBUTE_MINSIZE __attribute__((minsize))
0311 #else
0312 #define LLVM_ATTRIBUTE_MINSIZE
0313 #endif
0314 
0315 #if __has_builtin(__builtin_expect) || defined(__GNUC__)
0316 #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
0317 #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
0318 #else
0319 #define LLVM_LIKELY(EXPR) (EXPR)
0320 #define LLVM_UNLIKELY(EXPR) (EXPR)
0321 #endif
0322 
0323 /// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so,
0324 /// mark a method "not for inlining".
0325 #if __has_attribute(noinline)
0326 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
0327 #elif defined(_MSC_VER)
0328 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
0329 #else
0330 #define LLVM_ATTRIBUTE_NOINLINE
0331 #endif
0332 
0333 /// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do
0334 /// so, mark a method "always inline" because it is performance sensitive.
0335 #if __has_attribute(always_inline)
0336 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline __attribute__((always_inline))
0337 #elif defined(_MSC_VER)
0338 #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline
0339 #else
0340 #define LLVM_ATTRIBUTE_ALWAYS_INLINE inline
0341 #endif
0342 
0343 /// LLVM_ATTRIBUTE_NO_DEBUG - On compilers where we have a directive to do
0344 /// so, mark a method "no debug" because debug info makes the debugger
0345 /// experience worse.
0346 #if __has_attribute(nodebug)
0347 #define LLVM_ATTRIBUTE_NODEBUG __attribute__((nodebug))
0348 #else
0349 #define LLVM_ATTRIBUTE_NODEBUG
0350 #endif
0351 
0352 #if __has_attribute(returns_nonnull)
0353 #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull))
0354 #elif defined(_MSC_VER)
0355 #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_
0356 #else
0357 #define LLVM_ATTRIBUTE_RETURNS_NONNULL
0358 #endif
0359 
0360 /// LLVM_ATTRIBUTE_RESTRICT - Annotates a pointer to tell the compiler that
0361 /// it is not aliased in the current scope.
0362 #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
0363 #define LLVM_ATTRIBUTE_RESTRICT __restrict
0364 #else
0365 #define LLVM_ATTRIBUTE_RESTRICT
0366 #endif
0367 
0368 /// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a
0369 /// pointer that does not alias any other valid pointer.
0370 #ifdef __GNUC__
0371 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
0372 #elif defined(_MSC_VER)
0373 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
0374 #else
0375 #define LLVM_ATTRIBUTE_RETURNS_NOALIAS
0376 #endif
0377 
0378 /// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
0379 #if defined(__cplusplus) && __cplusplus > 201402L && LLVM_HAS_CPP_ATTRIBUTE(fallthrough)
0380 #define LLVM_FALLTHROUGH [[fallthrough]]
0381 #elif LLVM_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
0382 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
0383 #elif __has_attribute(fallthrough)
0384 #define LLVM_FALLTHROUGH __attribute__((fallthrough))
0385 #elif LLVM_HAS_CPP_ATTRIBUTE(clang::fallthrough)
0386 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
0387 #else
0388 #define LLVM_FALLTHROUGH
0389 #endif
0390 
0391 /// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that
0392 /// they are constant initialized.
0393 #if LLVM_HAS_CPP_ATTRIBUTE(clang::require_constant_initialization)
0394 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION                                   \
0395   [[clang::require_constant_initialization]]
0396 #else
0397 #define LLVM_REQUIRE_CONSTANT_INITIALIZATION
0398 #endif
0399 
0400 /// LLVM_GSL_OWNER - Apply this to owning classes like SmallVector to enable
0401 /// lifetime warnings.
0402 #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Owner)
0403 #define LLVM_GSL_OWNER [[gsl::Owner]]
0404 #else
0405 #define LLVM_GSL_OWNER
0406 #endif
0407 
0408 /// LLVM_GSL_POINTER - Apply this to non-owning classes like
0409 /// StringRef to enable lifetime warnings.
0410 #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer)
0411 #define LLVM_GSL_POINTER [[gsl::Pointer]]
0412 #else
0413 #define LLVM_GSL_POINTER
0414 #endif
0415 
0416 #if LLVM_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
0417 #define LLVM_LIFETIME_BOUND [[clang::lifetimebound]]
0418 #else
0419 #define LLVM_LIFETIME_BOUND
0420 #endif
0421 
0422 #if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
0423 #define LLVM_CTOR_NODISCARD [[nodiscard]]
0424 #else
0425 #define LLVM_CTOR_NODISCARD
0426 #endif
0427 
0428 /// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
0429 /// pedantic diagnostics.
0430 #ifdef __GNUC__
0431 #define LLVM_EXTENSION __extension__
0432 #else
0433 #define LLVM_EXTENSION
0434 #endif
0435 
0436 /// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
0437 /// to an expression which states that it is undefined behavior for the
0438 /// compiler to reach this point.  Otherwise is not defined.
0439 ///
0440 /// '#else' is intentionally left out so that other macro logic (e.g.,
0441 /// LLVM_ASSUME_ALIGNED and llvm_unreachable()) can detect whether
0442 /// LLVM_BUILTIN_UNREACHABLE has a definition.
0443 #if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
0444 # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
0445 #elif defined(_MSC_VER)
0446 # define LLVM_BUILTIN_UNREACHABLE __assume(false)
0447 #endif
0448 
0449 /// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression
0450 /// which causes the program to exit abnormally.
0451 #if __has_builtin(__builtin_trap) || defined(__GNUC__)
0452 # define LLVM_BUILTIN_TRAP __builtin_trap()
0453 #elif defined(_MSC_VER)
0454 // The __debugbreak intrinsic is supported by MSVC, does not require forward
0455 // declarations involving platform-specific typedefs (unlike RaiseException),
0456 // results in a call to vectored exception handlers, and encodes to a short
0457 // instruction that still causes the trapping behavior we want.
0458 # define LLVM_BUILTIN_TRAP __debugbreak()
0459 #else
0460 # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0
0461 #endif
0462 
0463 /// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to
0464 /// an expression which causes the program to break while running
0465 /// under a debugger.
0466 #if __has_builtin(__builtin_debugtrap)
0467 # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap()
0468 #elif defined(_MSC_VER)
0469 // The __debugbreak intrinsic is supported by MSVC and breaks while
0470 // running under the debugger, and also supports invoking a debugger
0471 // when the OS is configured appropriately.
0472 # define LLVM_BUILTIN_DEBUGTRAP __debugbreak()
0473 #else
0474 // Just continue execution when built with compilers that have no
0475 // support. This is a debugging aid and not intended to force the
0476 // program to abort if encountered.
0477 # define LLVM_BUILTIN_DEBUGTRAP
0478 #endif
0479 
0480 /// \macro LLVM_ASSUME_ALIGNED
0481 /// Returns a pointer with an assumed alignment.
0482 #if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__)
0483 # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a)
0484 #elif defined(LLVM_BUILTIN_UNREACHABLE)
0485 # define LLVM_ASSUME_ALIGNED(p, a) \
0486            (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE, (p)))
0487 #else
0488 # define LLVM_ASSUME_ALIGNED(p, a) (p)
0489 #endif
0490 
0491 /// \macro LLVM_PACKED
0492 /// Used to specify a packed structure.
0493 /// LLVM_PACKED(
0494 ///    struct A {
0495 ///      int i;
0496 ///      int j;
0497 ///      int k;
0498 ///      long long l;
0499 ///   });
0500 ///
0501 /// LLVM_PACKED_START
0502 /// struct B {
0503 ///   int i;
0504 ///   int j;
0505 ///   int k;
0506 ///   long long l;
0507 /// };
0508 /// LLVM_PACKED_END
0509 #ifdef _MSC_VER
0510 # define LLVM_PACKED(d) __pragma(pack(push, 1)) d __pragma(pack(pop))
0511 # define LLVM_PACKED_START __pragma(pack(push, 1))
0512 # define LLVM_PACKED_END   __pragma(pack(pop))
0513 #else
0514 # define LLVM_PACKED(d) d __attribute__((packed))
0515 # define LLVM_PACKED_START _Pragma("pack(push, 1)")
0516 # define LLVM_PACKED_END   _Pragma("pack(pop)")
0517 #endif
0518 
0519 /// \macro LLVM_MEMORY_SANITIZER_BUILD
0520 /// Whether LLVM itself is built with MemorySanitizer instrumentation.
0521 #if __has_feature(memory_sanitizer)
0522 # define LLVM_MEMORY_SANITIZER_BUILD 1
0523 # include <sanitizer/msan_interface.h>
0524 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE __attribute__((no_sanitize_memory))
0525 #else
0526 # define LLVM_MEMORY_SANITIZER_BUILD 0
0527 # define __msan_allocated_memory(p, size)
0528 # define __msan_unpoison(p, size)
0529 # define LLVM_NO_SANITIZE_MEMORY_ATTRIBUTE
0530 #endif
0531 
0532 /// \macro LLVM_ADDRESS_SANITIZER_BUILD
0533 /// Whether LLVM itself is built with AddressSanitizer instrumentation.
0534 #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
0535 # define LLVM_ADDRESS_SANITIZER_BUILD 1
0536 #if __has_include(<sanitizer/asan_interface.h>)
0537 # include <sanitizer/asan_interface.h>
0538 #else
0539 // These declarations exist to support ASan with MSVC. If MSVC eventually ships
0540 // asan_interface.h in their headers, then we can remove this.
0541 #ifdef __cplusplus
0542 extern "C" {
0543 #endif
0544 void __asan_poison_memory_region(void const volatile *addr, size_t size);
0545 void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
0546 #ifdef __cplusplus
0547 } // extern "C"
0548 #endif
0549 #endif
0550 #else
0551 # define LLVM_ADDRESS_SANITIZER_BUILD 0
0552 # define __asan_poison_memory_region(p, size)
0553 # define __asan_unpoison_memory_region(p, size)
0554 #endif
0555 
0556 /// \macro LLVM_HWADDRESS_SANITIZER_BUILD
0557 /// Whether LLVM itself is built with HWAddressSanitizer instrumentation.
0558 #if __has_feature(hwaddress_sanitizer)
0559 #define LLVM_HWADDRESS_SANITIZER_BUILD 1
0560 #else
0561 #define LLVM_HWADDRESS_SANITIZER_BUILD 0
0562 #endif
0563 
0564 /// \macro LLVM_THREAD_SANITIZER_BUILD
0565 /// Whether LLVM itself is built with ThreadSanitizer instrumentation.
0566 #if __has_feature(thread_sanitizer) || defined(__SANITIZE_THREAD__)
0567 # define LLVM_THREAD_SANITIZER_BUILD 1
0568 #else
0569 # define LLVM_THREAD_SANITIZER_BUILD 0
0570 #endif
0571 
0572 #if LLVM_THREAD_SANITIZER_BUILD
0573 // Thread Sanitizer is a tool that finds races in code.
0574 // See http://code.google.com/p/data-race-test/wiki/DynamicAnnotations .
0575 // tsan detects these exact functions by name.
0576 #ifdef __cplusplus
0577 extern "C" {
0578 #endif
0579 void AnnotateHappensAfter(const char *file, int line, const volatile void *cv);
0580 void AnnotateHappensBefore(const char *file, int line, const volatile void *cv);
0581 void AnnotateIgnoreWritesBegin(const char *file, int line);
0582 void AnnotateIgnoreWritesEnd(const char *file, int line);
0583 #ifdef __cplusplus
0584 }
0585 #endif
0586 
0587 // This marker is used to define a happens-before arc. The race detector will
0588 // infer an arc from the begin to the end when they share the same pointer
0589 // argument.
0590 # define TsanHappensBefore(cv) AnnotateHappensBefore(__FILE__, __LINE__, cv)
0591 
0592 // This marker defines the destination of a happens-before arc.
0593 # define TsanHappensAfter(cv) AnnotateHappensAfter(__FILE__, __LINE__, cv)
0594 
0595 // Ignore any races on writes between here and the next TsanIgnoreWritesEnd.
0596 # define TsanIgnoreWritesBegin() AnnotateIgnoreWritesBegin(__FILE__, __LINE__)
0597 
0598 // Resume checking for racy writes.
0599 # define TsanIgnoreWritesEnd() AnnotateIgnoreWritesEnd(__FILE__, __LINE__)
0600 #else
0601 # define TsanHappensBefore(cv)
0602 # define TsanHappensAfter(cv)
0603 # define TsanIgnoreWritesBegin()
0604 # define TsanIgnoreWritesEnd()
0605 #endif
0606 
0607 /// \macro LLVM_NO_SANITIZE
0608 /// Disable a particular sanitizer for a function.
0609 #if __has_attribute(no_sanitize)
0610 #define LLVM_NO_SANITIZE(KIND) __attribute__((no_sanitize(KIND)))
0611 #else
0612 #define LLVM_NO_SANITIZE(KIND)
0613 #endif
0614 
0615 /// Mark debug helper function definitions like dump() that should not be
0616 /// stripped from debug builds.
0617 /// Note that you should also surround dump() functions with
0618 /// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
0619 /// get stripped in release builds.
0620 // FIXME: Move this to a private config.h as it's not usable in public headers.
0621 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0622 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
0623 #else
0624 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
0625 #endif
0626 
0627 /// \macro LLVM_PRETTY_FUNCTION
0628 /// Gets a user-friendly looking function signature for the current scope
0629 /// using the best available method on each platform.  The exact format of the
0630 /// resulting string is implementation specific and non-portable, so this should
0631 /// only be used, for example, for logging or diagnostics.
0632 #if defined(_MSC_VER)
0633 #define LLVM_PRETTY_FUNCTION __FUNCSIG__
0634 #elif defined(__GNUC__) || defined(__clang__)
0635 #define LLVM_PRETTY_FUNCTION __PRETTY_FUNCTION__
0636 #else
0637 #define LLVM_PRETTY_FUNCTION __func__
0638 #endif
0639 
0640 /// \macro LLVM_THREAD_LOCAL
0641 /// A thread-local storage specifier which can be used with globals,
0642 /// extern globals, and static globals.
0643 ///
0644 /// This is essentially an extremely restricted analog to C++11's thread_local
0645 /// support. It uses thread_local if available, falling back on gcc __thread
0646 /// if not. __thread doesn't support many of the C++11 thread_local's
0647 /// features. You should only use this for PODs that you can statically
0648 /// initialize to some constant value. In almost all circumstances this is most
0649 /// appropriate for use with a pointer, integer, or small aggregation of
0650 /// pointers and integers.
0651 #if LLVM_ENABLE_THREADS
0652 #if __has_feature(cxx_thread_local) || defined(_MSC_VER)
0653 #define LLVM_THREAD_LOCAL thread_local
0654 #else
0655 // Clang, GCC, and other compatible compilers used __thread prior to C++11 and
0656 // we only need the restricted functionality that provides.
0657 #define LLVM_THREAD_LOCAL __thread
0658 #endif
0659 #else // !LLVM_ENABLE_THREADS
0660 // If threading is disabled entirely, this compiles to nothing and you get
0661 // a normal global variable.
0662 #define LLVM_THREAD_LOCAL
0663 #endif
0664 
0665 /// \macro LLVM_ENABLE_EXCEPTIONS
0666 /// Whether LLVM is built with exception support.
0667 #if __has_feature(cxx_exceptions)
0668 #define LLVM_ENABLE_EXCEPTIONS 1
0669 #elif defined(__GNUC__) && defined(__EXCEPTIONS)
0670 #define LLVM_ENABLE_EXCEPTIONS 1
0671 #elif defined(_MSC_VER) && defined(_CPPUNWIND)
0672 #define LLVM_ENABLE_EXCEPTIONS 1
0673 #endif
0674 
0675 /// \macro LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
0676 /// Disable the profile instrument for a function.
0677 #if __has_attribute(no_profile_instrument_function)
0678 #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION                                    \
0679   __attribute__((no_profile_instrument_function))
0680 #else
0681 #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
0682 #endif
0683 
0684 /// \macro LLVM_PREFERRED_TYPE
0685 /// Adjust type of bit-field in debug info.
0686 #if __has_attribute(preferred_type)
0687 #define LLVM_PREFERRED_TYPE(T) __attribute__((preferred_type(T)))
0688 #else
0689 #define LLVM_PREFERRED_TYPE(T)
0690 #endif
0691 
0692 #endif