clang 12 and earlier only defined the SHA-1 intrinsics when
__ARM_FEATURE_CRYPTO is defined.
(defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5))
/*
(defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5))
/*
- * With clang 15.0 and earlier, arm_neon.h has a bug where it only defines the
- * SHA-1 intrinsics when SHA-2 is enabled in the main target. This prevents
- * them from being used in target attribute functions. Work around this by
- * defining __ARM_FEATURE_SHA2.
- *
- * And yes, the feature it wants is indeed *SHA-2*, not SHA-1.
+ * clang's arm_neon.h used to have a bug where it only defined the SHA-1
+ * intrinsics when CRYPTO (clang 12 and earlier) or SHA2 (clang 13 and 14) is
+ * enabled in the main target. This prevents them from being used in target
+ * attribute functions. Work around this by defining the macros ourselves.
-#if defined(__clang__) && __clang_major__ <= 15 && !defined(__ARM_FEATURE_SHA2)
-# define __ARM_FEATURE_SHA2 1
-# define USED_SHA2_FEATURE_WORKAROUND
+#if defined(__clang__) && __clang_major__ <= 15
+# ifndef __ARM_FEATURE_CRYPTO
+# define __ARM_FEATURE_CRYPTO 1
+# define DEFINED_ARM_FEATURE_CRYPTO
+# endif
+# ifndef __ARM_FEATURE_SHA2
+# define __ARM_FEATURE_SHA2 1
+# define DEFINED_ARM_FEATURE_SHA2
+# endif
#endif
#include <arm_neon.h>
#endif
#include <arm_neon.h>
-#ifdef USED_SHA2_FEATURE_WORKAROUND
+#ifdef DEFINED_ARM_FEATURE_CRYPTO
+# undef __ARM_FEATURE_CRYPTO
+#endif
+#ifdef DEFINED_ARM_FEATURE_SHA2
# undef __ARM_FEATURE_SHA2
#endif
# undef __ARM_FEATURE_SHA2
#endif