[clang] 2bdf5aa - [Driver] Properly report error for unsupported powerpc darwin/macos triples

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 11 18:53:55 PDT 2023


Author: Fangrui Song
Date: 2023-09-11T18:53:51-07:00
New Revision: 2bdf5aa5dffffebf6e3b1afe588db990ca58e55c

URL: https://github.com/llvm/llvm-project/commit/2bdf5aa5dffffebf6e3b1afe588db990ca58e55c
DIFF: https://github.com/llvm/llvm-project/commit/2bdf5aa5dffffebf6e3b1afe588db990ca58e55c.diff

LOG: [Driver] Properly report error for unsupported powerpc darwin/macos triples

The removal started at https://reviews.llvm.org/D50989 and
https://reviews.llvm.org/D75494 removed the Triple support. Without recognizing
Darwin triples as Mach-O, we will get assertion error in ToolChains/Darwin.h due
to the universal binary mechanism.

Fix #47698

---

This requires fixing many misuses of llc -march= and llvm-mc -arch= (
commits 806761a7629df268c8aed49657aeccffa6bca449 and 252c42354eca54274ed7b10c32c73c6937478e8b).

Added: 
    

Modified: 
    clang/test/Driver/unsupported-target-arch.c
    llvm/lib/TargetParser/Triple.cpp
    llvm/unittests/TargetParser/TripleTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/Driver/unsupported-target-arch.c b/clang/test/Driver/unsupported-target-arch.c
index 24174650151f1ce..8df0ee9fe7d06f1 100644
--- a/clang/test/Driver/unsupported-target-arch.c
+++ b/clang/test/Driver/unsupported-target-arch.c
@@ -59,3 +59,7 @@
 // RUN: not %clang --target=thumbeb-none-elf -o %t.o %s 2> %t.err
 // RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-THUMBEB-INVALID-ENV %s
 // CHECK-THUMBEB-INVALID-ENV: warning: mismatch between architecture and environment in target triple 'thumbeb-none-elf'; did you mean 'thumbeb-none-eabi'? [-Winvalid-command-line-argument]{{$}}
+
+// RUN: not %clang --target=powerpc-apple-darwin -o /dev/null %s 2> %t.err
+// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-PPCMAC %s
+// CHECK-PPCMAC: error: unknown target triple 'unknown-apple-macosx{{.*}}'

diff  --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 260819d4a83d5a2..3da145f3b0b8927 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -787,6 +787,8 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
 }
 
 static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
+  if (T.isOSDarwin())
+    return Triple::MachO;
   switch (T.getArch()) {
   case Triple::UnknownArch:
   case Triple::aarch64:
@@ -795,9 +797,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
   case Triple::thumb:
   case Triple::x86:
   case Triple::x86_64:
-    if (T.isOSDarwin())
-      return Triple::MachO;
-    else if (T.isOSWindows())
+    if (T.isOSWindows())
       return Triple::COFF;
     return Triple::ELF;
 

diff  --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index dae5a82ff491860..2b2ec73fcb8a926 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -1937,6 +1937,7 @@ TEST(TripleTest, FileFormat) {
   EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
   EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
   EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
+  EXPECT_EQ(Triple::MachO, Triple("powerpc-apple-macosx").getObjectFormat());
 
   EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
 


        


More information about the cfe-commits mailing list