Skip to content

Commit ab5133b

Browse files
committed
Revert "[Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (#120507)"
This reverts commit 653a547. Breaks tests, see #120507 (comment)
1 parent 5f6b714 commit ab5133b

File tree

13 files changed

+90
-175
lines changed

13 files changed

+90
-175
lines changed

clang/lib/Basic/Targets/OSTargets.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
114114
assert(OsVersion.getMinor().value_or(0) < 100 &&
115115
OsVersion.getSubminor().value_or(0) < 100 && "Invalid version!");
116116
Builder.defineMacro("__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__", Str);
117+
118+
// Tell users about the kernel if there is one.
119+
Builder.defineMacro("__MACH__");
117120
}
118121

119122
PlatformMinVersion = OsVersion;

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6686,8 +6686,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
66866686
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);
66876687
else if (Target.isOSBinFormatELF())
66886688
TC = std::make_unique<toolchains::Generic_ELF>(*this, Target, Args);
6689-
else if (Target.isAppleMachO())
6690-
TC = std::make_unique<toolchains::AppleMachO>(*this, Target, Args);
66916689
else if (Target.isOSBinFormatMachO())
66926690
TC = std::make_unique<toolchains::MachO>(*this, Target, Args);
66936691
else

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,11 @@ MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
966966
getProgramPaths().push_back(getDriver().Dir);
967967
}
968968

969-
AppleMachO::AppleMachO(const Driver &D, const llvm::Triple &Triple,
970-
const ArgList &Args)
971-
: MachO(D, Triple, Args), CudaInstallation(D, Triple, Args),
972-
RocmInstallation(D, Triple, Args), SYCLInstallation(D, Triple, Args) {}
973-
974969
/// Darwin - Darwin tool chain for i386 and x86_64.
975970
Darwin::Darwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
976-
: AppleMachO(D, Triple, Args), TargetInitialized(false) {}
971+
: MachO(D, Triple, Args), TargetInitialized(false),
972+
CudaInstallation(D, Triple, Args), RocmInstallation(D, Triple, Args),
973+
SYCLInstallation(D, Triple, Args) {}
977974

978975
types::ID MachO::LookupTypeForExtension(StringRef Ext) const {
979976
types::ID Ty = ToolChain::LookupTypeForExtension(Ext);
@@ -1022,18 +1019,18 @@ bool Darwin::hasBlocksRuntime() const {
10221019
}
10231020
}
10241021

