[clang] 3d59f9d - [ARM][AArch64] Correct __ARM_FEATURE_CRYPTO macro and crypto feature

David Candler via cfe-commits cfe-commits at lists.llvm.org
Fri May 14 06:26:25 PDT 2021


Author: David Candler
Date: 2021-05-14T14:19:46+01:00
New Revision: 3d59f9d22440645ca0237dfc5d91ca09f749174b

URL: https://github.com/llvm/llvm-project/commit/3d59f9d22440645ca0237dfc5d91ca09f749174b
DIFF: https://github.com/llvm/llvm-project/commit/3d59f9d22440645ca0237dfc5d91ca09f749174b.diff

LOG: [ARM][AArch64] Correct __ARM_FEATURE_CRYPTO macro and crypto feature

This patch contains a couple of minor corrections to my previous
crypto patch:

Since both AArch32 and AArch64 are now correctly setting the aes and
sha2 features individually, it is not necessary to continue to check
the crypto feature when defining feature macros.

In the AArch32 driver, the feature vector is only modified when the
crypto feature is actually in the vector. If crypto is not present,
there is no need to split it and explicitly define crypto/sha2/aes.

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D102406

Added: 
    

Modified: 
    clang/lib/Basic/Targets/AArch64.cpp
    clang/lib/Basic/Targets/ARM.cpp
    clang/lib/Driver/ToolChains/Arch/ARM.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index d26ae943b2e8a..82273a5e97aef 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -289,7 +289,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
 
   // The __ARM_FEATURE_CRYPTO is deprecated in favor of finer grained feature
   // macros for AES, SHA2, SHA3 and SM4
-  if (HasCrypto || (HasAES && HasSHA2))
+  if (HasAES && HasSHA2)
     Builder.defineMacro("__ARM_FEATURE_CRYPTO", "1");
 
   if (HasAES)

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 748a59525ef20..12439fcbeff96 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -649,7 +649,7 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts,
     // ACLE 6.5.7 Crypto Extension
     // The __ARM_FEATURE_CRYPTO is deprecated in favor of finer grained
     // feature macros for AES and SHA2
-    if (Crypto || (SHA2 && AES))
+    if (SHA2 && AES)
       Builder.defineMacro("__ARM_FEATURE_CRYPTO", "1");
     if (SHA2)
       Builder.defineMacro("__ARM_FEATURE_SHA2", "1");

diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 061eaf7924dbe..16d72e5367f58 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -636,6 +636,10 @@ void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   // FIXME: this needs reimplementation after the TargetParser rewrite
   bool HasSHA2 = false;
   bool HasAES = false;
+  const auto ItCrypto =
+      llvm::find_if(llvm::reverse(Features), [](const StringRef F) {
+        return F.contains("crypto");
+      });
   const auto ItSHA2 =
       llvm::find_if(llvm::reverse(Features), [](const StringRef F) {
         return F.contains("crypto") || F.contains("sha2");
@@ -650,7 +654,7 @@ void arm::getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
     HasSHA2 = ItSHA2->take_front() == "+";
   if (FoundAES)
     HasAES = ItAES->take_front() == "+";
-  if (FoundSHA2 || FoundAES) {
+  if (ItCrypto != Features.rend()) {
     if (HasSHA2 && HasAES)
       Features.push_back("+crypto");
     else


        


More information about the cfe-commits mailing list