X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FCPortability.h;h=3b362d2a885b96781ea4a7bbf000574694cb3387;hb=a674aa6cee470969ddecd340154002cf1d3efc1c;hp=0989cbc920fb745a07c6e4dee2afa7c72d85b911;hpb=9b7138e49c6c545f09a1f016df5b26fd05d13d23;p=folly.git diff --git a/folly/CPortability.h b/folly/CPortability.h index 0989cbc9..3b362d2a 100644 --- a/folly/CPortability.h +++ b/folly/CPortability.h @@ -33,15 +33,33 @@ # endif #endif +// portable version check for clang +#ifndef __CLANG_PREREQ +# if defined __clang__ && defined __clang_major__ && defined __clang_minor__ +/* nolint */ +# define __CLANG_PREREQ(maj, min) \ + ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min)) +# else +/* nolint */ +# define __CLANG_PREREQ(maj, min) 0 +# endif +#endif + +#if defined(__has_builtin) +#define FOLLY_HAS_BUILTIN(...) __has_builtin(__VA_ARGS__) +#else +#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 @@ -71,14 +89,19 @@ /* 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 +/** + * Define a convenience macro to test when ASAN, UBSAN or TSAN sanitizer are + * being used + */ +#if defined(FOLLY_SANITIZE_ADDRESS) || defined(FOLLY_SANITIZE_THREAD) || \ + defined(UNDEFINED_SANITIZER) +#define FOLLY_SANITIZE 1 +#endif + /** * ASAN/MSAN/TSAN define pre-processor symbols: * ADDRESS_SANITIZER/MEMORY_SANITIZER/THREAD_SANITIZER. @@ -90,10 +113,10 @@ * used as folly whitelists some functions. */ #if UNDEFINED_SANITIZER -# define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER(x) \ - __attribute__((no_sanitize(x))) +#define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER(...) \ + __attribute__((no_sanitize(__VA_ARGS__))) #else -# define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER(x) +#define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER(...) #endif // UNDEFINED_SANITIZER /** @@ -126,3 +149,12 @@ #else # define FOLLY_ALWAYS_INLINE inline #endif + +// attribute hidden +#if _MSC_VER +#define FOLLY_ATTR_VISIBILITY_HIDDEN +#elif defined(__clang__) || defined(__GNUC__) +#define FOLLY_ATTR_VISIBILITY_HIDDEN __attribute__((__visibility__("hidden"))) +#else +#define FOLLY_ATTR_VISIBILITY_HIDDEN +#endif