aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2025-01-10 19:22:46 +0900
committerNAKAMURA Takumi <geek4civic@gmail.com>2025-01-10 19:22:46 +0900
commit8b02a27fc607ebc54c5a811188b3cea5063564e7 (patch)
treec1ca7d4acca553301204ebb83383aa87cb59311a /clang/lib/Driver/Driver.cpp
parent694a772457b2999b7bd68625a16bf0755e95dcdb (diff)
parent397ac44f623f891d8f05d6673a95984ac0a26671 (diff)
downloadllvm-users/chapuni/cov/merge/mcdcsort.zip
llvm-users/chapuni/cov/merge/mcdcsort.tar.gz
llvm-users/chapuni/cov/merge/mcdcsort.tar.bz2
Merge branch 'main' into users/chapuni/cov/merge/mcdcsortusers/chapuni/cov/merge/mcdcsort
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 36d6c93..528b7d1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1063,6 +1063,34 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
//
}
+bool Driver::loadZOSCustomizationFile(llvm::cl::ExpansionContext &ExpCtx) {
+ if (IsCLMode() || IsDXCMode() || IsFlangMode())
+ return false;
+
+ SmallString<128> CustomizationFile;
+ StringRef PathLIBEnv = StringRef(getenv("CLANG_CONFIG_PATH")).trim();
+ // If the env var is a directory then append "/clang.cfg" and treat
+ // that as the config file. Otherwise treat the env var as the
+ // config file.
+ if (!PathLIBEnv.empty()) {
+ llvm::sys::path::append(CustomizationFile, PathLIBEnv);
+ if (llvm::sys::fs::is_directory(PathLIBEnv))
+ llvm::sys::path::append(CustomizationFile, "/clang.cfg");
+ if (llvm::sys::fs::is_regular_file(CustomizationFile))
+ return readConfigFile(CustomizationFile, ExpCtx);
+ Diag(diag::err_drv_config_file_not_found) << CustomizationFile;
+ return true;
+ }
+
+ SmallString<128> BaseDir(llvm::sys::path::parent_path(Dir));
+ llvm::sys::path::append(CustomizationFile, BaseDir + "/etc/clang.cfg");
+ if (llvm::sys::fs::is_regular_file(CustomizationFile))
+ return readConfigFile(CustomizationFile, ExpCtx);
+
+ // If no customization file, just return
+ return false;
+}
+
static void appendOneArg(InputArgList &Args, const Arg *Opt) {
// The args for config files or /clang: flags belong to different InputArgList
// objects than Args. This copies an Arg from one of those other InputArgLists
@@ -1284,11 +1312,18 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
}
// Otherwise, use the real triple as used by the driver.
+ llvm::Triple RealTriple =
+ computeTargetTriple(*this, TargetTriple, *CLOptions);
if (Triple.str().empty()) {
- Triple = computeTargetTriple(*this, TargetTriple, *CLOptions);
+ Triple = RealTriple;
assert(!Triple.str().empty());
}
+ // On z/OS, start by loading the customization file before loading
+ // the usual default config file(s).
+ if (RealTriple.isOSzOS() && loadZOSCustomizationFile(ExpCtx))
+ return true;
+
// Search for config files in the following order:
// 1. <triple>-<mode>.cfg using real driver mode
// (e.g. i386-pc-linux-gnu-clang++.cfg).
@@ -6686,6 +6721,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);
else if (Target.isOSBinFormatELF())
TC = std::make_unique<toolchains::Generic_ELF>(*this, Target, Args);
+ else if (Target.isAppleMachO())
+ TC = std::make_unique<toolchains::AppleMachO>(*this, Target, Args);
else if (Target.isOSBinFormatMachO())
TC = std::make_unique<toolchains::MachO>(*this, Target, Args);
else