Improve performance of enumerate() with optimization disabled
[folly.git] / folly / CPortability.h
index 8f8ac21d6e63062ddcca40bf42715bc3df9f84f9..1c63ec8adbdbb9c3af8f03cea902f5dc6ee6d327 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2017-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #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
+
+#if defined(__has_include)
+#define FOLLY_HAS_INCLUDE(...) __has_include(__VA_ARGS__)
+#else
+#define FOLLY_HAS_INCLUDE(...) 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
 
 
 /* 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.