Move clang bug workaround to the head of file

Signed-off-by: Jerry Yu <jerry.h.yu@arm.com>
diff --git a/library/sha256.c b/library/sha256.c
index d5be7aa..c167dbe 100644
--- a/library/sha256.c
+++ b/library/sha256.c
@@ -22,8 +22,31 @@
  *  http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
  */
 
+#if defined(__aarch64__) && !defined(__ARM_FEATURE_CRYPTO) && \
+    defined(__clang__) &&  __clang_major__ < 18 && __clang_major__ > 3
+/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged.
+ *
+ * The intrinsic declaration are guarded with ACLE predefined macros in clang,
+ * and those macros are only enabled with command line. Define the macros can
+ * enable those declaration and avoid compile error on it.
+ */
+#define __ARM_FEATURE_CRYPTO 1
+#pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
+#define MBEDTLS_POP_TARGET_PRAGMA
+#endif /* __aarch64__ && __clang__ &&
+         !__ARM_FEATURE_CRYPTO && __clang_major__ < 18 && __clang_major__ > 3 */
+
 #include "common.h"
 
+#if defined(MBEDTLS_POP_TARGET_PRAGMA) && \
+    !(defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT) || \
+      defined(MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY))
+#if defined(__clang__)
+#pragma clang attribute pop
+#endif
+#undef MBEDTLS_POP_TARGET_PRAGMA
+#endif
+
 #if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C)
 
 #include "mbedtls/sha256.h"
@@ -42,16 +65,6 @@
 #      if defined(__clang__)
 #        if __clang_major__ < 4
 #          error "A more recent Clang is required for MBEDTLS_SHA256_USE_A64_CRYPTO_*"
-#        elif __clang_major__ < 18
-           /* TODO: Re-consider above after https://reviews.llvm.org/D131064
-            *       merged.
-            *
-            * The intrinsic declaration are guarded with ACLE predefined macros
-            * in clang, and those macros are only enabled with command line.
-            * Define the macros can enable those declaration and avoid compile
-            * error on it.
-            */
-#          define __ARM_FEATURE_CRYPTO 1
 #        endif
 #        pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function)
 #        define MBEDTLS_POP_TARGET_PRAGMA
@@ -398,7 +411,6 @@
 
 #endif /* MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_A64_CRYPTO_ONLY */
 
-
 #if !defined(MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT)
 #define mbedtls_internal_sha256_process_many_c mbedtls_internal_sha256_process_many
 #define mbedtls_internal_sha256_process_c      mbedtls_internal_sha256_process