From f99fa5284c5a9e18d5f1af4c3ee13eaee675610e Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 26 Jul 2017 14:18:41 -0700 Subject: [PATCH] Add FOLLY_HAS_FEATURE and use it Summary: [Folly] Add `FOLLY_HAS_FEATURE` and use it. Use it in the definitions of `FOLLY_SANITIZE_ADDRESS` and `FOLLY_SANITIZE_THREAD`. Reviewed By: meyering Differential Revision: D5496915 fbshipit-source-id: e272137ad8ba891e64fc98444edf573115764ee2 --- folly/CPortability.h | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/folly/CPortability.h b/folly/CPortability.h index 8f8ac21d..cba31683 100644 --- a/folly/CPortability.h +++ b/folly/CPortability.h @@ -51,15 +51,15 @@ #define FOLLY_HAS_BUILTIN(...) 0 #endif +#if defined(__has_feature) +#define FOLLY_HAS_FEATURE(...) __has_feature(__VA_ARGS__) +#else +#define FOLLY_HAS_FEATURE(...) 0 +#endif + /* Define a convenience macro to test when address sanitizer is being used * across the different compilers (e.g. clang, gcc) */ -#if defined(__clang__) -# if __has_feature(address_sanitizer) -# define FOLLY_SANITIZE_ADDRESS 1 -# endif -#elif defined (__GNUC__) && \ - (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ >= 5)) && \ - __SANITIZE_ADDRESS__ +#if FOLLY_HAS_FEATURE(address_sanitizer) || __SANITIZE_ADDRESS__ # define FOLLY_SANITIZE_ADDRESS 1 #endif @@ -89,11 +89,7 @@ /* Define a convenience macro to test when thread sanitizer is being used * across the different compilers (e.g. clang, gcc) */ -#if defined(__clang__) -# if __has_feature(thread_sanitizer) -# define FOLLY_SANITIZE_THREAD 1 -# endif -#elif defined(__GNUC__) && __SANITIZE_THREAD__ +#if FOLLY_HAS_FEATURE(thread_sanitizer) || __SANITIZE_THREAD__ # define FOLLY_SANITIZE_THREAD 1 #endif -- 2.34.1