From 82bcb0fe7dec8d40f0e69fe40d503925f8f70d5d Mon Sep 17 00:00:00 2001 From: fanc999 Date: Thu, 25 Jul 2024 15:17:24 +0000 Subject: [PATCH] Bug 1907001 - Add MOZ_HAS_CLANG_ATTRIBUTE r=glandium, a=dmeehan Note this patch was provided by a contributor to fix MSVC builds of a SpiderMonkey embedding. Differential Revision: https://phabricator.services.mozilla.com/D216843 --- mfbt/Attributes.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h index 3be46cf5a824..2e93c6347047 100644 --- a/mfbt/Attributes.h +++ b/mfbt/Attributes.h @@ -78,6 +78,13 @@ # define MOZ_HAVE_NO_STACK_PROTECTOR __attribute__((no_stack_protector)) #endif +/* if defined(__clang__) && __has_attribute (attr) may not be portable */ +#if defined(__clang__) +# define MOZ_HAS_CLANG_ATTRIBUTE(attr) __has_attribute(attr) +#else +# define MOZ_HAS_CLANG_ATTRIBUTE(attr) 0 +#endif + /* * When built with clang analyzer (a.k.a scan-build), define MOZ_HAVE_NORETURN * to mark some false positives @@ -88,15 +95,13 @@ # endif #endif -#if defined(__GNUC__) || \ - (defined(__clang__) && __has_attribute(no_profile_instrument_function)) +#if defined(__GNUC__) || MOZ_HAS_CLANG_ATTRIBUTE(no_profile_instrument_function) # define MOZ_NOPROFILE __attribute__((no_profile_instrument_function)) #else # define MOZ_NOPROFILE #endif -#if defined(__GNUC__) || \ - (defined(__clang__) && __has_attribute(no_instrument_function)) +#if defined(__GNUC__) || (MOZ_HAS_CLANG_ATTRIBUTE(no_instrument_function)) # define MOZ_NOINSTRUMENT __attribute__((no_instrument_function)) #else # define MOZ_NOINSTRUMENT @@ -121,7 +126,7 @@ * * This is useful to have clearer information on assertion failures. */ -#if defined(__clang__) && __has_attribute(nomerge) +#if MOZ_HAS_CLANG_ATTRIBUTE(nomerge) # define MOZ_NOMERGE __attribute__((nomerge)) #else # define MOZ_NOMERGE