1025-
void AppleMachO::AddCudaIncludeArgs(const ArgList &DriverArgs,
1026-
ArgStringList &CC1Args) const {
1022+
void Darwin::AddCudaIncludeArgs(const ArgList &DriverArgs,
1023+
ArgStringList &CC1Args) const {
10271024
CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
10281025
}
10291026

1030-
void AppleMachO::AddHIPIncludeArgs(const ArgList &DriverArgs,
1031-
ArgStringList &CC1Args) const {
1027+
void Darwin::AddHIPIncludeArgs(const ArgList &DriverArgs,
1028+
ArgStringList &CC1Args) const {
10321029
RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
10331030
}
10341031

1035-
void AppleMachO::addSYCLIncludeArgs(const ArgList &DriverArgs,
1036-
ArgStringList &CC1Args) const {
1032+
void Darwin::addSYCLIncludeArgs(const ArgList &DriverArgs,
1033+
ArgStringList &CC1Args) const {
10371034
SYCLInstallation->addSYCLIncludeArgs(DriverArgs, CC1Args);
10381035
}
10391036

@@ -1128,8 +1125,6 @@ VersionTuple MachO::getLinkerVersion(const llvm::opt::ArgList &Args) const {
11281125

11291126
Darwin::~Darwin() {}
11301127

1131-
AppleMachO::~AppleMachO() {}
1132-
11331128
MachO::~MachO() {}
11341129

11351130
std::string Darwin::ComputeEffectiveClangTriple(const ArgList &Args,
@@ -2493,7 +2488,7 @@ static void AppendPlatformPrefix(SmallString<128> &Path,
24932488
// Returns the effective sysroot from either -isysroot or --sysroot, plus the
24942489
// platform prefix (if any).
24952490
llvm::SmallString<128>
2496-
AppleMachO::GetEffectiveSysroot(const llvm::opt::ArgList &DriverArgs) const {
2491+
DarwinClang::GetEffectiveSysroot(const llvm::opt::ArgList &DriverArgs) const {
24972492
llvm::SmallString<128> Path("/");
24982493
if (DriverArgs.hasArg(options::OPT_isysroot))
24992494
Path = DriverArgs.getLastArgValue(options::OPT_isysroot);
@@ -2506,9 +2501,8 @@ AppleMachO::GetEffectiveSysroot(const llvm::opt::ArgList &DriverArgs) const {
25062501
return Path;
25072502
}
25082503

2509-
void AppleMachO::AddClangSystemIncludeArgs(
2510-
const llvm::opt::ArgList &DriverArgs,
2511-
llvm::opt::ArgStringList &CC1Args) const {
2504+
void DarwinClang::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
2505+
llvm::opt::ArgStringList &CC1Args) const {
25122506
const Driver &D = getDriver();
25132507

25142508
llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs);
@@ -2586,7 +2580,7 @@ bool DarwinClang::AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverAr
25862580
return getVFS().exists(Base);
25872581
}
25882582

2589-
void AppleMachO::AddClangCXXStdlibIncludeArgs(
2583+
void DarwinClang::AddClangCXXStdlibIncludeArgs(
25902584
const llvm::opt::ArgList &DriverArgs,
25912585
llvm::opt::ArgStringList &CC1Args) const {
25922586
// The implementation from a base class will pass through the -stdlib to
@@ -2643,60 +2637,55 @@ void AppleMachO::AddClangCXXStdlibIncludeArgs(
26432637
}
26442638

26452639
case ToolChain::CST_Libstdcxx:
2646-
AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args);
2647-
break;
2648-
}
2649-
}
2650-
2651-
void AppleMachO::AddGnuCPlusPlusIncludePaths(
2652-
const llvm::opt::ArgList &DriverArgs,
2653-
llvm::opt::ArgStringList &CC1Args) const {}
2654-
2655-
void DarwinClang::AddGnuCPlusPlusIncludePaths(
2656-
const llvm::opt::ArgList &DriverArgs,
2657-
llvm::opt::ArgStringList &CC1Args) const {
2658-
llvm::SmallString<128> UsrIncludeCxx = GetEffectiveSysroot(DriverArgs);
2659-
llvm::sys::path::append(UsrIncludeCxx, "usr", "include", "c++");
2640+
llvm::SmallString<128> UsrIncludeCxx = Sysroot;
2641+
llvm::sys::path::append(UsrIncludeCxx, "usr", "include", "c++");
2642+
2643+
llvm::Triple::ArchType arch = getTriple().getArch();
2644+
bool IsBaseFound = true;
2645+
switch (arch) {
2646+
default: break;
2647+
2648+
case llvm::Triple::x86:
2649+
case llvm::Triple::x86_64:
2650+
IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2651+
"4.2.1",
2652+
"i686-apple-darwin10",
2653+
arch == llvm::Triple::x86_64 ? "x86_64" : "");
2654+
IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2655+
"4.0.0", "i686-apple-darwin8",
2656+
"");
2657+
break;
26602658

2661-
llvm::Triple::ArchType arch = getTriple().getArch();
2662-
bool IsBaseFound = true;
2663-
switch (arch) {
2664-
default:
2665-
break;
2659+
case llvm::Triple::arm:
2660+
case llvm::Triple::thumb:
2661+
IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2662+
"4.2.1",
2663+
"arm-apple-darwin10",
2664+
"v7");
2665+
IsBaseFound |= AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2666+
"4.2.1",
2667+
"arm-apple-darwin10",
2668+
"v6");
2669+
break;
26662670

2667-
case llvm::Triple::x86:
2668-
case llvm::Triple::x86_64:
2669-
IsBaseFound = AddGnuCPlusPlusIncludePaths(
2670-
DriverArgs, CC1Args, UsrIncludeCxx, "4.2.1", "i686-apple-darwin10",
2671-
arch == llvm::Triple::x86_64 ? "x86_64" : "");
2672-
IsBaseFound |= AddGnuCPlusPlusIncludePaths(
2673-
DriverArgs, CC1Args, UsrIncludeCxx, "4.0.0", "i686-apple-darwin8", "");
2674-
break;
2671+
case llvm::Triple::aarch64:
2672+
IsBaseFound = AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx,
2673+
"4.2.1",
2674+
"arm64-apple-darwin10",
2675+
"");
2676+
break;
2677+
}
26752678

2676-
case llvm::Triple::arm:
2677-
case llvm::Triple::thumb:
2678-
IsBaseFound =
2679-
AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, "4.2.1",
2680-
"arm-apple-darwin10", "v7");
2681-
IsBaseFound |=
2682-
AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, "4.2.1",
2683-
"arm-apple-darwin10", "v6");
2684-
break;
2679+
if (!IsBaseFound) {
2680+
getDriver().Diag(diag::warn_drv_libstdcxx_not_found);
2681+
}
26852682

2686-
case llvm::Triple::aarch64:
2687-
IsBaseFound =
2688-
AddGnuCPlusPlusIncludePaths(DriverArgs, CC1Args, UsrIncludeCxx, "4.2.1",
2689-
"arm64-apple-darwin10", "");
26902683
break;
26912684
}
2692-
2693-
if (!IsBaseFound) {
2694-
getDriver().Diag(diag::warn_drv_libstdcxx_not_found);
2695-
}
26962685
}
26972686

