From 89c94c242c7ddcc700aba6af7243dcac7a9a4ef2 Mon Sep 17 00:00:00 2001 From: Ahmed Bougacha Date: Wed, 9 Mar 2022 15:52:21 -0800 Subject: [PATCH] [clang][Driver] Get darwin -Xarch_ working for subtypes, again. 35ca7d9ddf4 broke 471c4f829934 for -arch flags that don't map 1:1 to the triple arch. This has been broken for the many years since. It hasn't mattered much since then, mostly because few people use it, but also because it works for x86_64/i386, armv7/armv7s don't differ much, arm64 is its own arch, and arm64/arm64_32 have different arches (and it's a rare combination anyway). But arm64/arm64e exposes this issue again. Patch by: Justin Bogner with some added tests. --- clang/lib/Driver/ToolChains/Darwin.cpp | 9 +++------ clang/test/Driver/darwin-xarch.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 005236c..a11cd3f 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -2487,12 +2487,9 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args, if (A->getOption().matches(options::OPT_Xarch__)) { // Skip this argument unless the architecture matches either the toolchain // triple arch, or the arch being bound. - llvm::Triple::ArchType XarchArch = - tools::darwin::getArchTypeForMachOArchName(A->getValue(0)); - if (!(XarchArch == getArch() || - (!BoundArch.empty() && - XarchArch == - tools::darwin::getArchTypeForMachOArchName(BoundArch)))) + StringRef XarchArch = A->getValue(0); + if (!(XarchArch == getArchName() || + (!BoundArch.empty() && XarchArch == BoundArch))) continue; Arg *OriginalArg = A; diff --git a/clang/test/Driver/darwin-xarch.c b/clang/test/Driver/darwin-xarch.c index 3014236..0df17fd 100644 --- a/clang/test/Driver/darwin-xarch.c +++ b/clang/test/Driver/darwin-xarch.c @@ -18,3 +18,32 @@ // RUN: FileCheck --check-prefix=CHECK-ARMV7-LINK < %t %s // // CHECK-ARMV7-LINK: ld{{.*}} "-arch" "armv7"{{.*}} "-some-linker-arg" + + +// RUN: %clang -target armv7s-apple-ios7 -### \ +// RUN: -arch armv7 -Xarch_armv7 -DARMV7=1 \ +// RUN: -arch armv7s -Xarch_armv7s -DARMV7S=1 \ +// RUN: -c %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-ARMV7S < %t %s +// +// CHECK-ARMV7S: clang{{.*}}" "-cc1" "-triple" "thumbv7-apple-ios7.0.0" +// CHECK-ARMV7S-NOT: "-D" "ARMV7S=1" +// CHECK-ARMV7S-SAME: "-D" "ARMV7=1" +// +// CHECK-ARMV7S: clang{{.*}}" "-cc1" "-triple" "thumbv7s-apple-ios7.0.0" +// CHECK-ARMV7S-NOT: "-D" "ARMV7=1" +// CHECK-ARMV7S-SAME: "-D" "ARMV7S=1" + +// RUN: %clang -target arm64-apple-ios14 -### \ +// RUN: -arch arm64 -Xarch_arm64 -DARM64=1 \ +// RUN: -arch arm64e -Xarch_arm64e -DARM64E=1 \ +// RUN: -c %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-ARM64 < %t %s +// +// CHECK-ARM64: clang{{.*}}" "-cc1" "-triple" "arm64-apple-ios14.0.0" +// CHECK-ARM64-NOT: "-D" "ARM64E=1" +// CHECK-ARM64-SAME: "-D" "ARM64=1" +// +// CHECK-ARM64: clang{{.*}}" "-cc1" "-triple" "arm64e-apple-ios14.0.0" +// CHECK-ARM64-NOT: "-D" "ARM64=1" +// CHECK-ARM64-SAME: "-D" "ARM64E=1" -- 2.7.4