Skip to content

Commit 8a68671

Browse files
committed
[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.
1 parent 7a49c30 commit 8a68671

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ std::string aarch64::getAArch64TargetCPU(const ArgList &Args,
5757
if (Triple.isArm64e())
5858
return "apple-a12";
5959

60-
// Make sure we pick the appropriate Apple CPU if -arch is used or when
61-
// targetting a Darwin OS.
62-
if (Args.getLastArg(options::OPT_arch) || Triple.isOSDarwin())
60+
// Make sure we pick the appropriate Apple CPU when targetting a Darwin OS.
61+
if (Triple.isOSDarwin())
6362
return Triple.getArch() == llvm::Triple::aarch64_32 ? "apple-s4"
6463
: "apple-a7";
6564

@@ -274,7 +273,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
274273
success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features);
275274
else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
276275
success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
277-
else if (Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple))
276+
else if (isCPUDeterminedByTriple(Triple))
278277
success = getAArch64ArchFeaturesFromMcpu(
279278
D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
280279
else
@@ -287,8 +286,7 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
287286
else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
288287
success =
289288
getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
290-
else if (success &&
291-
(Args.hasArg(options::OPT_arch) || isCPUDeterminedByTriple(Triple)))
289+
else if (success && isCPUDeterminedByTriple(Triple))
292290
success = getAArch64MicroArchFeaturesFromMcpu(
293291
D, getAArch64TargetCPU(Args, Triple, A), Args, Features);
294292

clang/test/Driver/arm-arch-darwin.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
/// -arch is unsupported for non-Darwin targets.
66
// RUN: not %clang --target=armv7m -arch armv7m -mcpu=cortex-m4 -### -c %s 2>&1 | FileCheck -check-prefix=ERR %s
77
// ERR: unsupported option '-arch' for target 'armv7m'
8+
9+
// RUN: not %clang --target=aarch64-linux-gnu -arch arm64 -### -c %s 2>&1 | FileCheck -check-prefix=ERR2 %s
10+
// ERR2: unsupported option '-arch' for target 'aarch64-linux-gnu'

0 commit comments

Comments
 (0)