2698-
void AppleMachO::AddCXXStdlibLibArgs(const ArgList &Args,
2699-
ArgStringList &CmdArgs) const {
2687+
void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args,
2688+
ArgStringList &CmdArgs) const {
27002689
CXXStdlibType Type = GetCXXStdlibType(Args);
27012690

27022691
switch (Type) {
@@ -3632,7 +3621,7 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
36323621
return Res;
36333622
}
36343623

3635-
void AppleMachO::printVerboseInfo(raw_ostream &OS) const {
3624+
void Darwin::printVerboseInfo(raw_ostream &OS) const {
36363625
CudaInstallation->print(OS);
36373626
RocmInstallation->print(OS);
36383627
}

clang/lib/Driver/ToolChains/Darwin.h

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -291,52 +291,8 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
291291
/// }
292292
};
293293

294-
/// Apple specific MachO extensions
295-
class LLVM_LIBRARY_VISIBILITY AppleMachO : public MachO {
296-
public:
297-
AppleMachO(const Driver &D, const llvm::Triple &Triple,
298-
const llvm::opt::ArgList &Args);
299-
~AppleMachO() override;
300-
301-
/// }
302-
/// @name Apple Specific ToolChain Implementation
303-
/// {
304-
void
305-
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
306-
llvm::opt::ArgStringList &CC1Args) const override;
307-
308-
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
309-
llvm::opt::ArgStringList &CC1Args) const override;
310-
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
311-
llvm::opt::ArgStringList &CC1Args) const override;
312-
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
313-
llvm::opt::ArgStringList &CC1Args) const override;
314-
315-
void AddClangCXXStdlibIncludeArgs(
316-
const llvm::opt::ArgList &DriverArgs,
317-
llvm::opt::ArgStringList &CC1Args) const override;
318-
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
319-
llvm::opt::ArgStringList &CmdArgs) const override;
320-
321-
void printVerboseInfo(raw_ostream &OS) const override;
322-
/// }
323-
324-
LazyDetector<CudaInstallationDetector> CudaInstallation;
325-
LazyDetector<RocmInstallationDetector> RocmInstallation;
326-
LazyDetector<SYCLInstallationDetector> SYCLInstallation;
327-
328-
protected:
329-
llvm::SmallString<128>
330-
GetEffectiveSysroot(const llvm::opt::ArgList &DriverArgs) const;
331-
332-
private:
333-
virtual void
334-
AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
335-
llvm::opt::ArgStringList &CC1Args) const;
336-
};
337-
338294
/// Darwin - The base Darwin tool chain.
339-
class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO {
295+
class LLVM_LIBRARY_VISIBILITY Darwin : public MachO {
340296
public:
341297
/// Whether the information on the target has been initialized.
342298
//
@@ -374,6 +330,10 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO {
374330
/// The target variant triple that was specified (if any).
375331
mutable std::optional<llvm::Triple> TargetVariantTriple;
376332

333+
LazyDetector<CudaInstallationDetector> CudaInstallation;
334+
LazyDetector<RocmInstallationDetector> RocmInstallation;
335+
LazyDetector<SYCLInstallationDetector> SYCLInstallation;
336+
377337
private:
378338
void AddDeploymentTarget(llvm::opt::DerivedArgList &Args) const;
379339

@@ -385,7 +345,7 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO {
385345
std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args,
386346
types::ID InputType) const override;
387347

388-
/// @name Darwin Specific Toolchain Implementation
348+
/// @name Apple Specific Toolchain Implementation
389349
/// {
390350

391351
void addMinVersionArgs(const llvm::opt::ArgList &Args,
@@ -601,6 +561,13 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO {
601561
ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
602562
bool hasBlocksRuntime() const override;
603563

564+
void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
565+
llvm::opt::ArgStringList &CC1Args) const override;
566+
void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
567+
llvm::opt::ArgStringList &CC1Args) const override;
568+
void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
569+
llvm::opt::ArgStringList &CC1Args) const override;
570+
604571
bool UseObjCMixedDispatch() const override {
605572
// This is only used with the non-fragile ABI and non-legacy dispatch.
606573

@@ -631,6 +598,8 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public AppleMachO {
631598
bool SupportsEmbeddedBitcode() const override;
632599

633600
SanitizerMask getSupportedSanitizers() const override;
601+
602+
void printVerboseInfo(raw_ostream &OS) const override;
634603
};
635604

636605
/// DarwinClang - The Darwin toolchain used by Clang.
@@ -648,6 +617,16 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
648617
llvm::opt::ArgStringList &CmdArgs,
649618
bool ForceLinkBuiltinRT = false) const override;
650619

620+
void AddClangCXXStdlibIncludeArgs(
621+
const llvm::opt::ArgList &DriverArgs,
622+
llvm::opt::ArgStringList &CC1Args) const override;
623+
624+
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
625+
llvm::opt::ArgStringList &CC1Args) const override;
626+
627+
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
628+
llvm::opt::ArgStringList &CmdArgs) const override;
629+
651630
void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
652631
llvm::opt::ArgStringList &CmdArgs) const override;
653632

