Skip to content

Commit 9f77fac

Browse files
committed
[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
1 parent 97fe519 commit 9f77fac

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang/test/Driver/unsupported-target-arch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,7 @@
5959
// RUN: not %clang --target=thumbeb-none-elf -o %t.o %s 2> %t.err
6060
// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-THUMBEB-INVALID-ENV %s
6161
// 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]{{$}}
62+
63+
// RUN: not %clang --target=powerpc-apple-darwin -o /dev/null %s 2> %t.err
64+
// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-PPCMAC %s
65+
// CHECK-PPCMAC: error: unknown target triple 'unknown-apple-macosx10.4.0'{{$}}

llvm/lib/TargetParser/Triple.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,8 @@ static Triple::SubArchType parseSubArch(StringRef SubArchName) {
782782
}
783783

784784
static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
785+
if (T.isOSDarwin())
786+
return Triple::MachO;
785787
switch (T.getArch()) {
786788
case Triple::UnknownArch:
787789
case Triple::aarch64:
@@ -790,9 +792,7 @@ static Triple::ObjectFormatType getDefaultFormat(const Triple &T) {
790792
case Triple::thumb:
791793
case Triple::x86:
792794
case Triple::x86_64:
793-
if (T.isOSDarwin())
794-
return Triple::MachO;
795-
else if (T.isOSWindows())
795+
if (T.isOSWindows())
796796
return Triple::COFF;
797797
return Triple::ELF;
798798

llvm/unittests/TargetParser/TripleTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,7 @@ TEST(TripleTest, FileFormat) {
18011801
EXPECT_EQ(Triple::MachO, Triple("i686-apple-macosx").getObjectFormat());
18021802
EXPECT_EQ(Triple::MachO, Triple("i686-apple-ios").getObjectFormat());
18031803
EXPECT_EQ(Triple::MachO, Triple("i686---macho").getObjectFormat());
1804+
EXPECT_EQ(Triple::MachO, Triple("powerpc-apple-macosx").getObjectFormat());
18041805

18051806
EXPECT_EQ(Triple::COFF, Triple("i686--win32").getObjectFormat());
18061807

0 commit comments

Comments
 (0)