[clang] 8a68671 - [Driver, AArch64] Ensure -arch logic is Darwin-specific

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 5 18:10:43 PST 2023


Author: Fangrui Song
Date: 2023-12-05T18:10:39-08:00
New Revision: 8a686716e360157ad5726560cc5ea61be647893c

URL: https://github.com/llvm/llvm-project/commit/8a686716e360157ad5726560cc5ea61be647893c
DIFF: https://github.com/llvm/llvm-project/commit/8a686716e360157ad5726560cc5ea61be647893c.diff

LOG: [Driver,AArch64] Ensure -arch logic is Darwin-specific

`-arch` is a Darwin-specific option that is ignored for other targets
and not known by GCC. It leads to an error for non-Darwin OSes for
non-AArch64 architectures. Ensure that it leads to an error for AArch64
non-Darwin OSes as well.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Arch/AArch64.cpp
    clang/test/Driver/arm-arch-darwin.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 1f77c98705174..097258b169244 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -57,9 +57,8 @@ std::string aarch64::getAArch64TargetCPU(const ArgList &Args,
   if (Triple.isArm64e())
     return "apple-a12";
 
-  // Make sure we pick the appropriate Apple CPU if -arch is used or when
-  // targetting a Darwin OS.
-  if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
+  // Make sure we pick the appropriate Apple CPU when targetting a Darwin OS.
+  if (Triple.isOSDarwin())
     return Triple.getArch() == llvm::Triple::aarch64_32 ? "apple-s4"
                                                         : "apple-a7";
 
@@ -274,7 +273,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
     success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features);
   else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
     success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
-  else if (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple))
+  else if (isCPUDeterminedByTriple(Triple))
     success = getAArch64ArchFeaturesFromMcpu(
         D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
   else
@@ -287,8 +286,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
   else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
     success =
         getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
-  else if (success &&
-           (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple)))
+  else if (success && isCPUDeterminedByTriple(Triple))
     success = getAArch64MicroArchFeaturesFromMcpu(
         D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
 

diff  --git a/clang/test/Driver/arm-arch-darwin.c b/clang/test/Driver/arm-arch-darwin.c
index c523622964738..f6d3f88a3f8d1 100644
--- a/clang/test/Driver/arm-arch-darwin.c
+++ b/clang/test/Driver/arm-arch-darwin.c
@@ -5,3 +5,6 @@
 /// -arch is unsupported for non-Darwin targets.
 // RUN: not %clang --target=armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | FileCheck -check-prefix=ERR %s
 // ERR: unsupported option '-arch' for target 'armv7m'
+
+// RUN: not %clang --target=aarch64-linux-gnu -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ERR2 %s
+// ERR2: unsupported option '-arch' for target 'aarch64-linux-gnu'


        


More information about the cfe-commits mailing list