diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h --- a/llvm/include/llvm/Support/Compiler.h +++ b/llvm/include/llvm/Support/Compiler.h @@ -103,31 +103,35 @@ #define LLVM_LVALUE_FUNCTION #endif -/// LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked -/// into a shared library, then the class should be private to the library and -/// not accessible from outside it. Can also be used to mark variables and -/// functions, making them private to any shared library they are linked into. -/// On PE/COFF targets, library visibility is the default, so this isn't needed. -#if (__has_attribute(visibility) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ +/// \macro LLVM_LIBRARY_VISIBILITY +/// If a class marked with this attribute is linked into a shared library, then +/// the class should be private to the library and not accessible from outside +/// it. Can also be used to mark variables and functions, making them private to +/// any shared library they are linked into. On PE/COFF targets, library +/// visibility is the default, so this isn't needed. +#if (__has_attribute(visibility) || defined(__GNUC__)) && \ !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32) #define LLVM_LIBRARY_VISIBILITY __attribute__ ((visibility("hidden"))) #else #define LLVM_LIBRARY_VISIBILITY #endif +/// \macro LLVM_PREFETCH #if defined(__GNUC__) #define LLVM_PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality) #else #define LLVM_PREFETCH(addr, rw, locality) #endif -#if __has_attribute(used) || LLVM_GNUC_PREREQ(3, 1, 0) +/// \macro LLVM_ATTRIBUTE_USED +#if __has_attribute(used) || defined(__GNUC__) #define LLVM_ATTRIBUTE_USED __attribute__((__used__)) #else #define LLVM_ATTRIBUTE_USED #endif -/// LLVM_NODISCARD - Warn if a type or return value is discarded. +/// \macro LLVM_NODISCARD +/// Warn if a type or return value is discarded. #if __cplusplus > 201402L && __has_cpp_attribute(nodiscard) #define LLVM_NODISCARD [[nodiscard]] #elif !__cplusplus @@ -140,43 +144,45 @@ #define LLVM_NODISCARD #endif -// Indicate that a non-static, non-const C++ member function reinitializes -// the entire object to a known state, independent of the previous state of -// the object. -// -// The clang-tidy check bugprone-use-after-move recognizes this attribute as a -// marker that a moved-from object has left the indeterminate state and can be -// reused. +/// \macro LLVM_ATTRIBUTE_REINITIALIZES +/// Indicate that a non-static, non-const C++ member function reinitializes the +/// entire object to a known state, independent of the previous state of the +/// object. +/// +/// The clang-tidy check bugprone-use-after-move recognizes this attribute as a +/// marker that a moved-from object has left the indeterminate state and can be +/// reused. #if __has_cpp_attribute(clang::reinitializes) #define LLVM_ATTRIBUTE_REINITIALIZES [[clang::reinitializes]] #else #define LLVM_ATTRIBUTE_REINITIALIZES #endif -// Some compilers warn about unused functions. When a function is sometimes -// used or not depending on build settings (e.g. a function only called from -// within "assert"), this attribute can be used to suppress such warnings. -// -// However, it shouldn't be used for unused *variables*, as those have a much -// more portable solution: -// (void)unused_var_name; -// Prefer cast-to-void wherever it is sufficient. -#if __has_attribute(unused) || LLVM_GNUC_PREREQ(3, 1, 0) +/// \macro LLVM_ATTRIBUTE_UNUSED +/// Some compilers warn about unused functions. When a function is sometimes +/// used or not depending on build settings (e.g. a function only called from +/// within "assert"), this attribute can be used to suppress such warnings. +/// +/// However, it shouldn't be used for unused *variables*, as those have a much +/// more portable solution: +/// (void)unused_var_name; +/// Prefer cast-to-void wherever it is sufficient. +#if __has_attribute(unused) || defined(__GNUC__) #define LLVM_ATTRIBUTE_UNUSED __attribute__((__unused__)) #else #define LLVM_ATTRIBUTE_UNUSED #endif +/// \macro LLVM_ATTRIBUTE_WEAK // FIXME: Provide this for PE/COFF targets. -#if (__has_attribute(weak) || LLVM_GNUC_PREREQ(4, 0, 0)) && \ +#if (__has_attribute(weak) || defined(__GNUC__)) && \ (!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)) #define LLVM_ATTRIBUTE_WEAK __attribute__((__weak__)) #else #define LLVM_ATTRIBUTE_WEAK #endif -// Prior to clang 3.2, clang did not accept any spelling of -// __has_attribute(const), so assume it is supported. +/// \macro LLVM_READNONE #if defined(__clang__) || defined(__GNUC__) // aka 'CONST' but following LLVM Conventions. #define LLVM_READNONE __attribute__((__const__)) @@ -184,6 +190,7 @@ #define LLVM_READNONE #endif +/// \macro LLVM_READONLY #if __has_attribute(pure) || defined(__GNUC__) // aka 'PURE' but following LLVM Conventions. #define LLVM_READONLY __attribute__((__pure__)) @@ -191,7 +198,9 @@ #define LLVM_READONLY #endif -#if __has_builtin(__builtin_expect) || LLVM_GNUC_PREREQ(4, 0, 0) +/// \macro LLVM_LIKELY +/// \macro LLVM_UNLIKELY +#if __has_builtin(__builtin_expect) || defined(__GNUC__) #define LLVM_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true) #define LLVM_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false) #else @@ -199,9 +208,10 @@ #define LLVM_UNLIKELY(EXPR) (EXPR) #endif -/// LLVM_ATTRIBUTE_NOINLINE - On compilers where we have a directive to do so, -/// mark a method "not for inlining". -#if __has_attribute(noinline) || LLVM_GNUC_PREREQ(3, 4, 0) +/// \macro LLVM_ATTRIBUTE_NOINLINE +/// On compilers where we have a directive to do so, mark a method "not for +/// inlining". +#if __has_attribute(noinline) || defined(__GNUC__) #define LLVM_ATTRIBUTE_NOINLINE __attribute__((noinline)) #elif defined(_MSC_VER) #define LLVM_ATTRIBUTE_NOINLINE __declspec(noinline) @@ -209,11 +219,10 @@ #define LLVM_ATTRIBUTE_NOINLINE #endif -/// LLVM_ATTRIBUTE_ALWAYS_INLINE - On compilers where we have a directive to do -/// so, mark a method "always inline" because it is performance sensitive. GCC -/// 3.4 supported this but is buggy in various cases and produces unimplemented -/// errors, just use it in GCC 4.0 and later. -#if __has_attribute(always_inline) || LLVM_GNUC_PREREQ(4, 0, 0) +/// \macro LLVM_ATTRIBUTE_ALWAYS_INLINE +/// On compilers where we have a directive to do so, mark a method "always +/// inline" because it is performance sensitive. +#if __has_attribute(always_inline) || defined(__GNUC__) #define LLVM_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) #elif defined(_MSC_VER) #define LLVM_ATTRIBUTE_ALWAYS_INLINE __forceinline @@ -229,7 +238,8 @@ #define LLVM_ATTRIBUTE_NORETURN #endif -#if __has_attribute(returns_nonnull) || LLVM_GNUC_PREREQ(4, 9, 0) +/// \macro LLVM_ATTRIBUTE_RETURNS_NONNULL +#if __has_attribute(returns_nonnull) || defined(__GNUC__) #define LLVM_ATTRIBUTE_RETURNS_NONNULL __attribute__((returns_nonnull)) #elif defined(_MSC_VER) #define LLVM_ATTRIBUTE_RETURNS_NONNULL _Ret_notnull_ @@ -237,8 +247,9 @@ #define LLVM_ATTRIBUTE_RETURNS_NONNULL #endif -/// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS Used to mark a function as returning a -/// pointer that does not alias any other valid pointer. +/// \macro LLVM_ATTRIBUTE_RETURNS_NOALIAS +/// Used to mark a function as returning a pointer that does not alias any other +/// valid pointer. #ifdef __GNUC__ #define LLVM_ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) #elif defined(_MSC_VER) @@ -247,7 +258,8 @@ #define LLVM_ATTRIBUTE_RETURNS_NOALIAS #endif -/// LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements. +/// \macro LLVM_FALLTHROUGH +/// Mark fallthrough cases in switch statements. #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough) #define LLVM_FALLTHROUGH [[fallthrough]] #elif __has_cpp_attribute(gnu::fallthrough) @@ -262,8 +274,8 @@ #define LLVM_FALLTHROUGH #endif -/// LLVM_REQUIRE_CONSTANT_INITIALIZATION - Apply this to globals to ensure that -/// they are constant initialized. +/// \macro LLVM_REQUIRE_CONSTANT_INITIALIZATION +/// Apply this to globals to ensure that they are constant initialized. #if __has_cpp_attribute(clang::require_constant_initialization) #define LLVM_REQUIRE_CONSTANT_INITIALIZATION \ [[clang::require_constant_initialization]] @@ -271,15 +283,15 @@ #define LLVM_REQUIRE_CONSTANT_INITIALIZATION #endif -/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress -/// pedantic diagnostics. +/// \macro LLVM_EXTENSION +/// Support compilers where we have a keyword to suppress pedantic diagnostics. #ifdef __GNUC__ #define LLVM_EXTENSION __extension__ #else #define LLVM_EXTENSION #endif -// LLVM_ATTRIBUTE_DEPRECATED(decl, "message") +/// \macro LLVM_ATTRIBUTE_DEPRECATED #if __has_feature(attribute_deprecated_with_message) # define LLVM_ATTRIBUTE_DEPRECATED(decl, message) \ decl __attribute__((deprecated(message))) @@ -294,18 +306,20 @@ decl #endif -/// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands -/// to an expression which states that it is undefined behavior for the -/// compiler to reach this point. Otherwise is not defined. -#if __has_builtin(__builtin_unreachable) || LLVM_GNUC_PREREQ(4, 5, 0) +/// \macro LLVM_BUILTIN_UNREACHABLE +/// On compilers which support it, expands to an expression which states that it +/// is undefined behavior for the compiler to reach this point. Otherwise is not +/// defined. +#if __has_builtin(__builtin_unreachable) || defined(__GNUC__) # define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable() #elif defined(_MSC_VER) # define LLVM_BUILTIN_UNREACHABLE __assume(false) #endif -/// LLVM_BUILTIN_TRAP - On compilers which support it, expands to an expression -/// which causes the program to exit abnormally. -#if __has_builtin(__builtin_trap) || LLVM_GNUC_PREREQ(4, 3, 0) +/// \macro LLVM_BUILTIN_TRAP +/// On compilers which support it, expands to an expression which causes the +/// program to exit abnormally. +#if __has_builtin(__builtin_trap) || defined(__GNUC__) # define LLVM_BUILTIN_TRAP __builtin_trap() #elif defined(_MSC_VER) // The __debugbreak intrinsic is supported by MSVC, does not require forward @@ -317,9 +331,9 @@ # define LLVM_BUILTIN_TRAP *(volatile int*)0x11 = 0 #endif -/// LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to -/// an expression which causes the program to break while running -/// under a debugger. +/// \macro LLVM_BUILTIN_DEBUGTRAP +/// On compilers which support it, expands to an expression which causes the +/// program to break while running under a debugger. #if __has_builtin(__builtin_debugtrap) # define LLVM_BUILTIN_DEBUGTRAP __builtin_debugtrap() #elif defined(_MSC_VER) @@ -336,7 +350,7 @@ /// \macro LLVM_ASSUME_ALIGNED /// Returns a pointer with an assumed alignment. -#if __has_builtin(__builtin_assume_aligned) || LLVM_GNUC_PREREQ(4, 7, 0) +#if __has_builtin(__builtin_assume_aligned) || defined(__GNUC__) # define LLVM_ASSUME_ALIGNED(p, a) __builtin_assume_aligned(p, a) #elif defined(LLVM_BUILTIN_UNREACHABLE) // As of today, clang does not support __builtin_assume_aligned. @@ -463,6 +477,7 @@ #define LLVM_NO_SANITIZE(KIND) #endif +/// \macro LLVM_DUMP_METHOD /// Mark debug helper function definitions like dump() that should not be /// stripped from debug builds. /// Note that you should also surround dump() functions with