1 //===--- Compiler.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 // 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 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_DEMANGLE_COMPILER_H 15 #define LLVM_DEMANGLE_COMPILER_H 16 17 #ifdef _MSC_VER 18 // snprintf is implemented in VS 2015 19 #if _MSC_VER < 1900 20 #define snprintf _snprintf_s 21 #endif 22 #endif 23 24 #ifndef __has_feature 25 #define __has_feature(x) 0 26 #endif 27 28 #ifndef __has_cpp_attribute 29 #define __has_cpp_attribute(x) 0 30 #endif 31 32 #ifndef __has_attribute 33 #define __has_attribute(x) 0 34 #endif 35 36 #ifndef __has_builtin 37 #define __has_builtin(x) 0 38 #endif 39 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)) 48 #else 49 #define LLVM_GNUC_PREREQ(maj, min, patch) 0 50 #endif 51 #endif 52 53 #if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0) 54 #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) 55 #else 56 #define LLVM_ATTRIBUTE_USED 57 #endif 58 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) 63 #endif 64 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) 69 #else 70 #define LLVM_ATTRIBUTE_NOINLINE 71 #endif 72 73 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 74 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED 75 #else 76 #define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE 77 #endif 78 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]] 83 #elif !__cplusplus 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]] 89 #else 90 #define LLVM_FALLTHROUGH 91 #endif 92 93 #endif 94