[PATCH] D100807: [clang][driver] Use the canonical Darwin arch name when printing out the triple for a Darwin target

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 19 18:23:32 PDT 2021


arphaman created this revision.
arphaman added reviewers: ab, t.p.northover.
Herald added subscribers: ributzka, kristof.beyls.
arphaman requested review of this revision.
Herald added a project: clang.

Clang's driver currently prints out different default triples when it's invoked like this on Apple Silicon:

  $ clang --version
  Target: arm64-apple-darwin19.0.0
  $ clang -arch arm64 --version
  Target: aarch64-apple-darwin19.0.0

This change ensures that the driver uses the canonical arch names for a Darwin triple when the target triple is being printed out by the driver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100807

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm64_32-link.c
  clang/test/Driver/default-toolchain.c


Index: clang/test/Driver/default-toolchain.c
===================================================================
--- clang/test/Driver/default-toolchain.c
+++ clang/test/Driver/default-toolchain.c
@@ -2,7 +2,10 @@
 // RUN: grep 'Target: x86_64-unknown-unknown' %t
 
 // RUN: %clang -target i386-apple-darwin9 -arch ppc -m64 -v 2> %t
-// RUN: grep 'Target: powerpc64-apple-darwin9' %t
+// RUN: grep 'Target: ppc64-apple-darwin9' %t
 
 // RUN: %clang -target i386-apple-darwin9 -arch ppc64 -m32 -v 2> %t
-// RUN: grep 'Target: powerpc-apple-darwin9' %t
+// RUN: grep 'Target: ppc-apple-darwin9' %t
+
+// RUN: %clang -target x86_64-apple-macos11 -arch arm64 -v 2>&1 | FileCheck --check-prefix=ARM64 %s
+// ARM64: Target: arm64-apple-macos11
Index: clang/test/Driver/arm64_32-link.c
===================================================================
--- clang/test/Driver/arm64_32-link.c
+++ clang/test/Driver/arm64_32-link.c
@@ -1,4 +1,4 @@
 // RUN: %clang -target x86_64-apple-darwin -arch arm64_32 -miphoneos-version-min=8.0 %s -### 2>&1 | FileCheck %s
 
-// CHECK: "-cc1"{{.*}} "-triple" "aarch64_32-apple-ios8.0.0"
+// CHECK: "-cc1"{{.*}} "-triple" "arm64_32-apple-ios8.0.0"
 // CHECK: ld{{.*}} "-arch" "arm64_32"
Index: clang/test/Driver/aarch64-cpus.c
===================================================================
--- clang/test/Driver/aarch64-cpus.c
+++ clang/test/Driver/aarch64-cpus.c
@@ -33,7 +33,7 @@
 // ARM64E-DARWIN: "-cc1"{{.*}} "-triple" "arm64e{{.*}}" "-target-cpu" "apple-a12"
 
 // RUN: %clang -target arm64-apple-darwin -arch arm64_32 -### -c %s 2>&1 | FileCheck -check-prefix=ARM64_32-DARWIN %s
-// ARM64_32-DARWIN: "-cc1"{{.*}} "-triple" "aarch64_32{{.*}}" "-target-cpu" "apple-s4"
+// ARM64_32-DARWIN: "-cc1"{{.*}} "-triple" "arm64_32{{.*}}" "-target-cpu" "apple-s4"
 
 // RUN: %clang -target aarch64 -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
 // RUN: %clang -target aarch64 -mlittle-endian -mcpu=cortex-a35 -### -c %s 2>&1 | FileCheck -check-prefix=CA35 %s
Index: clang/include/clang/Driver/ToolChain.h
===================================================================
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -237,7 +237,13 @@
   StringRef getDefaultUniversalArchName() const;
 
   std::string getTripleString() const {
-    return Triple.getTriple();
+    if (!Triple.isOSDarwin())
+      return Triple.getTriple();
+    // Use the default architecture name (that's expected by -arch) for a
+    // Darwin triple to provide consistent triple output to the user.
+    llvm::Triple TT = Triple;
+    TT.setArchName(getDefaultUniversalArchName());
+    return TT.getTriple();
   }
 
   /// Get the toolchain's effective clang triple.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100807.338680.patch
Type: text/x-patch
Size: 2736 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210420/ec16e42f/attachment.bin>


More information about the cfe-commits mailing list