[clang] 89c94c2 - [clang][Driver] Get darwin -Xarch_ working for subtypes, again.

Ahmed Bougacha via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 9 18:23:15 PST 2022


Author: Ahmed Bougacha
Date: 2022-03-09T18:21:45-08:00
New Revision: 89c94c242c7ddcc700aba6af7243dcac7a9a4ef2

URL: https://github.com/llvm/llvm-project/commit/89c94c242c7ddcc700aba6af7243dcac7a9a4ef2
DIFF: https://github.com/llvm/llvm-project/commit/89c94c242c7ddcc700aba6af7243dcac7a9a4ef2.diff

LOG: [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 <mail at justinbogner.com>
with some added tests.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Darwin.cpp
    clang/test/Driver/darwin-xarch.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 005236c4476f4..a11cd3fbaa71c 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 3014236f8ccda..0df17fda7b0e3 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"


        


More information about the cfe-commits mailing list