@@ -672,16 +651,15 @@ class LLVM_LIBRARY_VISIBILITY DarwinClang : public Darwin {
672651
StringRef Sanitizer,
673652
bool shared = true) const;
674653

675-
void
676-
AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
677-
llvm::opt::ArgStringList &CC1Args) const override;
678-
679654
bool AddGnuCPlusPlusIncludePaths(const llvm::opt::ArgList &DriverArgs,
680655
llvm::opt::ArgStringList &CC1Args,
681656
llvm::SmallString<128> Base,
682657
llvm::StringRef Version,
683658
llvm::StringRef ArchDir,
684659
llvm::StringRef BitDir) const;
660+
661+
llvm::SmallString<128>
662+
GetEffectiveSysroot(const llvm::opt::ArgList &DriverArgs) const;
685663
};
686664

687665
} // end namespace toolchains

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,11 +1507,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
15071507
// ELF targets define __ELF__
15081508
if (TI.getTriple().isOSBinFormatELF())
15091509
Builder.defineMacro("__ELF__");
1510-
else if (TI.getTriple().isAppleMachO())
1511-
// Apple MachO targets define __MACH__ even when not using DarwinTargetInfo.
1512-
// Hurd will also define this in some circumstances, but that's done in
1513-
// HurdTargetInfo. Windows targets don't define this.
1514-
Builder.defineMacro("__MACH__");
15151510

15161511
// Target OS macro definitions.
15171512
if (PPOpts.DefineTargetOSMacros) {

clang/lib/Lex/InitHeaderSearch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
313313
break;
314314

315315
case llvm::Triple::UnknownOS:
316-
if (triple.isWasm() || triple.isAppleMachO())
316+
if (triple.isWasm())
317317
return false;
318318
break;
319319

clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/include/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/MacOSX15.1.sdk/embedded/usr/local/include/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/include/c++/v1/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/MacOSX15.1.sdk/usr/local/include/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)