Skip to content

Commit 62ce88f

Browse files
committed
[clang] Enhance handling of Apple-specific -arch/-target option values
The -arch option itself is Apple-specific, so, if -target is not passed explicitely, we try to construct an Apple triple. If the default triple is Apple-specific, we just update it's arch so it matches the one passed via -arch option, otherwise, we construct a triple "from scratch". The arm64e arch value is also Apple-specific, so, if a computed triple has empty vendor name and/or OS and environment name, fill them correspondingly.
1 parent 5242044 commit 62ce88f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,41 @@ static llvm::Triple computeTargetTriple(const Driver &D,
521521
if (TargetTriple.contains("-unknown-gnu") || TargetTriple.contains("-pc-gnu"))
522522
Target.setOSName("hurd");
523523

524+
// Since -arch is an Apple-specific option, construct an Apple triple when
525+
// -target is not explicitely passed.
526+
if (Args.hasArg(options::OPT_arch) && !Args.hasArg(options::OPT_target)) {
527+
if (Target.isOSBinFormatMachO()) {
528+
// The default triple is already Apple-specific - just update the arch.
529+
Target.setArchName(Args.getLastArg(options::OPT_arch)->getValue());
530+
} else {
531+
// The default triple is not Apple-specific - construct a new one to avoid
532+
// handling unrelated info from the default one (e.g. environment).
533+
Target = llvm::Triple(llvm::Triple::normalize(
534+
Args.getLastArg(options::OPT_arch)->getValue()));
535+
Target.setVendor(llvm::Triple::Apple);
536+
// -fobjc-arc is not supported on versions of OS X prior to 10.6
537+
if (Args.hasArg(options::OPT_fobjc_arc))
538+
Target.setOSName("macosx10.6.0");
539+
else
540+
Target.setOS(llvm::Triple::Darwin);
541+
}
542+
}
543+
544+
// Since arm64e arch is Apple-specific, set VendorName and OS correspondingly
545+
// if not set already.
546+
if (!Args.hasArg(options::OPT_arch) && Target.getArchName() == "arm64e" &&
547+
!Target.isOSBinFormatMachO()) {
548+
if (Target.getVendorName().empty())
549+
Target.setVendor(llvm::Triple::Apple);
550+
if (Target.getOSAndEnvironmentName().empty()) {
551+
// -fobjc-arc is not supported on versions of OS X prior to 10.6
552+
if (Args.hasArg(options::OPT_fobjc_arc))
553+
Target.setOSName("macosx10.6.0");
554+
else
555+
Target.setOS(llvm::Triple::Darwin);
556+
}
557+
}
558+
524559
// Handle Apple-specific options available here.
525560
if (Target.isOSBinFormatMachO()) {
526561
// If an explicit Darwin arch name is given, that trumps all.

0 commit comments

Comments
 (0)