Skip to content

Commit

Permalink
Search for attributes with __has_attribute instead of
Browse files Browse the repository at this point in the history
__has_cpp_attribute.
  • Loading branch information
BenHuddleston committed Apr 2, 2019
1 parent da2dd53 commit de6a7a4
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions folly/CPortability.h
Expand Up @@ -121,33 +121,25 @@
#endif

#if FOLLY_SANITIZE
/**
* GCC 8.2.0 and Clang 6.0 both support the no_sanitize attribute, however,
* GCC 7.3.0 does not. Check for alternative attributes if no_sanitize is not
* available.
*/
#if defined(__has_cpp_attribute)

#if __has_cpp_attribute(no_sanitize)
// Find an attribute to disable undefined behaviour sanitization
#if __has_attribute(__no_sanitize__)
#define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER \
__attribute__((no_sanitize("undefined")))
#elif __has_cpp_attribute(no_sanitize_undefined)
__attribute__((__no_sanitize__("undefined")))
#elif __has_attribute(__no_sanitize_undefined__)
#define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER \
__attribute__((no_sanitize_undefined))
#endif // __has_cpp_attribute(no_sanitize)
__attribute__((__no_sanitize_undefined__))
#endif // __has_attribute(no_sanitize)

#if __has_cpp_attribute(no_sanitize)
// Find an attribute to disable non-null attribute sanitization
#if __has_attribute(__no_sanitize__)
#define FOLLY_DISABLE_NONNULL_SANITIZER \
__attribute__((no_sanitize("nonnull-attribute")))
#elif __has_cpp_attribute(nonnull)
__attribute__((__no_sanitize__("nonnull-attribute")))
#elif __has_attribute(__nonnull__)
#define FOLLY_DISABLE_NONNULL_SANITIZER \
__attribute__((nonnull))
#endif // __has_cpp_attribute(no_sanitize)
__attribute__((__nonnull__))
#endif // __has_attribute(no_sanitize)

#else // defined(__has_cpp_attribute)
#error __has_cpp_attribute was not found, cannot determine which attributes to\
use.
#endif // defined(__has_cpp_attribute)
#else // FOLLY_SANITIZE
#define FOLLY_DISABLE_UNDEFINED_BEHAVIOR_SANITIZER
#define FOLLY_DISABLE_NONNULL_SANITIZER
Expand Down

0 comments on commit de6a7a4

Please sign in to comment.