1 //===--- Compiler.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
9 // This file contains a variety of feature test macros copied from
10 // include/llvm/Support/Compiler.h so that LLVMDemangle does not need to take
11 // a dependency on LLVMSupport.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_DEMANGLE_COMPILER_H
15 #define LLVM_DEMANGLE_COMPILER_H
18 // snprintf is implemented in VS 2015
20 #define snprintf _snprintf_s
25 #define __has_feature(x) 0
28 #ifndef __has_cpp_attribute
29 #define __has_cpp_attribute(x) 0
32 #ifndef __has_attribute
33 #define __has_attribute(x) 0
37 #define __has_builtin(x) 0
40 #ifndef LLVM_GNUC_PREREQ
41 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
42 #define LLVM_GNUC_PREREQ(maj, min, patch) \
43 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) + __GNUC_PATCHLEVEL__ >= \
44 ((maj) << 20) + ((min) << 10) + (patch))
45 #elif defined(__GNUC__) && defined(__GNUC_MINOR__)
46 #define LLVM_GNUC_PREREQ(maj, min, patch) \
47 ((__GNUC__ << 20) + (__GNUC_MINOR__ << 10) >= ((maj) << 20) + ((min) << 10))
49 #define LLVM_GNUC_PREREQ(maj, min, patch) 0
53 #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0)
54 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
56 #define LLVM_ATTRIBUTE_USED
59 #if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0)
60 #define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
61 #elif defined(_MSC_VER)
62 #define LLVM_BUILTIN_UNREACHABLE __assume(false)
65 #if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0)
66 #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline))
67 #elif defined(_MSC_VER)
68 #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline)
70 #define LLVM_ATTRIBUTE_NOINLINE
73 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
74 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
76 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
79 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
80 #define LLVM_FALLTHROUGH [[fallthrough]]
81 #elif __has_cpp_attribute(gnu::fallthrough)
82 #define LLVM_FALLTHROUGH [[gnu::fallthrough]]
84 // Workaround for llvm.org/PR23435, since clang 3.6 and below emit a spurious
85 // error when __has_cpp_attribute is given a scoped attribute in C mode.
86 #define LLVM_FALLTHROUGH
87 #elif __has_cpp_attribute(clang::fallthrough)
88 #define LLVM_FALLTHROUGH [[clang::fallthrough]]
90 #define LLVM_FALLTHROUGH