[clang] [lldb] [llvm] [lldb] Fix object format in the Triple of Mach-O files (approach 4) (PR #145157)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 21 04:03:58 PDT 2025
https://github.com/royitaqi updated https://github.com/llvm/llvm-project/pull/145157
>From a9931d429fd9e4d89da938e74f84a2b9f7da48de Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 20 Jun 2025 11:58:03 -0700
Subject: [PATCH 1/6] Change api
---
llvm/include/llvm/TargetParser/Triple.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 7fd5278f1ed53..56dfae61c2423 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -461,7 +461,9 @@ class Triple {
/// @name Direct Component Access
/// @{
- const std::string &str() const { return Data; }
+ // const std::string &str() const { return Data; }
+
+ const std::string &str(bool includeObjectFormat) const { return Data; }
const std::string &getTriple() const { return Data; }
>From 1e11372ff3099ccd599191579aebf94531cc6592 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 20 Jun 2025 11:58:20 -0700
Subject: [PATCH 2/6] Fix compilation errors
---
clang/include/clang/Driver/ToolChain.h | 2 +-
clang/lib/Basic/Targets.cpp | 2 +-
clang/lib/CodeGen/CodeGenAction.cpp | 2 +-
clang/lib/Driver/Driver.cpp | 36 +++++++++----------
clang/lib/Driver/OffloadBundler.cpp | 2 +-
clang/lib/Driver/SanitizerArgs.cpp | 10 +++---
clang/lib/Driver/ToolChain.cpp | 10 +++---
clang/lib/Driver/ToolChains/AMDGPU.h | 2 +-
clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 6 ++--
clang/lib/Driver/ToolChains/Clang.cpp | 14 ++++----
clang/lib/Driver/ToolChains/CommonArgs.cpp | 14 ++++----
clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +-
clang/lib/Driver/ToolChains/Cygwin.cpp | 2 +-
clang/lib/Driver/ToolChains/Flang.cpp | 2 +-
clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +-
clang/lib/Driver/ToolChains/Gnu.cpp | 22 ++++++------
clang/lib/Driver/ToolChains/Hurd.cpp | 4 +--
clang/lib/Driver/ToolChains/Linux.cpp | 16 ++++-----
clang/lib/Driver/ToolChains/MinGW.cpp | 14 ++++----
clang/lib/Driver/ToolChains/OHOS.cpp | 4 +--
clang/lib/Driver/ToolChains/PS4CPU.cpp | 6 ++--
.../lib/Driver/ToolChains/RISCVToolchain.cpp | 6 ++--
clang/lib/Driver/ToolChains/SYCL.cpp | 2 +-
clang/lib/Driver/ToolChains/Solaris.cpp | 2 +-
clang/lib/Driver/XRayArgs.cpp | 8 ++---
clang/lib/Frontend/CompilerInstance.cpp | 2 +-
clang/lib/Frontend/CompilerInvocation.cpp | 28 +++++++--------
.../InterfaceStubFunctionsConsumer.cpp | 2 +-
clang/lib/Sema/Sema.cpp | 10 +++---
clang/lib/Sema/SemaExprCXX.cpp | 2 +-
clang/lib/Sema/SemaPPC.cpp | 2 +-
clang/lib/Sema/SemaStmt.cpp | 2 +-
lldb/source/API/SBDebugger.cpp | 2 +-
lldb/source/API/SBModule.cpp | 2 +-
lldb/source/API/SBModuleSpec.cpp | 2 +-
lldb/source/API/SBTarget.cpp | 2 +-
lldb/source/Core/Module.cpp | 4 +--
.../DynamicLoaderDarwinKernel.cpp | 2 +-
.../DynamicLoaderFreeBSDKernel.cpp | 2 +-
.../Clang/ClangExpressionParser.cpp | 2 +-
.../Clang/ClangModulesDeclVendor.cpp | 2 +-
.../Clang/CppModuleConfiguration.cpp | 8 ++---
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 2 +-
.../gdb-server/PlatformRemoteGDBServer.cpp | 2 +-
.../TypeSystem/Clang/TypeSystemClang.cpp | 6 ++--
lldb/source/Target/Platform.cpp | 2 +-
lldb/source/Target/Statistics.cpp | 2 +-
llvm/lib/AsmParser/LLParser.cpp | 2 +-
llvm/lib/BinaryFormat/MachO.cpp | 2 +-
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 +--
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp | 8 ++---
llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 4 +--
.../RuntimeDyld/RuntimeDyldChecker.cpp | 2 +-
llvm/lib/IR/AsmWriter.cpp | 2 +-
llvm/lib/IR/Core.cpp | 2 +-
llvm/lib/LTO/LTO.cpp | 2 +-
llvm/lib/LTO/LTOCodeGenerator.cpp | 2 +-
llvm/lib/Linker/IRMover.cpp | 4 +--
llvm/lib/MC/TargetRegistry.cpp | 2 +-
llvm/lib/Object/IRObjectFile.cpp | 2 +-
llvm/lib/Object/IRSymtab.cpp | 2 +-
llvm/lib/Object/ModuleSymbolTable.cpp | 6 ++--
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 2 +-
llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 2 +-
llvm/lib/Target/SPIRV/SPIRVSubtarget.h | 2 +-
llvm/lib/Target/TargetMachineC.cpp | 2 +-
llvm/lib/TargetParser/Host.cpp | 2 +-
llvm/lib/TargetParser/Triple.cpp | 4 +--
llvm/lib/TargetParser/Unix/Host.inc | 2 +-
70 files changed, 173 insertions(+), 173 deletions(-)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index b8899e78176b4..6538fed73c20f 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -653,7 +653,7 @@ class ToolChain {
virtual std::string getMultiarchTriple(const Driver &D,
const llvm::Triple &TargetTriple,
StringRef SysRoot) const {
- return TargetTriple.str();
+ return TargetTriple.str(false);
}
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 9889141ad2085..757d07e3ac87c 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -783,7 +783,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
// Construct the target
std::unique_ptr<TargetInfo> Target = AllocateTarget(Triple, *Opts);
if (!Target) {
- Diags.Report(diag::err_target_unknown_triple) << Triple.str();
+ Diags.Report(diag::err_target_unknown_triple) << Triple.str(false);
return nullptr;
}
Target->TargetOpts = Opts;
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 1f5eb427b566f..bc30023dd56fb 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1133,7 +1133,7 @@ void CodeGenAction::ExecuteAction() {
return;
const TargetOptions &TargetOpts = CI.getTargetOpts();
- if (TheModule->getTargetTriple().str() != TargetOpts.Triple) {
+ if (TheModule->getTargetTriple().str(false) != TargetOpts.Triple) {
Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
<< TargetOpts.Triple;
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 73ff7757c3b04..f0fc93fe6a36f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -144,7 +144,7 @@ getNVIDIAOffloadTargetTriple(const Driver &D, const ArgList &Args,
D.Diag(diag::err_drv_cuda_offload_only_emit_bc);
return std::nullopt;
}
- D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str();
+ D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str(false);
return std::nullopt;
}
@@ -165,7 +165,7 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList &Args) {
return TT;
if (TT->getArch() == llvm::Triple::spirv64)
return TT;
- D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str();
+ D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str(false);
return std::nullopt;
}
@@ -714,13 +714,13 @@ static llvm::Triple computeTargetTriple(const Driver &D,
// Currently the only architecture supported by *-uefi triples are x86_64.
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
- D.Diag(diag::err_target_unknown_triple) << Target.str();
+ D.Diag(diag::err_target_unknown_triple) << Target.str(false);
// The `-maix[32|64]` flags are only valid for AIX targets.
if (Arg *A = Args.getLastArgNoClaim(options::OPT_maix32, options::OPT_maix64);
A && !Target.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << Target.str();
+ << A->getAsString(Args) << Target.str(false);
// Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'.
Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
@@ -748,7 +748,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
A->getOption().matches(options::OPT_maix32)) {
if (D.IsFlangMode() && !Target.isOSAIX()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << Target.str();
+ << A->getAsString(Args) << Target.str(false);
} else {
AT = Target.get32BitArchVariant().getArch();
if (Target.getEnvironment() == llvm::Triple::GNUX32)
@@ -779,7 +779,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false)) {
if (Target.get32BitArchVariant().getArch() != llvm::Triple::x86)
D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu"
- << Target.str();
+ << Target.str(false);
if (A && !A->getOption().matches(options::OPT_m32))
D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -1361,7 +1361,7 @@ static bool findTripleConfigFile(llvm::cl::ExpansionContext &ExpCtx,
SmallString<128> &ConfigFilePath,
llvm::Triple Triple, std::string Suffix) {
// First, try the full unmodified triple.
- if (ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath))
+ if (ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath))
return true;
// Don't continue if we didn't find a parsable version in the triple.
@@ -1375,14 +1375,14 @@ static bool findTripleConfigFile(llvm::cl::ExpansionContext &ExpCtx,
// e.g. arm64-apple-darwin23.6.0 -> arm64-apple-darwin23
if (OSVersion.getMajor() != 0) {
Triple.setOSName(BaseOSName + llvm::utostr(OSVersion.getMajor()));
- if (ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath))
+ if (ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath))
return true;
}
// Finally, try without any version suffix at all.
// e.g. arm64-apple-darwin23.6.0 -> arm64-apple-darwin
Triple.setOSName(BaseOSName);
- return ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath);
+ return ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath);
}
bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
@@ -1402,7 +1402,7 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
// and the name prefix is not a valid triple, force it for backwards
// compatibility.
if (!ClangNameParts.TargetPrefix.empty() &&
- computeTargetTriple(*this, "/invalid/", *CLOptions).str() ==
+ computeTargetTriple(*this, "/invalid/", *CLOptions).str(false) ==
"/invalid/") {
llvm::Triple PrefixTriple{ClangNameParts.TargetPrefix};
if (PrefixTriple.getArch() == llvm::Triple::UnknownArch ||
@@ -1413,9 +1413,9 @@ 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()) {
+ if (Triple.str(false).empty()) {
Triple = RealTriple;
- assert(!Triple.str().empty());
+ assert(!Triple.str(false).empty());
}
// On z/OS, start by loading the customization file before loading
@@ -1582,7 +1582,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
T.setObjectFormat(llvm::Triple::COFF);
if (Args.hasArg(options::OPT__SLASH_arm64EC))
T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
- TargetTriple = T.str();
+ TargetTriple = T.str(false);
} else if (IsDXCMode()) {
// Build TargetTriple from target_profile option for clang-dxc.
if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) {
@@ -1617,7 +1617,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
A->claim();
}
- TargetTriple = T.str();
+ TargetTriple = T.str(false);
}
} else {
Diag(diag::err_drv_dxc_missing_target_profile);
@@ -1770,7 +1770,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) &&
UArgs->hasArg(options::OPT__SLASH_arm64EC)) {
getDiags().Report(clang::diag::warn_target_override_arm64ec)
- << TC.getTriple().str();
+ << TC.getTriple().str(false);
}
// A common user mistake is specifying a target of aarch64-none-eabi or
@@ -6715,8 +6715,8 @@ const ToolChain &Driver::getOffloadToolChain(
const llvm::opt::ArgList &Args, const Action::OffloadKind Kind,
const llvm::Triple &Target, const llvm::Triple &AuxTarget) const {
std::unique_ptr<ToolChain> &TC =
- ToolChains[Target.str() + "/" + AuxTarget.str()];
- std::unique_ptr<ToolChain> &HostTC = ToolChains[AuxTarget.str()];
+ ToolChains[Target.str(false) + "/" + AuxTarget.str(false)];
+ std::unique_ptr<ToolChain> &HostTC = ToolChains[AuxTarget.str(false)];
assert(HostTC && "Host toolchain for offloading doesn't exit?");
if (!TC) {
@@ -6781,7 +6781,7 @@ const ToolChain &Driver::getOffloadToolChain(
const ToolChain &Driver::getToolChain(const ArgList &Args,
const llvm::Triple &Target) const {
- auto &TC = ToolChains[Target.str()];
+ auto &TC = ToolChains[Target.str(false)];
if (!TC) {
switch (Target.getOS()) {
case llvm::Triple::AIX:
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 3dfd51ee2365a..8bbe47decaa0f 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -135,7 +135,7 @@ bool OffloadTargetInfo::isOffloadKindCompatible(
}
bool OffloadTargetInfo::isTripleValid() const {
- return !Triple.str().empty() && Triple.getArch() != Triple::UnknownArch;
+ return !Triple.str(false).empty() && Triple.getArch() != Triple::UnknownArch;
}
bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index eb4718909c951..c94d9ae735473 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -500,7 +500,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
<< Desc << A->getAsString(Args);
else
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << Desc << Triple.str();
+ << Desc << Triple.str(false);
}
DiagnosedKinds |= KindsToDiagnose;
}
@@ -530,7 +530,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
if (DiagnoseErrors) {
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << Desc << TC.getTriple().str();
+ << Desc << TC.getTriple().str(false);
}
DiagnosedKinds |= KindsToDiagnose;
}
@@ -700,7 +700,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
S.Mask = KindsToDiagnose;
if (DiagnoseErrors)
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str();
+ << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str(false);
Kinds &= ~KindsToDiagnose;
}
}
@@ -1013,7 +1013,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
Arg *A =
Args.getLastArg(options::OPT_shared_libsan, options::OPT_static_libsan);
D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << TC.getTriple().str();
+ << A->getSpelling() << TC.getTriple().str(false);
}
ImplicitCfiRuntime = TC.getTriple().isAndroid();
@@ -1434,7 +1434,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
if (KcfiArity) {
if (!TC.getTriple().isOSLinux() || !TC.getTriple().isArch64Bit()) {
TC.getDriver().Diag(clang::diag::err_drv_kcfi_arity_unsupported_target)
- << TC.getTriple().str();
+ << TC.getTriple().str(false);
}
CmdArgs.push_back("-fsanitize-kcfi-arity");
}
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index f2911713668ae..3f30f39461f4a 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -342,7 +342,7 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
std::vector<std::string> Result;
const llvm::Triple Triple(ComputeEffectiveClangTriple(Args));
- Result.push_back("--target=" + Triple.str());
+ Result.push_back("--target=" + Triple.str(false));
switch (Triple.getArch()) {
case llvm::Triple::aarch64:
@@ -871,7 +871,7 @@ std::optional<std::string>
ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const {
llvm::Triple TripleWithoutLevel(getTriple());
TripleWithoutLevel.setEnvironmentName("android"); // remove any version number
- const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
+ const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str(false);
unsigned TripleVersion = getTriple().getEnvironmentVersion().getMajor();
unsigned BestVersion = 0;
@@ -923,7 +923,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
auto getPathForTriple =
[&](const llvm::Triple &Triple) -> std::optional<std::string> {
SmallString<128> P(BaseDir);
- llvm::sys::path::append(P, Triple.str());
+ llvm::sys::path::append(P, Triple.str(false));
if (getVFS().exists(P))
return std::string(P);
return {};
@@ -992,7 +992,7 @@ std::optional<std::string> ToolChain::getRuntimePath() const {
if (Triple.isOSDarwin())
return {};
- llvm::sys::path::append(P, Triple.str());
+ llvm::sys::path::append(P, Triple.str(false));
return std::string(P);
}
@@ -1019,7 +1019,7 @@ ToolChain::path_list ToolChain::getArchSpecificLibPaths() const {
Paths.push_back(std::string(Path));
};
- AddPath({getTriple().str()});
+ AddPath({getTriple().str(false)});
AddPath({getOSLibName(), llvm::Triple::getArchTypeName(getArch())});
return Paths;
}
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 08bd4fa556f78..40f5f943b3a09 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -163,7 +163,7 @@ class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
parseSanitizerValue(A->getValue(), /*Allow Groups*/ false);
if (K != SanitizerKind::Address)
Diags.Report(clang::diag::warn_drv_unsupported_option_for_target)
- << A->getAsString(Args) << getTriple().str();
+ << A->getAsString(Args) << getTriple().str(false);
}
}
};
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index e944cba0eb23c..83fc5c88be018 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -48,7 +48,7 @@ CSKYToolChain::CSKYToolChain(const Driver &D, const llvm::Triple &Triple,
// Multilib cross-compiler GCC installations put ld in a triple-prefixed
// directory off of the parent of the GCC installation.
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str() + "/bin")
+ GCCInstallation.getTriple().str(false) + "/bin")
.str());
PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
getFilePaths().push_back(computeSysRoot() + "/lib" +
@@ -98,7 +98,7 @@ void CSKYToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const GCCVersion &Version = GCCInstallation.getVersion();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
const Multilib &Multilib = GCCInstallation.getMultilib();
addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
TripleStr, Multilib.includeSuffix(), DriverArgs,
@@ -112,7 +112,7 @@ std::string CSKYToolChain::computeSysRoot() const {
SmallString<128> SysRootDir;
if (GCCInstallation.isValid()) {
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
} else {
// Use the triple as provided to the driver. Unlike the parsed triple
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 80dd72a23a673..8ac3abbfc74cd 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,7 +579,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
if (TC.getTriple().isOSAIX()) {
if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
+ << ProfileSampleUseArg->getSpelling() << TC.getTriple().str(false);
}
if (ProfileGenerateArg) {
@@ -2137,7 +2137,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
if (VecExtabi) {
if (!T.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-mabi=vec-extabi" << T.str();
+ << "-mabi=vec-extabi" << T.str(false);
CmdArgs.push_back("-mabi=vec-extabi");
}
@@ -5746,7 +5746,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< (NoPICDataIsTextRelative ? "-mno-pic-data-is-text-relative"
: "-mpic-data-is-text-relative")
- << RawTriple.str();
+ << RawTriple.str(false);
}
bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
@@ -5868,7 +5868,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
if (!Triple.isOSAIX() || Triple.isPPC32())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str();
+ << A->getSpelling() << RawTriple.str(false);
CmdArgs.push_back("-mabi=quadword-atomics");
}
@@ -5877,7 +5877,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// support for 128-bit long double is available for AIX.
if (Triple.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str();
+ << A->getSpelling() << RawTriple.str(false);
}
if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
@@ -5906,7 +5906,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_msvr4_struct_return)) {
if (!TC.getTriple().isPPC32()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str();
+ << A->getSpelling() << RawTriple.str(false);
} else if (A->getOption().matches(options::OPT_maix_struct_return)) {
CmdArgs.push_back("-maix-struct-return");
} else {
@@ -5919,7 +5919,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_freg_struct_return)) {
if (TC.getArch() != llvm::Triple::x86) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str();
+ << A->getSpelling() << RawTriple.str(false);
} else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
CmdArgs.push_back("-fpcc-struct-return");
} else {
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 937ee09cac7cc..fc125992e1608 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1089,7 +1089,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
StringRef OptStr = HasRoptr ? "-mxcoff-roptr" : "-mno-xcoff-roptr";
if (!IsOSAIX)
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << OptStr << Triple.str();
+ << OptStr << Triple.str(false);
if (HasRoptr) {
// The data sections option is on by default on AIX. We only need to error
@@ -1636,7 +1636,7 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
if (SanArgs.hasMemTag()) {
if (!TC.getTriple().isAndroid()) {
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fsanitize=memtag*" << TC.getTriple().str();
+ << "-fsanitize=memtag*" << TC.getTriple().str(false);
}
CmdArgs.push_back(
Args.MakeArgString("--android-memtag-mode=" + SanArgs.getMemtagMode()));
@@ -1889,7 +1889,7 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
options::OPT_fPIE, options::OPT_fpie)) {
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastPICArg->getSpelling() << Triple.str();
+ << LastPICArg->getSpelling() << Triple.str(false);
if (Triple.getArch() == llvm::Triple::x86_64)
return std::make_tuple(llvm::Reloc::PIC_, 2U, false);
return std::make_tuple(llvm::Reloc::Static, 0U, false);
@@ -1941,7 +1941,7 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
// uses it, and it isn't even valid on any OS but Darwin.
if (!Triple.isOSDarwin())
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << Triple.str();
+ << A->getSpelling() << Triple.str(false);
// FIXME: Warn when this flag trumps some other PIC or PIE flag.
@@ -1971,14 +1971,14 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
if (!EmbeddedPISupported)
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastROPIArg->getSpelling() << Triple.str();
+ << LastROPIArg->getSpelling() << Triple.str(false);
ROPI = true;
}
Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
if (!EmbeddedPISupported)
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastRWPIArg->getSpelling() << Triple.str();
+ << LastRWPIArg->getSpelling() << Triple.str(false);
RWPI = true;
}
@@ -2131,7 +2131,7 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
DwarfVersion = N;
if (DwarfVersion == 5 && TC.getTriple().isOSAIX())
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << GDwarfN->getSpelling() << TC.getTriple().str();
+ << GDwarfN->getSpelling() << TC.getTriple().str(false);
}
if (DwarfVersion == 0) {
DwarfVersion = TC.GetDefaultDwarfVersion();
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 3c5dfba329cf8..2246636054bdc 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,7 @@ void tools::CrossWindows::Linker::ConstructJob(
CmdArgs.push_back("-m");
switch (TC.getArch()) {
default:
- D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+ D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str(false);
break;
case llvm::Triple::arm:
case llvm::Triple::thumb:
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index f0e90deee98b3..628c5db4d8291 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -93,7 +93,7 @@ void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// On systems using multiarch, add /usr/include/$triple before
// /usr/include.
- std::string MultiarchIncludeDir = getTriple().str();
+ std::string MultiarchIncludeDir = getTriple().str(false);
if (!MultiarchIncludeDir.empty() &&
D.getVFS().exists(SysRoot + "/usr/include/" + MultiarchIncludeDir))
addExternCSystemInclude(DriverArgs, CC1Args,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index dcc46469df3e9..a29ec15e888d1 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -270,7 +270,7 @@ void Flang::AddPPCTargetArgs(const ArgList &Args,
if (VecExtabi) {
if (!T.isOSAIX()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-mabi=vec-extabi" << T.str();
+ << "-mabi=vec-extabi" << T.str(false);
}
CmdArgs.push_back("-mabi=vec-extabi");
}
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 910db1dde0d18..80b26d5272f39 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -331,7 +331,7 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
types::ID InputType) const {
llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
- return Triple.str();
+ return Triple.str(false);
}
Tool *Fuchsia::buildLinker() const { return new tools::fuchsia::Linker(*this); }
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index e42cd0f97cb49..5a1795d3848ef 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -416,7 +416,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-m");
CmdArgs.push_back(LDMOption);
} else {
- D.Diag(diag::err_target_unknown_triple) << Triple.str();
+ D.Diag(diag::err_target_unknown_triple) << Triple.str(false);
return;
}
@@ -2171,7 +2171,7 @@ void Generic_GCC::GCCInstallationDetector::init(
SmallVector<StringRef, 16> CandidateTripleAliases;
SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
// Add some triples that we want to check first.
- CandidateTripleAliases.push_back(TargetTriple.str());
+ CandidateTripleAliases.push_back(TargetTriple.str(false));
std::string TripleNoVendor, BiarchTripleNoVendor;
if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
@@ -2255,7 +2255,7 @@ void Generic_GCC::GCCInstallationDetector::init(
// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
// triple x86_64-gentoo-linux-gnu is present.
- GentooTestTriples.push_back(TargetTriple.str());
+ GentooTestTriples.push_back(TargetTriple.str(false));
GentooTestTriples.append(CandidateTripleAliases.begin(),
CandidateTripleAliases.end());
if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
@@ -2815,8 +2815,8 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
}
// Also include the multiarch variant if it's different.
- if (TargetTriple.str() != BiarchTriple.str())
- BiarchTripleAliases.push_back(BiarchTriple.str());
+ if (TargetTriple.str(false) != BiarchTriple.str(false))
+ BiarchTripleAliases.push_back(BiarchTriple.str(false));
}
bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
@@ -3108,7 +3108,7 @@ void Generic_GCC::PushPPaths(ToolChain::path_list &PPaths) {
// used to target i386.
if (GCCInstallation.isValid()) {
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str() + "/bin")
+ GCCInstallation.getTriple().str(false) + "/bin")
.str());
}
}
@@ -3161,7 +3161,7 @@ void Generic_GCC::AddMultilibPaths(const Driver &D,
// Note that this matches the GCC behavior. See the below comment for where
// Clang diverges from GCC's behavior.
addPathIfExists(D,
- LibPath + "/../" + GCCTriple.str() + "/lib/../" + OSLibDir +
+ LibPath + "/../" + GCCTriple.str(false) + "/lib/../" + OSLibDir +
SelectedMultilibs.back().osSuffix(),
Paths);
@@ -3189,7 +3189,7 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D,
const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
const Multilib &Multilib = GCCInstallation.getMultilib();
addPathIfExists(
- D, LibPath + "/../" + GCCTriple.str() + "/lib" + Multilib.osSuffix(),
+ D, LibPath + "/../" + GCCTriple.str(false) + "/lib" + Multilib.osSuffix(),
Paths);
}
}
@@ -3203,7 +3203,7 @@ void Generic_GCC::AddMultilibIncludeArgs(const ArgList &DriverArgs,
const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
std::string LibPath(GCCInstallation.getParentLibPath());
addSystemInclude(DriverArgs, CC1Args,
- Twine(LibPath) + "/../" + GCCTriple.str() + "/include");
+ Twine(LibPath) + "/../" + GCCTriple.str(false) + "/include");
const auto &Callback = Multilibs.includeDirsCallback();
if (Callback) {
@@ -3334,7 +3334,7 @@ bool Generic_GCC::addGCCLibStdCxxIncludePaths(
// equivalent to '/usr/include/c++/X.Y' in almost all cases.
StringRef LibDir = GCCInstallation.getParentLibPath();
StringRef InstallDir = GCCInstallation.getInstallPath();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
const Multilib &Multilib = GCCInstallation.getMultilib();
const GCCVersion &Version = GCCInstallation.getVersion();
@@ -3389,7 +3389,7 @@ Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
if (GCCInstallation.isValid()) {
addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args,
- GCCInstallation.getTriple().str());
+ GCCInstallation.getTriple().str(false));
}
}
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 0bc114b90ffc0..3fccd174db006 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -49,7 +49,7 @@ std::string Hurd::getMultiarchTriple(const Driver &D,
// For most architectures, just use whatever we have rather than trying to be
// clever.
- return TargetTriple.str();
+ return TargetTriple.str(false);
}
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
@@ -207,7 +207,7 @@ void Hurd::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
if (!GCCInstallation.isValid())
return;
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
StringRef DebianMultiarch =
GCCInstallation.getTriple().getArch() == llvm::Triple::x86 ? "i386-gnu"
: TripleStr;
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 19919cf5136d8..79e67a9270123 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -101,12 +101,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
} else if (TargetTriple.isMusl()) {
Libc = "musl";
} else {
- return TargetTriple.str();
+ return TargetTriple.str(false);
}
switch (TargetEnvironment) {
default:
- return TargetTriple.str();
+ return TargetTriple.str(false);
case llvm::Triple::GNUSF:
case llvm::Triple::MuslSF:
FPFlavor = "sf";
@@ -174,7 +174,7 @@ std::string Linux::getMultiarchTriple(const Driver &D,
case llvm::Triple::systemz:
return "s390x-linux-gnu";
}
- return TargetTriple.str();
+ return TargetTriple.str(false);
}
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
@@ -406,7 +406,7 @@ std::string Linux::computeSysRoot() const {
// $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
// Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" +
- GCCInstallation.getTriple().str() + "/libc")
+ GCCInstallation.getTriple().str(false) + "/libc")
.str();
if (getVFS().exists(Path))
return Path;
@@ -421,7 +421,7 @@ std::string Linux::computeSysRoot() const {
// variants.
const StringRef InstallDir = GCCInstallation.getInstallPath();
- const StringRef TripleStr = GCCInstallation.getTriple().str();
+ const StringRef TripleStr = GCCInstallation.getTriple().str(false);
const Multilib &Multilib = GCCInstallation.getMultilib();
std::string Path =
@@ -620,7 +620,7 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
if (Distro == Distro::Exherbo &&
(Triple.getVendor() == llvm::Triple::UnknownVendor ||
Triple.getVendor() == llvm::Triple::PC))
- return "/usr/" + Triple.str() + "/lib/" + Loader;
+ return "/usr/" + Triple.str(false) + "/lib/" + Loader;
return "/" + LibDir + "/" + Loader;
}
@@ -694,7 +694,7 @@ void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
return;
// Detect Debian g++-multiarch-incdir.diff.
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
StringRef DebianMultiarch =
GCCInstallation.getTriple().getArch() == llvm::Triple::x86
? "i386-linux-gnu"
@@ -756,7 +756,7 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
CC1Args.push_back("-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(
GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str() + "/include"));
+ GCCInstallation.getTriple().str(false) + "/include"));
}
}
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 2245b036b8459..8b7150441d281 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -141,7 +141,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("mipspe");
break;
default:
- D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
+ D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str(false);
}
Arg *SubsysArg =
@@ -414,8 +414,8 @@ static llvm::Triple getLiteralTriple(const Driver &D, const llvm::Triple &T) {
void toolchains::MinGW::findGccLibDir(const llvm::Triple &LiteralTriple) {
llvm::SmallVector<llvm::SmallString<32>, 5> SubdirNames;
- SubdirNames.emplace_back(LiteralTriple.str());
- SubdirNames.emplace_back(getTriple().str());
+ SubdirNames.emplace_back(LiteralTriple.str(false));
+ SubdirNames.emplace_back(getTriple().str(false));
SubdirNames.emplace_back(getTriple().getArchName());
SubdirNames.back() += "-w64-mingw32";
SubdirNames.emplace_back(getTriple().getArchName());
@@ -442,9 +442,9 @@ void toolchains::MinGW::findGccLibDir(const llvm::Triple &LiteralTriple) {
static llvm::ErrorOr<std::string> findGcc(const llvm::Triple &LiteralTriple,
const llvm::Triple &T) {
llvm::SmallVector<llvm::SmallString<32>, 5> Gccs;
- Gccs.emplace_back(LiteralTriple.str());
+ Gccs.emplace_back(LiteralTriple.str(false));
Gccs.back() += "-gcc";
- Gccs.emplace_back(T.str());
+ Gccs.emplace_back(T.str(false));
Gccs.back() += "-gcc";
Gccs.emplace_back(T.getArchName());
Gccs.back() += "-w64-mingw32-gcc";
@@ -462,8 +462,8 @@ static llvm::ErrorOr<std::string>
findClangRelativeSysroot(const Driver &D, const llvm::Triple &LiteralTriple,
const llvm::Triple &T, std::string &SubdirName) {
llvm::SmallVector<llvm::SmallString<32>, 4> Subdirs;
- Subdirs.emplace_back(LiteralTriple.str());
- Subdirs.emplace_back(T.str());
+ Subdirs.emplace_back(LiteralTriple.str(false));
+ Subdirs.emplace_back(T.str(false));
Subdirs.emplace_back(T.getArchName());
Subdirs.back() += "-w64-mingw32";
Subdirs.emplace_back(T.getArchName());
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp
index 72f36d08f4da7..5275b79ce4eab 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -112,7 +112,7 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) const {
case llvm::Triple::loongarch64:
return "loongarch64-linux-ohos";
}
- return T.str();
+ return T.str(false);
}
std::string OHOS::getMultiarchTriple(const Driver &D,
@@ -296,7 +296,7 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
// Second try the normalized triple.
P.assign(D.ResourceDir);
- llvm::sys::path::append(P, "lib", Triple.str(), SelectedMultilib.gccSuffix());
+ llvm::sys::path::append(P, "lib", Triple.str(false), SelectedMultilib.gccSuffix());
Paths.push_back(P.c_str());
// Third try the effective triple.
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index cb56a7ebeba24..ab1250618845b 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -209,7 +209,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fuse-ld" << TC.getTriple().str();
+ << "-fuse-ld" << TC.getTriple().str(false);
}
std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
@@ -432,7 +432,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fuse-ld" << TC.getTriple().str();
+ << "-fuse-ld" << TC.getTriple().str(false);
}
std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
@@ -570,7 +570,7 @@ void toolchains::PS4PS5Base::addClangTargetOptions(
if (DriverArgs.hasArg(options::OPT_fuse_init_array)) {
Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array);
getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(DriverArgs) << getTriple().str();
+ << A->getAsString(DriverArgs) << getTriple().str(false);
}
CC1Args.push_back("-fno-use-init-array");
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index d88ddc264d72a..1bdf590741147 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -62,7 +62,7 @@ RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
// Multilib cross-compiler GCC installations put ld in a triple-prefixed
// directory off of the parent of the GCC installation.
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str() + "/bin")
+ GCCInstallation.getTriple().str(false) + "/bin")
.str());
PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
} else {
@@ -119,7 +119,7 @@ void RISCVToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const GCCVersion &Version = GCCInstallation.getVersion();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
const Multilib &Multilib = GCCInstallation.getMultilib();
addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
TripleStr, Multilib.includeSuffix(), DriverArgs,
@@ -133,7 +133,7 @@ std::string RISCVToolChain::computeSysRoot() const {
SmallString<128> SysRootDir;
if (GCCInstallation.isValid()) {
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
} else {
// Use the triple as provided to the driver. Unlike the parsed triple
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 6611c142a5efd..5f724ca36e4c5 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -67,7 +67,7 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
for (OptSpecifier Opt : getUnsupportedOpts()) {
if (const Arg *A = Args.getLastArg(Opt)) {
D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
- << A->getAsString(Args) << getTriple().str();
+ << A->getAsString(Args) << getTriple().str(false);
}
}
}
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index 48d1002381761..5c6041f60254b 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -414,7 +414,7 @@ void Solaris::addLibStdCxxIncludePaths(
// the lib directory of the GCC installation.
// On Solaris this usually looks like /usr/gcc/X.Y/include/c++/X.Y.Z
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str();
+ StringRef TripleStr = GCCInstallation.getTriple().str(false);
const Multilib &Multilib = GCCInstallation.getMultilib();
const GCCVersion &Version = GCCInstallation.getVersion();
diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 701dd2906dccb..65a5a11bef1cd 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -35,7 +35,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str();
+ << XRayInstrument->getSpelling() << Triple.str(false);
break;
}
} else if (Triple.isOSBinFormatELF()) {
@@ -56,11 +56,11 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str();
+ << XRayInstrument->getSpelling() << Triple.str(false);
}
} else {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str();
+ << XRayInstrument->getSpelling() << Triple.str(false);
}
if (Args.hasFlag(options::OPT_fxray_shared, options::OPT_fno_xray_shared,
@@ -74,7 +74,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fxray-shared" << Triple.str();
+ << "-fxray-shared" << Triple.str(false);
}
unsigned PICLvl = std::get<1>(tools::ParsePICArgs(TC, Args));
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 587b0d1af9c8d..c759ec33f9952 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -122,7 +122,7 @@ bool CompilerInstance::createTarget() {
TO->CPU = *getFrontendOpts().AuxTargetCPU;
if (getFrontendOpts().AuxTargetFeatures)
TO->FeaturesAsWritten = *getFrontendOpts().AuxTargetFeatures;
- TO->HostTriple = getTarget().getTriple().str();
+ TO->HostTriple = getTarget().getTriple().str(false);
setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), *TO));
}
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c02719121c73..cbbb211cb0478 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -597,7 +597,7 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
LangOptions::ExceptionHandlingKind::None &&
T.isWindowsMSVCEnvironment())
Diags.Report(diag::err_fe_invalid_exception_model)
- << static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str();
+ << static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str(false);
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
Diags.Report(diag::warn_c_kext);
@@ -2169,7 +2169,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
// future.
if (T.isOSAIX())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str();
+ << A->getSpelling() << T.str(false);
const Option &O = A->getOption();
if (O.matches(OPT_fpcc_struct_return) ||
@@ -2185,7 +2185,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
if (Arg *A = Args.getLastArg(OPT_mxcoff_roptr)) {
if (!T.isOSAIX())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str();
+ << A->getSpelling() << T.str(false);
// Since the storage mapping class is specified per csect,
// without using data sections, it is less effective to use read-only
@@ -2204,7 +2204,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
if (Arg *A = Args.getLastArg(OPT_mabi_EQ_quadword_atomics)) {
if (!T.isOSAIX() || T.isPPC32())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str();
+ << A->getSpelling() << T.str(false);
}
bool NeedLocTracking = false;
@@ -3848,7 +3848,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
llvm::raw_string_ostream OS(Targets);
llvm::interleave(
Opts.OMPTargetTriples, OS,
- [&OS](const llvm::Triple &T) { OS << T.str(); }, ",");
+ [&OS](const llvm::Triple &T) { OS << T.str(false); }, ",");
GenerateArg(Consumer, OPT_fopenmp_targets_EQ, Targets);
}
@@ -4278,7 +4278,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
// Add unsupported host targets here:
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
- Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str();
+ Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str(false);
break;
}
}
@@ -4348,7 +4348,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Diags.Report(diag::err_drv_invalid_omp_target) << A->getValue(i);
else if (getArchPtrSize(T) != getArchPtrSize(TT))
Diags.Report(diag::err_drv_incompatible_omp_arch)
- << A->getValue(i) << T.str();
+ << A->getValue(i) << T.str(false);
else
Opts.OMPTargetTriples.push_back(TT);
}
@@ -4521,7 +4521,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
} else {
auto Kind = TargetCXXABI::getKind(CXXABI);
if (!TargetCXXABI::isSupportedCXXABI(T, Kind))
- Diags.Report(diag::err_unsupported_cxx_abi) << CXXABI << T.str();
+ Diags.Report(diag::err_unsupported_cxx_abi) << CXXABI << T.str(false);
else
Opts.CXXABI = Kind;
}
@@ -4584,19 +4584,19 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (T.getOSName().empty()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
- << ExpectedOS << OS << T.str();
+ << ExpectedOS << OS << T.str(false);
} else if (T.getEnvironmentName().empty()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
- << ShaderStage << Environment << T.str();
+ << ShaderStage << Environment << T.str(false);
} else if (!T.isShaderStageEnvironment()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << ShaderStage << T.getEnvironmentName() << T.str();
+ << ShaderStage << T.getEnvironmentName() << T.str(false);
}
if (T.isDXIL()) {
if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << ShaderModel << T.getOSName() << T.str();
+ << ShaderModel << T.getOSName() << T.str(false);
}
// Validate that if fnative-half-type is given, that
// the language standard is at least hlsl2018, and that
@@ -4613,7 +4613,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
} else if (T.isSPIRVLogical()) {
if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << VulkanEnv << T.getOSName() << T.str();
+ << VulkanEnv << T.getOSName() << T.str(false);
}
if (Args.getLastArg(OPT_fnative_half_type)) {
const LangStandard &Std =
@@ -4626,7 +4626,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
llvm_unreachable("expected DXIL or SPIR-V target");
}
} else
- Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
+ Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str(false);
if (Opts.LangStd < LangStandard::lang_hlsl202x) {
const LangStandard &Requested =
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index d7cfd23bb0a7a..ceae977e521b4 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -292,7 +292,7 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
raw_ostream &OS) -> void {
OS << "--- !" << Format << "\n";
OS << "IfsVersion: 3.0\n";
- OS << "Target: " << T.str() << "\n";
+ OS << "Target: " << T.str(false) << "\n";
OS << "Symbols:\n";
for (const auto &E : Symbols) {
const MangledSymbol &Symbol = E.second;
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 370ade6dea7a1..fab8963ead4c0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2164,8 +2164,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
else
PD << "expression";
targetDiag(Loc, PD, FD)
- << false /*show bit size*/ << 0 /*bitsize*/ << false /*return*/
- << Ty << Context.getTargetInfo().getTriple().str();
+ << false /*show bit size*/ << 0 << Ty << false /*return*/
+ << Context.getTargetInfo().getTriple().str(false);
}
return;
}
@@ -2199,7 +2199,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (targetDiag(Loc, PD, FD)
<< true /*show bit size*/
<< static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty
- << false /*return*/ << Context.getTargetInfo().getTriple().str()) {
+ << false /*return*/ << Context.getTargetInfo().getTriple().str(false)) {
if (D)
D->setInvalidDecl();
}
@@ -2225,7 +2225,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (Diag(Loc, PD, FD)
<< false /*show bit size*/ << 0 << Ty << false /*return*/
- << TI.getTriple().str()) {
+ << TI.getTriple().str(false)) {
if (D)
D->setInvalidDecl();
}
@@ -2244,7 +2244,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (Diag(Loc, PD, FD)
<< false /*show bit size*/ << 0 << Ty << true /*return*/
- << TI.getTriple().str()) {
+ << TI.getTriple().str(false)) {
if (D)
D->setInvalidDecl();
}
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 2546ab5c0a342..d3039e58b2a32 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -853,7 +853,7 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
// In OpenMP target regions, we replace 'throw' with a trap on GPU targets.
if (IsOpenMPGPUTarget)
- targetDiag(OpLoc, diag::warn_throw_not_valid_on_target) << T.str();
+ targetDiag(OpLoc, diag::warn_throw_not_valid_on_target) << T.str(false);
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index 9b4d82745f881..dc23f01d237bd 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -229,7 +229,7 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
BuiltinID == PPC::BI__builtin_ppc_minfe))
return Diag(TheCall->getBeginLoc(), diag::err_target_unsupported_type)
<< "builtin" << true << 128 << QualType(Context.LongDoubleTy)
- << false << Context.getTargetInfo().getTriple().str();
+ << false << Context.getTargetInfo().getTriple().str(false);
// Argument type should be exact.
QualType ArgType = QualType(Context.LongDoubleTy);
if (BuiltinID == PPC::BI__builtin_ppc_maxfl ||
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 50f5757dff5bc..1c9c694823596 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -4317,7 +4317,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
// In OpenMP target regions, we assume that catch is never reached on GPU
// targets.
if (IsOpenMPGPUTarget)
- targetDiag(TryLoc, diag::warn_try_not_valid_on_target) << T.str();
+ targetDiag(TryLoc, diag::warn_try_not_valid_on_target) << T.str(false);
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 603e306497841..d598ae92fec45 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -642,7 +642,7 @@ bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
ArchSpec default_arch = Target::GetDefaultArchitecture();
if (default_arch.IsValid()) {
- const std::string &triple_str = default_arch.GetTriple().str();
+ const std::string &triple_str = default_arch.GetTriple().str(false);
if (!triple_str.empty())
::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
else
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 985107ec68efd..1011586a89407 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -576,7 +576,7 @@ const char *SBModule::GetTriple() {
if (!module_sp)
return nullptr;
- std::string triple(module_sp->GetArchitecture().GetTriple().str());
+ std::string triple(module_sp->GetArchitecture().GetTriple().str(false));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index fbbcfeac20178..620d5f91fa0ce 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -112,7 +112,7 @@ void SBModuleSpec::SetObjectName(const char *name) {
const char *SBModuleSpec::GetTriple() {
LLDB_INSTRUMENT_VA(this);
- std::string triple(m_opaque_up->GetArchitecture().GetTriple().str());
+ std::string triple(m_opaque_up->GetArchitecture().GetTriple().str(false));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index f26f7951edc6f..b99786f388ec5 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1576,7 +1576,7 @@ const char *SBTarget::GetTriple() {
LLDB_INSTRUMENT_VA(this);
if (TargetSP target_sp = GetSP()) {
- std::string triple(target_sp->GetArchitecture().GetTriple().str());
+ std::string triple(target_sp->GetArchitecture().GetTriple().str(false));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 90997dada3666..5fba6c346afea 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1612,7 +1612,7 @@ bool Module::GetIsDynamicLinkEditor() {
uint32_t Module::Hash() {
std::string identifier;
llvm::raw_string_ostream id_strm(identifier);
- id_strm << m_arch.GetTriple().str() << '-' << m_file.GetPath();
+ id_strm << m_arch.GetTriple().str(false) << '-' << m_file.GetPath();
if (m_object_name)
id_strm << '(' << m_object_name << ')';
if (m_object_offset > 0)
@@ -1626,7 +1626,7 @@ uint32_t Module::Hash() {
std::string Module::GetCacheKey() {
std::string key;
llvm::raw_string_ostream strm(key);
- strm << m_arch.GetTriple().str() << '-' << m_file.GetFilename();
+ strm << m_arch.GetTriple().str(false) << '-' << m_file.GetFilename();
if (m_object_name)
strm << '(' << m_object_name << ')';
strm << '-' << llvm::format_hex(Hash(), 10);
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index fe9f5d086da2c..4a6e039916b93 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -498,7 +498,7 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr,
log,
"DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().str(false).c_str(), uuid_str.c_str());
}
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index a23ba3ad5c545..f5e94e8113b9a 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -236,7 +236,7 @@ lldb_private::UUID DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
LLDB_LOGF(log,
"DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str().c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().str(false).c_str(), uuid_str.c_str());
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 7aa9cae5a5614..9c1c643745869 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -509,7 +509,7 @@ static void SetupTargetOpts(CompilerInstance &compiler,
const auto target_machine = target_arch.GetMachine();
if (target_arch.IsValid()) {
- std::string triple = target_arch.GetTriple().str();
+ std::string triple = target_arch.GetTriple().str(false);
compiler.getTargetOpts().Triple = triple;
LLDB_LOGF(log, "Using %s as the target triple",
compiler.getTargetOpts().Triple.c_str());
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index c99ed9dd0a68d..6147ca3719ab0 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -659,7 +659,7 @@ ClangModulesDeclVendor::Create(Target &target) {
"-fsyntax-only",
"-femit-all-decls",
"-target",
- arch.GetTriple().str(),
+ arch.GetTriple().str(false),
"-fmodules-validate-system-headers",
"-Werror=non-modular-include-in-framework-module",
"-Xclang=-fincremental-extensions",
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index f3aabc12f92b7..e8d8a76983f1a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -35,8 +35,8 @@ bool CppModuleConfiguration::SetOncePath::TrySet(llvm::StringRef path) {
static llvm::SmallVector<std::string, 2>
getTargetIncludePaths(const llvm::Triple &triple) {
llvm::SmallVector<std::string, 2> paths;
- if (!triple.str().empty()) {
- paths.push_back("/usr/include/" + triple.str());
+ if (!triple.str(false).empty()) {
+ paths.push_back("/usr/include/" + triple.str(false));
if (!triple.getArchName().empty() ||
triple.getOSAndEnvironmentName().empty())
paths.push_back(("/usr/include/" + triple.getArchName() + "-" +
@@ -75,13 +75,13 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
parent_path(posix_dir, Style::posix).ends_with("c++")) {
if (!m_std_inc.TrySet(posix_dir))
return false;
- if (triple.str().empty())
+ if (triple.str(false).empty())
return true;
posix_dir.consume_back("c++/v1");
// Check if this is a target-specific libc++ include directory.
return m_std_target_inc.TrySet(
- (posix_dir + triple.str() + "/c++/v1").str());
+ (posix_dir + triple.str(false) + "/c++/v1").str());
}
std::optional<llvm::StringRef> inc_path;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 3950454b7c90e..e2a96512b38b6 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6746,7 +6746,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
break;
default:
error = Status::FromErrorStringWithFormat(
- "unsupported core architecture: %s", target_triple.str().c_str());
+ "unsupported core architecture: %s", target_triple.str(false).c_str());
break;
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 26ca6ed128972..448db34637601 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -354,7 +354,7 @@ Status PlatformRemoteGDBServer::LaunchProcess(ProcessLaunchInfo &launch_info) {
m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
ArchSpec arch_spec = launch_info.GetArchitecture();
- const char *arch_triple = arch_spec.GetTriple().str().c_str();
+ const char *arch_triple = arch_spec.GetTriple().str(false).c_str();
m_gdb_client_up->SendLaunchArchPacket(arch_triple);
LLDB_LOGF(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 29302413cf8fb..6e90e23b72ba5 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -497,8 +497,8 @@ static void ParseLangArgs(LangOptions &Opts, ArchSpec arch) {
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
llvm::Triple target_triple) {
m_display_name = name.str();
- if (!target_triple.str().empty())
- SetTargetTriple(target_triple.str());
+ if (!target_triple.str(false).empty())
+ SetTargetTriple(target_triple.str(false));
// The caller didn't pass an ASTContext so create a new one for this
// TypeSystemClang.
CreateASTContext();
@@ -509,7 +509,7 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
ASTContext &existing_ctxt) {
m_display_name = name.str();
- SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
+ SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str(false));
m_ast_up.reset(&existing_ctxt);
GetASTMap().Insert(&existing_ctxt, this);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 8000cd07565ae..c36e8a460e10c 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -250,7 +250,7 @@ void Platform::GetStatus(Stream &strm) {
ArchSpec arch(GetSystemArchitecture());
if (arch.IsValid()) {
- if (!arch.GetTriple().str().empty()) {
+ if (!arch.GetTriple().str(false).empty()) {
strm.Printf(" Triple: ");
arch.DumpTriple(strm.AsRawOstream());
strm.EOL();
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 4cfd0629ea271..7c24f54963044 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -401,7 +401,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
module_stat.path.append(1, ')');
}
module_stat.uuid = module->GetUUID().GetAsString();
- module_stat.triple = module->GetArchitecture().GetTriple().str();
+ module_stat.triple = module->GetArchitecture().GetTriple().str(false);
json_modules.emplace_back(module_stat.ToJSON());
}
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 23db009654f4f..f340db373c3ec 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -513,7 +513,7 @@ bool LLParser::parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback) {
// Run the override callback to potentially change the data layout string, and
// parse the data layout string.
if (auto LayoutOverride =
- DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
+ DataLayoutCallback(M->getTargetTriple().str(false), TentativeDLStr)) {
TentativeDLStr = *LayoutOverride;
DLStrLoc = {};
}
diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp
index f46b9d5147ff1..a0d428ce75bcd 100644
--- a/llvm/lib/BinaryFormat/MachO.cpp
+++ b/llvm/lib/BinaryFormat/MachO.cpp
@@ -71,7 +71,7 @@ static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T) {
static Error unsupported(const char *Str, const Triple &T) {
return createStringError(std::errc::invalid_argument,
"Unsupported triple for mach-o cpu %s: %s", Str,
- T.str().c_str());
+ T.str(false).c_str());
}
Expected<uint32_t> MachO::getCPUType(const Triple &T) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 105edb943eb7f..29a45a6c96e18 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4512,12 +4512,12 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
// Auto-upgrade the layout string
TentativeDataLayoutStr = llvm::UpgradeDataLayoutString(
- TentativeDataLayoutStr, TheModule->getTargetTriple().str());
+ TentativeDataLayoutStr, TheModule->getTargetTriple().str(false));
// Apply override
if (Callbacks.DataLayout) {
if (auto LayoutOverride = (*Callbacks.DataLayout)(
- TheModule->getTargetTriple().str(), TentativeDataLayoutStr))
+ TheModule->getTargetTriple().str(false), TentativeDataLayoutStr))
TentativeDataLayoutStr = *LayoutOverride;
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index fad8ebfad9f9a..816fd6c7bf202 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1476,7 +1476,7 @@ void ModuleBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
- M.getTargetTriple().str(), 0 /*TODO*/);
+ M.getTargetTriple().str(false), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index 4a3503a2da7db..9913f2a4b242c 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -44,7 +44,7 @@ static cl::opt<bool> EnableNoTrapAfterNoreturn(
"after noreturn calls, even if --trap-unreachable is set."));
void CodeGenTargetMachineImpl::initAsmInfo() {
- MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
+ MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str(false)));
assert(MRI && "Unable to create reg info");
MII.reset(TheTarget.createMCInstrInfo());
assert(MII && "Unable to create instruction info");
@@ -53,11 +53,11 @@ void CodeGenTargetMachineImpl::initAsmInfo() {
// code generation. This is similar to the hack in the AsmPrinter for
// module level assembly etc.
STI.reset(TheTarget.createMCSubtargetInfo(
- getTargetTriple().str(), getTargetCPU(), getTargetFeatureString()));
+ getTargetTriple().str(false), getTargetCPU(), getTargetFeatureString()));
assert(STI && "Unable to create subtarget info");
MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(
- *MRI, getTargetTriple().str(), Options.MCOptions);
+ *MRI, getTargetTriple().str(false), Options.MCOptions);
// TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0,
// and if the old one gets included then MCAsmInfo will be NULL and
// we'll crash later.
@@ -197,7 +197,7 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
return make_error<StringError>("createMCAsmBackend failed",
inconvertibleErrorCode());
- Triple T(getTargetTriple().str());
+ Triple T(getTargetTriple().str(false));
AsmStreamer.reset(getTarget().createMCObjectStreamer(
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index a57bda54f9180..2a13f785f5f74 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -253,7 +253,7 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
// Create an empty module when the MIR file is empty.
NoMIRDocuments = true;
auto M = std::make_unique<Module>(Filename, Context);
- if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
+ if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(false),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
return M;
@@ -277,7 +277,7 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
} else {
// Create an new, empty module.
M = std::make_unique<Module>(Filename, Context);
- if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
+ if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(false),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
NoLLVMIR = true;
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
index ff48a938cbd42..61a301ec1d6cf 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
@@ -757,7 +757,7 @@ class RuntimeDyldCheckerExprEval {
Expected<TargetInfo> getTargetInfo(const Triple &TT, const StringRef &CPU,
const SubtargetFeatures &TF) const {
- auto TripleName = TT.str();
+ auto TripleName = TT.str(false);
std::string ErrorStr;
const Target *TheTarget =
TargetRegistry::lookupTarget(TripleName, ErrorStr);
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 7223dd845d18d..13dd4cd130837 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3103,7 +3103,7 @@ void AssemblyWriter::printModule(const Module *M) {
if (!DL.empty())
Out << "target datalayout = \"" << DL << "\"\n";
if (!M->getTargetTriple().empty())
- Out << "target triple = \"" << M->getTargetTriple().str() << "\"\n";
+ Out << "target triple = \"" << M->getTargetTriple().str(false) << "\"\n";
if (!M->getModuleInlineAsm().empty()) {
Out << '\n';
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 1954b44af22ad..eb5de3bebaf5a 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -321,7 +321,7 @@ void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
/*--.. Target triple .......................................................--*/
const char * LLVMGetTarget(LLVMModuleRef M) {
- return unwrap(M)->getTargetTriple().str().c_str();
+ return unwrap(M)->getTargetTriple().str(false).c_str();
}
void LLVMSetTarget(LLVMModuleRef M, const char *TripleStr) {
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index ba120a0566834..f5f254f3f59e4 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -2373,7 +2373,7 @@ class OutOfProcessThinBackend : public CGThinBackend {
JOS.value("-c");
- JOS.value(Saver.save("--target=" + Triple.str()));
+ JOS.value(Saver.save("--target=" + Triple.str(false)));
for (const auto &A : CodegenOptions)
JOS.value(A);
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 09b91d81225a8..9765db53df6bf 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -375,7 +375,7 @@ bool LTOCodeGenerator::determineTarget() {
if (TargetMach)
return true;
- TripleStr = MergedModule->getTargetTriple().str();
+ TripleStr = MergedModule->getTargetTriple().str(false);
llvm::Triple Triple(TripleStr);
if (TripleStr.empty()) {
TripleStr = sys::getDefaultTargetTriple();
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 4dd5ae81c89c1..0296d24144eb6 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1492,9 +1492,9 @@ Error IRLinker::run() {
!SrcTriple.isCompatibleWith(DstTriple))
emitWarning("Linking two modules of different target triples: '" +
SrcM->getModuleIdentifier() + "' is '" +
- SrcM->getTargetTriple().str() + "' whereas '" +
+ SrcM->getTargetTriple().str(false) + "' whereas '" +
DstM.getModuleIdentifier() + "' is '" +
- DstM.getTargetTriple().str() + "'\n");
+ DstM.getTargetTriple().str(false) + "'\n");
DstM.setTargetTriple(Triple(SrcTriple.merge(DstTriple)));
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 9263dda65a8b0..393a75829933c 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -152,7 +152,7 @@ const Target *TargetRegistry::lookupTarget(const Triple &TT,
if (I == targets().end()) {
Error =
- "No available targets are compatible with triple \"" + TT.str() + "\"";
+ "No available targets are compatible with triple \"" + TT.str(false) + "\"";
return nullptr;
}
diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp
index 167fc27cf74ef..323ef1e007d25 100644
--- a/llvm/lib/Object/IRObjectFile.cpp
+++ b/llvm/lib/Object/IRObjectFile.cpp
@@ -66,7 +66,7 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
StringRef IRObjectFile::getTargetTriple() const {
// Each module must have the same target triple, so we arbitrarily access the
// first one.
- return Mods[0]->getTargetTriple().str();
+ return Mods[0]->getTargetTriple().str(false);
}
Expected<MemoryBufferRef>
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index 806477ae3de01..6954bc71adef1 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -349,7 +349,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
assert(!IRMods.empty());
Hdr.Version = storage::Header::kCurrentVersion;
setStr(Hdr.Producer, kExpectedProducerName);
- setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str());
+ setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str(false));
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
TT = IRMods[0]->getTargetTriple();
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index 1706772912772..9e0c8d45193c6 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -81,17 +81,17 @@ initializeRecordStreamer(const Module &M,
const Target *T = TargetRegistry::lookupTarget(TT, Err);
assert(T && T->hasMCAsmParser());
- std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str()));
+ std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str(false)));
if (!MRI)
return;
MCTargetOptions MCOptions;
- std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str(), MCOptions));
+ std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str(false), MCOptions));
if (!MAI)
return;
std::unique_ptr<MCSubtargetInfo> STI(
- T->createMCSubtargetInfo(TT.str(), "", ""));
+ T->createMCSubtargetInfo(TT.str(false), "", ""));
if (!STI)
return;
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 0d019bda36130..392ef5018f73c 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -726,7 +726,7 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
const Triple &TT = TM.getTargetTriple();
assert(TT.isOSBinFormatELF());
std::unique_ptr<MCSubtargetInfo> STI(
- TM.getTarget().createMCSubtargetInfo(TT.str(), "", ""));
+ TM.getTarget().createMCSubtargetInfo(TT.str(false), "", ""));
assert(STI && "Unable to create subtarget info");
this->STI = static_cast<const AArch64Subtarget *>(&*STI);
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 1a3e99ec7f68f..7da5169dadb38 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -972,7 +972,7 @@ void MipsAsmPrinter::EmitFPCallStub(
// freed) and since we're at the global level we can use the default
// constructed subtarget.
std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
- TM.getTargetTriple().str(), TM.getTargetCPU(),
+ TM.getTargetTriple().str(false), TM.getTargetCPU(),
TM.getTargetFeatureString()));
//
diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.h b/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
index ad3e38d296ed7..61ff61564229c 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
@@ -101,7 +101,7 @@ class SPIRVSubtarget : public SPIRVGenSubtargetInfo {
return TargetTriple.getArch() == Triple::spirv32 ||
TargetTriple.getArch() == Triple::spirv64;
}
- const std::string &getTargetTripleAsStr() const { return TargetTriple.str(); }
+ const std::string &getTargetTripleAsStr() const { return TargetTriple.str(false); }
VersionTuple getSPIRVVersion() const { return SPIRVVersion; };
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const;
bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const;
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index da6d35c8c8b43..94ebf6804d7c3 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -233,7 +233,7 @@ LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
}
char* LLVMGetTargetMachineTriple(LLVMTargetMachineRef T) {
- std::string StringRep = unwrap(T)->getTargetTriple().str();
+ std::string StringRep = unwrap(T)->getTargetTriple().str(false);
return strdup(StringRep.c_str());
}
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 14acef116708a..82b213eae9e0e 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2285,7 +2285,7 @@ std::string sys::getProcessTriple() {
if (sizeof(void *) == 4 && PT.isArch64Bit())
PT = PT.get32BitArchVariant();
- return PT.str();
+ return PT.str(false);
}
void sys::printDefaultTargetAndDetectedCPU(raw_ostream &OS) {
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 6a559ff023caa..cab05ca87866f 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2102,9 +2102,9 @@ std::string Triple::merge(const Triple &Other) const {
// If vendor is apple, pick the triple with the larger version number.
if (getVendor() == Triple::Apple)
if (Other.isOSVersionLT(*this))
- return str();
+ return str(false);
- return Other.str();
+ return Other.str(false);
}
bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
diff --git a/llvm/lib/TargetParser/Unix/Host.inc b/llvm/lib/TargetParser/Unix/Host.inc
index a33fe6fff8936..b3f3a6cfe82c5 100644
--- a/llvm/lib/TargetParser/Unix/Host.inc
+++ b/llvm/lib/TargetParser/Unix/Host.inc
@@ -65,7 +65,7 @@ static std::string updateTripleOSVersion(std::string TargetTripleString) {
NewOSName += name.release;
NewOSName += ".0.0";
TT.setOSName(NewOSName);
- return TT.str();
+ return TT.str(false);
}
}
}
>From d2514d71b4afa6eea0a6e777b357d6236908d548 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 20 Jun 2025 12:19:01 -0700
Subject: [PATCH 3/6] Revert changes in llvm and clang (git checkout HEAD^ --
llvm/*) (git checkout HEAD^ -- clang/*)
---
clang/include/clang/Driver/ToolChain.h | 2 +-
clang/lib/Basic/Targets.cpp | 2 +-
clang/lib/CodeGen/CodeGenAction.cpp | 2 +-
clang/lib/Driver/Driver.cpp | 36 +++++++++----------
clang/lib/Driver/OffloadBundler.cpp | 2 +-
clang/lib/Driver/SanitizerArgs.cpp | 10 +++---
clang/lib/Driver/ToolChain.cpp | 10 +++---
clang/lib/Driver/ToolChains/AMDGPU.h | 2 +-
clang/lib/Driver/ToolChains/CSKYToolChain.cpp | 6 ++--
clang/lib/Driver/ToolChains/Clang.cpp | 14 ++++----
clang/lib/Driver/ToolChains/CommonArgs.cpp | 14 ++++----
clang/lib/Driver/ToolChains/CrossWindows.cpp | 2 +-
clang/lib/Driver/ToolChains/Cygwin.cpp | 2 +-
clang/lib/Driver/ToolChains/Flang.cpp | 2 +-
clang/lib/Driver/ToolChains/Fuchsia.cpp | 2 +-
clang/lib/Driver/ToolChains/Gnu.cpp | 22 ++++++------
clang/lib/Driver/ToolChains/Hurd.cpp | 4 +--
clang/lib/Driver/ToolChains/Linux.cpp | 16 ++++-----
clang/lib/Driver/ToolChains/MinGW.cpp | 14 ++++----
clang/lib/Driver/ToolChains/OHOS.cpp | 4 +--
clang/lib/Driver/ToolChains/PS4CPU.cpp | 6 ++--
.../lib/Driver/ToolChains/RISCVToolchain.cpp | 6 ++--
clang/lib/Driver/ToolChains/SYCL.cpp | 2 +-
clang/lib/Driver/ToolChains/Solaris.cpp | 2 +-
clang/lib/Driver/XRayArgs.cpp | 8 ++---
clang/lib/Frontend/CompilerInstance.cpp | 2 +-
clang/lib/Frontend/CompilerInvocation.cpp | 28 +++++++--------
.../InterfaceStubFunctionsConsumer.cpp | 2 +-
clang/lib/Sema/Sema.cpp | 10 +++---
clang/lib/Sema/SemaExprCXX.cpp | 2 +-
clang/lib/Sema/SemaPPC.cpp | 2 +-
clang/lib/Sema/SemaStmt.cpp | 2 +-
llvm/lib/AsmParser/LLParser.cpp | 2 +-
llvm/lib/BinaryFormat/MachO.cpp | 2 +-
llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 +--
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp | 8 ++---
llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 4 +--
.../RuntimeDyld/RuntimeDyldChecker.cpp | 2 +-
llvm/lib/IR/AsmWriter.cpp | 2 +-
llvm/lib/IR/Core.cpp | 2 +-
llvm/lib/LTO/LTO.cpp | 2 +-
llvm/lib/LTO/LTOCodeGenerator.cpp | 2 +-
llvm/lib/Linker/IRMover.cpp | 4 +--
llvm/lib/MC/TargetRegistry.cpp | 2 +-
llvm/lib/Object/IRObjectFile.cpp | 2 +-
llvm/lib/Object/IRSymtab.cpp | 2 +-
llvm/lib/Object/ModuleSymbolTable.cpp | 6 ++--
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 2 +-
llvm/lib/Target/Mips/MipsAsmPrinter.cpp | 2 +-
llvm/lib/Target/SPIRV/SPIRVSubtarget.h | 2 +-
llvm/lib/Target/TargetMachineC.cpp | 2 +-
llvm/lib/TargetParser/Host.cpp | 2 +-
llvm/lib/TargetParser/Triple.cpp | 4 +--
llvm/lib/TargetParser/Unix/Host.inc | 2 +-
55 files changed, 152 insertions(+), 152 deletions(-)
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
index 6538fed73c20f..b8899e78176b4 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -653,7 +653,7 @@ class ToolChain {
virtual std::string getMultiarchTriple(const Driver &D,
const llvm::Triple &TargetTriple,
StringRef SysRoot) const {
- return TargetTriple.str(false);
+ return TargetTriple.str();
}
/// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 757d07e3ac87c..9889141ad2085 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -783,7 +783,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
// Construct the target
std::unique_ptr<TargetInfo> Target = AllocateTarget(Triple, *Opts);
if (!Target) {
- Diags.Report(diag::err_target_unknown_triple) << Triple.str(false);
+ Diags.Report(diag::err_target_unknown_triple) << Triple.str();
return nullptr;
}
Target->TargetOpts = Opts;
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index bc30023dd56fb..1f5eb427b566f 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1133,7 +1133,7 @@ void CodeGenAction::ExecuteAction() {
return;
const TargetOptions &TargetOpts = CI.getTargetOpts();
- if (TheModule->getTargetTriple().str(false) != TargetOpts.Triple) {
+ if (TheModule->getTargetTriple().str() != TargetOpts.Triple) {
Diagnostics.Report(SourceLocation(), diag::warn_fe_override_module)
<< TargetOpts.Triple;
TheModule->setTargetTriple(Triple(TargetOpts.Triple));
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f0fc93fe6a36f..73ff7757c3b04 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -144,7 +144,7 @@ getNVIDIAOffloadTargetTriple(const Driver &D, const ArgList &Args,
D.Diag(diag::err_drv_cuda_offload_only_emit_bc);
return std::nullopt;
}
- D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str(false);
+ D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str();
return std::nullopt;
}
@@ -165,7 +165,7 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList &Args) {
return TT;
if (TT->getArch() == llvm::Triple::spirv64)
return TT;
- D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str(false);
+ D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str();
return std::nullopt;
}
@@ -714,13 +714,13 @@ static llvm::Triple computeTargetTriple(const Driver &D,
// Currently the only architecture supported by *-uefi triples are x86_64.
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
- D.Diag(diag::err_target_unknown_triple) << Target.str(false);
+ D.Diag(diag::err_target_unknown_triple) << Target.str();
// The `-maix[32|64]` flags are only valid for AIX targets.
if (Arg *A = Args.getLastArgNoClaim(options::OPT_maix32, options::OPT_maix64);
A && !Target.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << Target.str(false);
+ << A->getAsString(Args) << Target.str();
// Handle pseudo-target flags '-m64', '-mx32', '-m32' and '-m16'.
Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
@@ -748,7 +748,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
A->getOption().matches(options::OPT_maix32)) {
if (D.IsFlangMode() && !Target.isOSAIX()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << Target.str(false);
+ << A->getAsString(Args) << Target.str();
} else {
AT = Target.get32BitArchVariant().getArch();
if (Target.getEnvironment() == llvm::Triple::GNUX32)
@@ -779,7 +779,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false)) {
if (Target.get32BitArchVariant().getArch() != llvm::Triple::x86)
D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu"
- << Target.str(false);
+ << Target.str();
if (A && !A->getOption().matches(options::OPT_m32))
D.Diag(diag::err_drv_argument_not_allowed_with)
@@ -1361,7 +1361,7 @@ static bool findTripleConfigFile(llvm::cl::ExpansionContext &ExpCtx,
SmallString<128> &ConfigFilePath,
llvm::Triple Triple, std::string Suffix) {
// First, try the full unmodified triple.
- if (ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath))
+ if (ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath))
return true;
// Don't continue if we didn't find a parsable version in the triple.
@@ -1375,14 +1375,14 @@ static bool findTripleConfigFile(llvm::cl::ExpansionContext &ExpCtx,
// e.g. arm64-apple-darwin23.6.0 -> arm64-apple-darwin23
if (OSVersion.getMajor() != 0) {
Triple.setOSName(BaseOSName + llvm::utostr(OSVersion.getMajor()));
- if (ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath))
+ if (ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath))
return true;
}
// Finally, try without any version suffix at all.
// e.g. arm64-apple-darwin23.6.0 -> arm64-apple-darwin
Triple.setOSName(BaseOSName);
- return ExpCtx.findConfigFile(Triple.str(false) + Suffix, ConfigFilePath);
+ return ExpCtx.findConfigFile(Triple.str() + Suffix, ConfigFilePath);
}
bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
@@ -1402,7 +1402,7 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
// and the name prefix is not a valid triple, force it for backwards
// compatibility.
if (!ClangNameParts.TargetPrefix.empty() &&
- computeTargetTriple(*this, "/invalid/", *CLOptions).str(false) ==
+ computeTargetTriple(*this, "/invalid/", *CLOptions).str() ==
"/invalid/") {
llvm::Triple PrefixTriple{ClangNameParts.TargetPrefix};
if (PrefixTriple.getArch() == llvm::Triple::UnknownArch ||
@@ -1413,9 +1413,9 @@ 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(false).empty()) {
+ if (Triple.str().empty()) {
Triple = RealTriple;
- assert(!Triple.str(false).empty());
+ assert(!Triple.str().empty());
}
// On z/OS, start by loading the customization file before loading
@@ -1582,7 +1582,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
T.setObjectFormat(llvm::Triple::COFF);
if (Args.hasArg(options::OPT__SLASH_arm64EC))
T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec);
- TargetTriple = T.str(false);
+ TargetTriple = T.str();
} else if (IsDXCMode()) {
// Build TargetTriple from target_profile option for clang-dxc.
if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) {
@@ -1617,7 +1617,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
A->claim();
}
- TargetTriple = T.str(false);
+ TargetTriple = T.str();
}
} else {
Diag(diag::err_drv_dxc_missing_target_profile);
@@ -1770,7 +1770,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) &&
UArgs->hasArg(options::OPT__SLASH_arm64EC)) {
getDiags().Report(clang::diag::warn_target_override_arm64ec)
- << TC.getTriple().str(false);
+ << TC.getTriple().str();
}
// A common user mistake is specifying a target of aarch64-none-eabi or
@@ -6715,8 +6715,8 @@ const ToolChain &Driver::getOffloadToolChain(
const llvm::opt::ArgList &Args, const Action::OffloadKind Kind,
const llvm::Triple &Target, const llvm::Triple &AuxTarget) const {
std::unique_ptr<ToolChain> &TC =
- ToolChains[Target.str(false) + "/" + AuxTarget.str(false)];
- std::unique_ptr<ToolChain> &HostTC = ToolChains[AuxTarget.str(false)];
+ ToolChains[Target.str() + "/" + AuxTarget.str()];
+ std::unique_ptr<ToolChain> &HostTC = ToolChains[AuxTarget.str()];
assert(HostTC && "Host toolchain for offloading doesn't exit?");
if (!TC) {
@@ -6781,7 +6781,7 @@ const ToolChain &Driver::getOffloadToolChain(
const ToolChain &Driver::getToolChain(const ArgList &Args,
const llvm::Triple &Target) const {
- auto &TC = ToolChains[Target.str(false)];
+ auto &TC = ToolChains[Target.str()];
if (!TC) {
switch (Target.getOS()) {
case llvm::Triple::AIX:
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 8bbe47decaa0f..3dfd51ee2365a 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -135,7 +135,7 @@ bool OffloadTargetInfo::isOffloadKindCompatible(
}
bool OffloadTargetInfo::isTripleValid() const {
- return !Triple.str(false).empty() && Triple.getArch() != Triple::UnknownArch;
+ return !Triple.str().empty() && Triple.getArch() != Triple::UnknownArch;
}
bool OffloadTargetInfo::operator==(const OffloadTargetInfo &Target) const {
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index c94d9ae735473..eb4718909c951 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -500,7 +500,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
<< Desc << A->getAsString(Args);
else
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << Desc << Triple.str(false);
+ << Desc << Triple.str();
}
DiagnosedKinds |= KindsToDiagnose;
}
@@ -530,7 +530,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
if (DiagnoseErrors) {
std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << Desc << TC.getTriple().str(false);
+ << Desc << TC.getTriple().str();
}
DiagnosedKinds |= KindsToDiagnose;
}
@@ -700,7 +700,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
S.Mask = KindsToDiagnose;
if (DiagnoseErrors)
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str(false);
+ << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str();
Kinds &= ~KindsToDiagnose;
}
}
@@ -1013,7 +1013,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
Arg *A =
Args.getLastArg(options::OPT_shared_libsan, options::OPT_static_libsan);
D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << TC.getTriple().str(false);
+ << A->getSpelling() << TC.getTriple().str();
}
ImplicitCfiRuntime = TC.getTriple().isAndroid();
@@ -1434,7 +1434,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
if (KcfiArity) {
if (!TC.getTriple().isOSLinux() || !TC.getTriple().isArch64Bit()) {
TC.getDriver().Diag(clang::diag::err_drv_kcfi_arity_unsupported_target)
- << TC.getTriple().str(false);
+ << TC.getTriple().str();
}
CmdArgs.push_back("-fsanitize-kcfi-arity");
}
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 3f30f39461f4a..f2911713668ae 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -342,7 +342,7 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
std::vector<std::string> Result;
const llvm::Triple Triple(ComputeEffectiveClangTriple(Args));
- Result.push_back("--target=" + Triple.str(false));
+ Result.push_back("--target=" + Triple.str());
switch (Triple.getArch()) {
case llvm::Triple::aarch64:
@@ -871,7 +871,7 @@ std::optional<std::string>
ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) const {
llvm::Triple TripleWithoutLevel(getTriple());
TripleWithoutLevel.setEnvironmentName("android"); // remove any version number
- const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str(false);
+ const std::string &TripleWithoutLevelStr = TripleWithoutLevel.str();
unsigned TripleVersion = getTriple().getEnvironmentVersion().getMajor();
unsigned BestVersion = 0;
@@ -923,7 +923,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
auto getPathForTriple =
[&](const llvm::Triple &Triple) -> std::optional<std::string> {
SmallString<128> P(BaseDir);
- llvm::sys::path::append(P, Triple.str(false));
+ llvm::sys::path::append(P, Triple.str());
if (getVFS().exists(P))
return std::string(P);
return {};
@@ -992,7 +992,7 @@ std::optional<std::string> ToolChain::getRuntimePath() const {
if (Triple.isOSDarwin())
return {};
- llvm::sys::path::append(P, Triple.str(false));
+ llvm::sys::path::append(P, Triple.str());
return std::string(P);
}
@@ -1019,7 +1019,7 @@ ToolChain::path_list ToolChain::getArchSpecificLibPaths() const {
Paths.push_back(std::string(Path));
};
- AddPath({getTriple().str(false)});
+ AddPath({getTriple().str()});
AddPath({getOSLibName(), llvm::Triple::getArchTypeName(getArch())});
return Paths;
}
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 40f5f943b3a09..08bd4fa556f78 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -163,7 +163,7 @@ class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
parseSanitizerValue(A->getValue(), /*Allow Groups*/ false);
if (K != SanitizerKind::Address)
Diags.Report(clang::diag::warn_drv_unsupported_option_for_target)
- << A->getAsString(Args) << getTriple().str(false);
+ << A->getAsString(Args) << getTriple().str();
}
}
};
diff --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index 83fc5c88be018..e944cba0eb23c 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -48,7 +48,7 @@ CSKYToolChain::CSKYToolChain(const Driver &D, const llvm::Triple &Triple,
// Multilib cross-compiler GCC installations put ld in a triple-prefixed
// directory off of the parent of the GCC installation.
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str(false) + "/bin")
+ GCCInstallation.getTriple().str() + "/bin")
.str());
PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
getFilePaths().push_back(computeSysRoot() + "/lib" +
@@ -98,7 +98,7 @@ void CSKYToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const GCCVersion &Version = GCCInstallation.getVersion();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
TripleStr, Multilib.includeSuffix(), DriverArgs,
@@ -112,7 +112,7 @@ std::string CSKYToolChain::computeSysRoot() const {
SmallString<128> SysRootDir;
if (GCCInstallation.isValid()) {
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
} else {
// Use the triple as provided to the driver. Unlike the parsed triple
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 8ac3abbfc74cd..80dd72a23a673 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -579,7 +579,7 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
if (TC.getTriple().isOSAIX()) {
if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << ProfileSampleUseArg->getSpelling() << TC.getTriple().str(false);
+ << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
}
if (ProfileGenerateArg) {
@@ -2137,7 +2137,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
if (VecExtabi) {
if (!T.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-mabi=vec-extabi" << T.str(false);
+ << "-mabi=vec-extabi" << T.str();
CmdArgs.push_back("-mabi=vec-extabi");
}
@@ -5746,7 +5746,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< (NoPICDataIsTextRelative ? "-mno-pic-data-is-text-relative"
: "-mpic-data-is-text-relative")
- << RawTriple.str(false);
+ << RawTriple.str();
}
bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
@@ -5868,7 +5868,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
if (!Triple.isOSAIX() || Triple.isPPC32())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str(false);
+ << A->getSpelling() << RawTriple.str();
CmdArgs.push_back("-mabi=quadword-atomics");
}
@@ -5877,7 +5877,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// support for 128-bit long double is available for AIX.
if (Triple.isOSAIX())
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str(false);
+ << A->getSpelling() << RawTriple.str();
}
if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
@@ -5906,7 +5906,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_msvr4_struct_return)) {
if (!TC.getTriple().isPPC32()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str(false);
+ << A->getSpelling() << RawTriple.str();
} else if (A->getOption().matches(options::OPT_maix_struct_return)) {
CmdArgs.push_back("-maix-struct-return");
} else {
@@ -5919,7 +5919,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_freg_struct_return)) {
if (TC.getArch() != llvm::Triple::x86) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << RawTriple.str(false);
+ << A->getSpelling() << RawTriple.str();
} else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
CmdArgs.push_back("-fpcc-struct-return");
} else {
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index fc125992e1608..937ee09cac7cc 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1089,7 +1089,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
StringRef OptStr = HasRoptr ? "-mxcoff-roptr" : "-mno-xcoff-roptr";
if (!IsOSAIX)
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << OptStr << Triple.str(false);
+ << OptStr << Triple.str();
if (HasRoptr) {
// The data sections option is on by default on AIX. We only need to error
@@ -1636,7 +1636,7 @@ bool tools::addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
if (SanArgs.hasMemTag()) {
if (!TC.getTriple().isAndroid()) {
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fsanitize=memtag*" << TC.getTriple().str(false);
+ << "-fsanitize=memtag*" << TC.getTriple().str();
}
CmdArgs.push_back(
Args.MakeArgString("--android-memtag-mode=" + SanArgs.getMemtagMode()));
@@ -1889,7 +1889,7 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
options::OPT_fPIE, options::OPT_fpie)) {
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastPICArg->getSpelling() << Triple.str(false);
+ << LastPICArg->getSpelling() << Triple.str();
if (Triple.getArch() == llvm::Triple::x86_64)
return std::make_tuple(llvm::Reloc::PIC_, 2U, false);
return std::make_tuple(llvm::Reloc::Static, 0U, false);
@@ -1941,7 +1941,7 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
// uses it, and it isn't even valid on any OS but Darwin.
if (!Triple.isOSDarwin())
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << Triple.str(false);
+ << A->getSpelling() << Triple.str();
// FIXME: Warn when this flag trumps some other PIC or PIE flag.
@@ -1971,14 +1971,14 @@ tools::ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
if (!EmbeddedPISupported)
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastROPIArg->getSpelling() << Triple.str(false);
+ << LastROPIArg->getSpelling() << Triple.str();
ROPI = true;
}
Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
if (!EmbeddedPISupported)
ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << LastRWPIArg->getSpelling() << Triple.str(false);
+ << LastRWPIArg->getSpelling() << Triple.str();
RWPI = true;
}
@@ -2131,7 +2131,7 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
DwarfVersion = N;
if (DwarfVersion == 5 && TC.getTriple().isOSAIX())
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
- << GDwarfN->getSpelling() << TC.getTriple().str(false);
+ << GDwarfN->getSpelling() << TC.getTriple().str();
}
if (DwarfVersion == 0) {
DwarfVersion = TC.GetDefaultDwarfVersion();
diff --git a/clang/lib/Driver/ToolChains/CrossWindows.cpp b/clang/lib/Driver/ToolChains/CrossWindows.cpp
index 2246636054bdc..3c5dfba329cf8 100644
--- a/clang/lib/Driver/ToolChains/CrossWindows.cpp
+++ b/clang/lib/Driver/ToolChains/CrossWindows.cpp
@@ -94,7 +94,7 @@ void tools::CrossWindows::Linker::ConstructJob(
CmdArgs.push_back("-m");
switch (TC.getArch()) {
default:
- D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str(false);
+ D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
break;
case llvm::Triple::arm:
case llvm::Triple::thumb:
diff --git a/clang/lib/Driver/ToolChains/Cygwin.cpp b/clang/lib/Driver/ToolChains/Cygwin.cpp
index 628c5db4d8291..f0e90deee98b3 100644
--- a/clang/lib/Driver/ToolChains/Cygwin.cpp
+++ b/clang/lib/Driver/ToolChains/Cygwin.cpp
@@ -93,7 +93,7 @@ void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// On systems using multiarch, add /usr/include/$triple before
// /usr/include.
- std::string MultiarchIncludeDir = getTriple().str(false);
+ std::string MultiarchIncludeDir = getTriple().str();
if (!MultiarchIncludeDir.empty() &&
D.getVFS().exists(SysRoot + "/usr/include/" + MultiarchIncludeDir))
addExternCSystemInclude(DriverArgs, CC1Args,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index a29ec15e888d1..dcc46469df3e9 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -270,7 +270,7 @@ void Flang::AddPPCTargetArgs(const ArgList &Args,
if (VecExtabi) {
if (!T.isOSAIX()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-mabi=vec-extabi" << T.str(false);
+ << "-mabi=vec-extabi" << T.str();
}
CmdArgs.push_back("-mabi=vec-extabi");
}
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 80b26d5272f39..910db1dde0d18 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -331,7 +331,7 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
types::ID InputType) const {
llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
- return Triple.str(false);
+ return Triple.str();
}
Tool *Fuchsia::buildLinker() const { return new tools::fuchsia::Linker(*this); }
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5a1795d3848ef..e42cd0f97cb49 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -416,7 +416,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-m");
CmdArgs.push_back(LDMOption);
} else {
- D.Diag(diag::err_target_unknown_triple) << Triple.str(false);
+ D.Diag(diag::err_target_unknown_triple) << Triple.str();
return;
}
@@ -2171,7 +2171,7 @@ void Generic_GCC::GCCInstallationDetector::init(
SmallVector<StringRef, 16> CandidateTripleAliases;
SmallVector<StringRef, 16> CandidateBiarchTripleAliases;
// Add some triples that we want to check first.
- CandidateTripleAliases.push_back(TargetTriple.str(false));
+ CandidateTripleAliases.push_back(TargetTriple.str());
std::string TripleNoVendor, BiarchTripleNoVendor;
if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
@@ -2255,7 +2255,7 @@ void Generic_GCC::GCCInstallationDetector::init(
// x86_64-gentoo-linux-gnu. But "clang -target x86_64-gentoo-linux-gnu"
// may pick the libraries for x86_64-pc-linux-gnu even when exact matching
// triple x86_64-gentoo-linux-gnu is present.
- GentooTestTriples.push_back(TargetTriple.str(false));
+ GentooTestTriples.push_back(TargetTriple.str());
GentooTestTriples.append(CandidateTripleAliases.begin(),
CandidateTripleAliases.end());
if (ScanGentooConfigs(TargetTriple, Args, GentooTestTriples,
@@ -2815,8 +2815,8 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
}
// Also include the multiarch variant if it's different.
- if (TargetTriple.str(false) != BiarchTriple.str(false))
- BiarchTripleAliases.push_back(BiarchTriple.str(false));
+ if (TargetTriple.str() != BiarchTriple.str())
+ BiarchTripleAliases.push_back(BiarchTriple.str());
}
bool Generic_GCC::GCCInstallationDetector::ScanGCCForMultilibs(
@@ -3108,7 +3108,7 @@ void Generic_GCC::PushPPaths(ToolChain::path_list &PPaths) {
// used to target i386.
if (GCCInstallation.isValid()) {
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str(false) + "/bin")
+ GCCInstallation.getTriple().str() + "/bin")
.str());
}
}
@@ -3161,7 +3161,7 @@ void Generic_GCC::AddMultilibPaths(const Driver &D,
// Note that this matches the GCC behavior. See the below comment for where
// Clang diverges from GCC's behavior.
addPathIfExists(D,
- LibPath + "/../" + GCCTriple.str(false) + "/lib/../" + OSLibDir +
+ LibPath + "/../" + GCCTriple.str() + "/lib/../" + OSLibDir +
SelectedMultilibs.back().osSuffix(),
Paths);
@@ -3189,7 +3189,7 @@ void Generic_GCC::AddMultiarchPaths(const Driver &D,
const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
const Multilib &Multilib = GCCInstallation.getMultilib();
addPathIfExists(
- D, LibPath + "/../" + GCCTriple.str(false) + "/lib" + Multilib.osSuffix(),
+ D, LibPath + "/../" + GCCTriple.str() + "/lib" + Multilib.osSuffix(),
Paths);
}
}
@@ -3203,7 +3203,7 @@ void Generic_GCC::AddMultilibIncludeArgs(const ArgList &DriverArgs,
const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
std::string LibPath(GCCInstallation.getParentLibPath());
addSystemInclude(DriverArgs, CC1Args,
- Twine(LibPath) + "/../" + GCCTriple.str(false) + "/include");
+ Twine(LibPath) + "/../" + GCCTriple.str() + "/include");
const auto &Callback = Multilibs.includeDirsCallback();
if (Callback) {
@@ -3334,7 +3334,7 @@ bool Generic_GCC::addGCCLibStdCxxIncludePaths(
// equivalent to '/usr/include/c++/X.Y' in almost all cases.
StringRef LibDir = GCCInstallation.getParentLibPath();
StringRef InstallDir = GCCInstallation.getInstallPath();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
const GCCVersion &Version = GCCInstallation.getVersion();
@@ -3389,7 +3389,7 @@ Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
if (GCCInstallation.isValid()) {
addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args,
- GCCInstallation.getTriple().str(false));
+ GCCInstallation.getTriple().str());
}
}
diff --git a/clang/lib/Driver/ToolChains/Hurd.cpp b/clang/lib/Driver/ToolChains/Hurd.cpp
index 3fccd174db006..0bc114b90ffc0 100644
--- a/clang/lib/Driver/ToolChains/Hurd.cpp
+++ b/clang/lib/Driver/ToolChains/Hurd.cpp
@@ -49,7 +49,7 @@ std::string Hurd::getMultiarchTriple(const Driver &D,
// For most architectures, just use whatever we have rather than trying to be
// clever.
- return TargetTriple.str(false);
+ return TargetTriple.str();
}
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
@@ -207,7 +207,7 @@ void Hurd::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
if (!GCCInstallation.isValid())
return;
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
StringRef DebianMultiarch =
GCCInstallation.getTriple().getArch() == llvm::Triple::x86 ? "i386-gnu"
: TripleStr;
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 79e67a9270123..19919cf5136d8 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -101,12 +101,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
} else if (TargetTriple.isMusl()) {
Libc = "musl";
} else {
- return TargetTriple.str(false);
+ return TargetTriple.str();
}
switch (TargetEnvironment) {
default:
- return TargetTriple.str(false);
+ return TargetTriple.str();
case llvm::Triple::GNUSF:
case llvm::Triple::MuslSF:
FPFlavor = "sf";
@@ -174,7 +174,7 @@ std::string Linux::getMultiarchTriple(const Driver &D,
case llvm::Triple::systemz:
return "s390x-linux-gnu";
}
- return TargetTriple.str(false);
+ return TargetTriple.str();
}
static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
@@ -406,7 +406,7 @@ std::string Linux::computeSysRoot() const {
// $GCCToolchainPath/lib/gcc/csky-linux-gnuabiv2/6.3.0
// Path = $GCCToolchainPath/csky-linux-gnuabiv2/libc
std::string Path = (GCCInstallation.getInstallPath() + "/../../../../" +
- GCCInstallation.getTriple().str(false) + "/libc")
+ GCCInstallation.getTriple().str() + "/libc")
.str();
if (getVFS().exists(Path))
return Path;
@@ -421,7 +421,7 @@ std::string Linux::computeSysRoot() const {
// variants.
const StringRef InstallDir = GCCInstallation.getInstallPath();
- const StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ const StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
std::string Path =
@@ -620,7 +620,7 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
if (Distro == Distro::Exherbo &&
(Triple.getVendor() == llvm::Triple::UnknownVendor ||
Triple.getVendor() == llvm::Triple::PC))
- return "/usr/" + Triple.str(false) + "/lib/" + Loader;
+ return "/usr/" + Triple.str() + "/lib/" + Loader;
return "/" + LibDir + "/" + Loader;
}
@@ -694,7 +694,7 @@ void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
return;
// Detect Debian g++-multiarch-incdir.diff.
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
StringRef DebianMultiarch =
GCCInstallation.getTriple().getArch() == llvm::Triple::x86
? "i386-linux-gnu"
@@ -756,7 +756,7 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
CC1Args.push_back("-isystem");
CC1Args.push_back(DriverArgs.MakeArgString(
GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str(false) + "/include"));
+ GCCInstallation.getTriple().str() + "/include"));
}
}
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 8b7150441d281..2245b036b8459 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -141,7 +141,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("mipspe");
break;
default:
- D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str(false);
+ D.Diag(diag::err_target_unknown_triple) << TC.getEffectiveTriple().str();
}
Arg *SubsysArg =
@@ -414,8 +414,8 @@ static llvm::Triple getLiteralTriple(const Driver &D, const llvm::Triple &T) {
void toolchains::MinGW::findGccLibDir(const llvm::Triple &LiteralTriple) {
llvm::SmallVector<llvm::SmallString<32>, 5> SubdirNames;
- SubdirNames.emplace_back(LiteralTriple.str(false));
- SubdirNames.emplace_back(getTriple().str(false));
+ SubdirNames.emplace_back(LiteralTriple.str());
+ SubdirNames.emplace_back(getTriple().str());
SubdirNames.emplace_back(getTriple().getArchName());
SubdirNames.back() += "-w64-mingw32";
SubdirNames.emplace_back(getTriple().getArchName());
@@ -442,9 +442,9 @@ void toolchains::MinGW::findGccLibDir(const llvm::Triple &LiteralTriple) {
static llvm::ErrorOr<std::string> findGcc(const llvm::Triple &LiteralTriple,
const llvm::Triple &T) {
llvm::SmallVector<llvm::SmallString<32>, 5> Gccs;
- Gccs.emplace_back(LiteralTriple.str(false));
+ Gccs.emplace_back(LiteralTriple.str());
Gccs.back() += "-gcc";
- Gccs.emplace_back(T.str(false));
+ Gccs.emplace_back(T.str());
Gccs.back() += "-gcc";
Gccs.emplace_back(T.getArchName());
Gccs.back() += "-w64-mingw32-gcc";
@@ -462,8 +462,8 @@ static llvm::ErrorOr<std::string>
findClangRelativeSysroot(const Driver &D, const llvm::Triple &LiteralTriple,
const llvm::Triple &T, std::string &SubdirName) {
llvm::SmallVector<llvm::SmallString<32>, 4> Subdirs;
- Subdirs.emplace_back(LiteralTriple.str(false));
- Subdirs.emplace_back(T.str(false));
+ Subdirs.emplace_back(LiteralTriple.str());
+ Subdirs.emplace_back(T.str());
Subdirs.emplace_back(T.getArchName());
Subdirs.back() += "-w64-mingw32";
Subdirs.emplace_back(T.getArchName());
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp
index 5275b79ce4eab..72f36d08f4da7 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -112,7 +112,7 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) const {
case llvm::Triple::loongarch64:
return "loongarch64-linux-ohos";
}
- return T.str(false);
+ return T.str();
}
std::string OHOS::getMultiarchTriple(const Driver &D,
@@ -296,7 +296,7 @@ ToolChain::path_list OHOS::getRuntimePaths() const {
// Second try the normalized triple.
P.assign(D.ResourceDir);
- llvm::sys::path::append(P, "lib", Triple.str(false), SelectedMultilib.gccSuffix());
+ llvm::sys::path::append(P, "lib", Triple.str(), SelectedMultilib.gccSuffix());
Paths.push_back(P.c_str());
// Third try the effective triple.
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index ab1250618845b..cb56a7ebeba24 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -209,7 +209,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fuse-ld" << TC.getTriple().str(false);
+ << "-fuse-ld" << TC.getTriple().str();
}
std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
@@ -432,7 +432,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fuse-ld" << TC.getTriple().str(false);
+ << "-fuse-ld" << TC.getTriple().str();
}
std::string LdName = TC.qualifyPSCmdName(TC.getLinkerBaseName());
@@ -570,7 +570,7 @@ void toolchains::PS4PS5Base::addClangTargetOptions(
if (DriverArgs.hasArg(options::OPT_fuse_init_array)) {
Arg *A = DriverArgs.getLastArg(options::OPT_fuse_init_array);
getDriver().Diag(clang::diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(DriverArgs) << getTriple().str(false);
+ << A->getAsString(DriverArgs) << getTriple().str();
}
CC1Args.push_back("-fno-use-init-array");
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 1bdf590741147..d88ddc264d72a 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -62,7 +62,7 @@ RISCVToolChain::RISCVToolChain(const Driver &D, const llvm::Triple &Triple,
// Multilib cross-compiler GCC installations put ld in a triple-prefixed
// directory off of the parent of the GCC installation.
PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
- GCCInstallation.getTriple().str(false) + "/bin")
+ GCCInstallation.getTriple().str() + "/bin")
.str());
PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
} else {
@@ -119,7 +119,7 @@ void RISCVToolChain::addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
const GCCVersion &Version = GCCInstallation.getVersion();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
addLibStdCXXIncludePaths(computeSysRoot() + "/include/c++/" + Version.Text,
TripleStr, Multilib.includeSuffix(), DriverArgs,
@@ -133,7 +133,7 @@ std::string RISCVToolChain::computeSysRoot() const {
SmallString<128> SysRootDir;
if (GCCInstallation.isValid()) {
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
} else {
// Use the triple as provided to the driver. Unlike the parsed triple
diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp
index 5f724ca36e4c5..6611c142a5efd 100644
--- a/clang/lib/Driver/ToolChains/SYCL.cpp
+++ b/clang/lib/Driver/ToolChains/SYCL.cpp
@@ -67,7 +67,7 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
for (OptSpecifier Opt : getUnsupportedOpts()) {
if (const Arg *A = Args.getLastArg(Opt)) {
D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
- << A->getAsString(Args) << getTriple().str(false);
+ << A->getAsString(Args) << getTriple().str();
}
}
}
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index 5c6041f60254b..48d1002381761 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -414,7 +414,7 @@ void Solaris::addLibStdCxxIncludePaths(
// the lib directory of the GCC installation.
// On Solaris this usually looks like /usr/gcc/X.Y/include/c++/X.Y.Z
StringRef LibDir = GCCInstallation.getParentLibPath();
- StringRef TripleStr = GCCInstallation.getTriple().str(false);
+ StringRef TripleStr = GCCInstallation.getTriple().str();
const Multilib &Multilib = GCCInstallation.getMultilib();
const GCCVersion &Version = GCCInstallation.getVersion();
diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 65a5a11bef1cd..701dd2906dccb 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -35,7 +35,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str(false);
+ << XRayInstrument->getSpelling() << Triple.str();
break;
}
} else if (Triple.isOSBinFormatELF()) {
@@ -56,11 +56,11 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str(false);
+ << XRayInstrument->getSpelling() << Triple.str();
}
} else {
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << XRayInstrument->getSpelling() << Triple.str(false);
+ << XRayInstrument->getSpelling() << Triple.str();
}
if (Args.hasFlag(options::OPT_fxray_shared, options::OPT_fno_xray_shared,
@@ -74,7 +74,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
- << "-fxray-shared" << Triple.str(false);
+ << "-fxray-shared" << Triple.str();
}
unsigned PICLvl = std::get<1>(tools::ParsePICArgs(TC, Args));
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index c759ec33f9952..587b0d1af9c8d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -122,7 +122,7 @@ bool CompilerInstance::createTarget() {
TO->CPU = *getFrontendOpts().AuxTargetCPU;
if (getFrontendOpts().AuxTargetFeatures)
TO->FeaturesAsWritten = *getFrontendOpts().AuxTargetFeatures;
- TO->HostTriple = getTarget().getTriple().str(false);
+ TO->HostTriple = getTarget().getTriple().str();
setAuxTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), *TO));
}
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index cbbb211cb0478..2c02719121c73 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -597,7 +597,7 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
LangOptions::ExceptionHandlingKind::None &&
T.isWindowsMSVCEnvironment())
Diags.Report(diag::err_fe_invalid_exception_model)
- << static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str(false);
+ << static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str();
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
Diags.Report(diag::warn_c_kext);
@@ -2169,7 +2169,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
// future.
if (T.isOSAIX())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str(false);
+ << A->getSpelling() << T.str();
const Option &O = A->getOption();
if (O.matches(OPT_fpcc_struct_return) ||
@@ -2185,7 +2185,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
if (Arg *A = Args.getLastArg(OPT_mxcoff_roptr)) {
if (!T.isOSAIX())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str(false);
+ << A->getSpelling() << T.str();
// Since the storage mapping class is specified per csect,
// without using data sections, it is less effective to use read-only
@@ -2204,7 +2204,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
if (Arg *A = Args.getLastArg(OPT_mabi_EQ_quadword_atomics)) {
if (!T.isOSAIX() || T.isPPC32())
Diags.Report(diag::err_drv_unsupported_opt_for_target)
- << A->getSpelling() << T.str(false);
+ << A->getSpelling() << T.str();
}
bool NeedLocTracking = false;
@@ -3848,7 +3848,7 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
llvm::raw_string_ostream OS(Targets);
llvm::interleave(
Opts.OMPTargetTriples, OS,
- [&OS](const llvm::Triple &T) { OS << T.str(false); }, ",");
+ [&OS](const llvm::Triple &T) { OS << T.str(); }, ",");
GenerateArg(Consumer, OPT_fopenmp_targets_EQ, Targets);
}
@@ -4278,7 +4278,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
// Add unsupported host targets here:
case llvm::Triple::nvptx:
case llvm::Triple::nvptx64:
- Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str(false);
+ Diags.Report(diag::err_drv_omp_host_target_not_supported) << T.str();
break;
}
}
@@ -4348,7 +4348,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Diags.Report(diag::err_drv_invalid_omp_target) << A->getValue(i);
else if (getArchPtrSize(T) != getArchPtrSize(TT))
Diags.Report(diag::err_drv_incompatible_omp_arch)
- << A->getValue(i) << T.str(false);
+ << A->getValue(i) << T.str();
else
Opts.OMPTargetTriples.push_back(TT);
}
@@ -4521,7 +4521,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
} else {
auto Kind = TargetCXXABI::getKind(CXXABI);
if (!TargetCXXABI::isSupportedCXXABI(T, Kind))
- Diags.Report(diag::err_unsupported_cxx_abi) << CXXABI << T.str(false);
+ Diags.Report(diag::err_unsupported_cxx_abi) << CXXABI << T.str();
else
Opts.CXXABI = Kind;
}
@@ -4584,19 +4584,19 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (T.getOSName().empty()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
- << ExpectedOS << OS << T.str(false);
+ << ExpectedOS << OS << T.str();
} else if (T.getEnvironmentName().empty()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_required_in_target)
- << ShaderStage << Environment << T.str(false);
+ << ShaderStage << Environment << T.str();
} else if (!T.isShaderStageEnvironment()) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << ShaderStage << T.getEnvironmentName() << T.str(false);
+ << ShaderStage << T.getEnvironmentName() << T.str();
}
if (T.isDXIL()) {
if (!T.isShaderModelOS() || T.getOSVersion() == VersionTuple(0)) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << ShaderModel << T.getOSName() << T.str(false);
+ << ShaderModel << T.getOSName() << T.str();
}
// Validate that if fnative-half-type is given, that
// the language standard is at least hlsl2018, and that
@@ -4613,7 +4613,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
} else if (T.isSPIRVLogical()) {
if (!T.isVulkanOS() || T.getVulkanVersion() == VersionTuple(0)) {
Diags.Report(diag::err_drv_hlsl_bad_shader_unsupported)
- << VulkanEnv << T.getOSName() << T.str(false);
+ << VulkanEnv << T.getOSName() << T.str();
}
if (Args.getLastArg(OPT_fnative_half_type)) {
const LangStandard &Std =
@@ -4626,7 +4626,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
llvm_unreachable("expected DXIL or SPIR-V target");
}
} else
- Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str(false);
+ Diags.Report(diag::err_drv_hlsl_unsupported_target) << T.str();
if (Opts.LangStd < LangStandard::lang_hlsl202x) {
const LangStandard &Requested =
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index ceae977e521b4..d7cfd23bb0a7a 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -292,7 +292,7 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
raw_ostream &OS) -> void {
OS << "--- !" << Format << "\n";
OS << "IfsVersion: 3.0\n";
- OS << "Target: " << T.str(false) << "\n";
+ OS << "Target: " << T.str() << "\n";
OS << "Symbols:\n";
for (const auto &E : Symbols) {
const MangledSymbol &Symbol = E.second;
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index fab8963ead4c0..370ade6dea7a1 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2164,8 +2164,8 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
else
PD << "expression";
targetDiag(Loc, PD, FD)
- << false /*show bit size*/ << 0 << Ty << false /*return*/
- << Context.getTargetInfo().getTriple().str(false);
+ << false /*show bit size*/ << 0 /*bitsize*/ << false /*return*/
+ << Ty << Context.getTargetInfo().getTriple().str();
}
return;
}
@@ -2199,7 +2199,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (targetDiag(Loc, PD, FD)
<< true /*show bit size*/
<< static_cast<unsigned>(Context.getTypeSize(Ty)) << Ty
- << false /*return*/ << Context.getTargetInfo().getTriple().str(false)) {
+ << false /*return*/ << Context.getTargetInfo().getTriple().str()) {
if (D)
D->setInvalidDecl();
}
@@ -2225,7 +2225,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (Diag(Loc, PD, FD)
<< false /*show bit size*/ << 0 << Ty << false /*return*/
- << TI.getTriple().str(false)) {
+ << TI.getTriple().str()) {
if (D)
D->setInvalidDecl();
}
@@ -2244,7 +2244,7 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
if (Diag(Loc, PD, FD)
<< false /*show bit size*/ << 0 << Ty << true /*return*/
- << TI.getTriple().str(false)) {
+ << TI.getTriple().str()) {
if (D)
D->setInvalidDecl();
}
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d3039e58b2a32..2546ab5c0a342 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -853,7 +853,7 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
// In OpenMP target regions, we replace 'throw' with a trap on GPU targets.
if (IsOpenMPGPUTarget)
- targetDiag(OpLoc, diag::warn_throw_not_valid_on_target) << T.str(false);
+ targetDiag(OpLoc, diag::warn_throw_not_valid_on_target) << T.str();
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index dc23f01d237bd..9b4d82745f881 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -229,7 +229,7 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo &TI,
BuiltinID == PPC::BI__builtin_ppc_minfe))
return Diag(TheCall->getBeginLoc(), diag::err_target_unsupported_type)
<< "builtin" << true << 128 << QualType(Context.LongDoubleTy)
- << false << Context.getTargetInfo().getTriple().str(false);
+ << false << Context.getTargetInfo().getTriple().str();
// Argument type should be exact.
QualType ArgType = QualType(Context.LongDoubleTy);
if (BuiltinID == PPC::BI__builtin_ppc_maxfl ||
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 1c9c694823596..50f5757dff5bc 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -4317,7 +4317,7 @@ StmtResult Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
// In OpenMP target regions, we assume that catch is never reached on GPU
// targets.
if (IsOpenMPGPUTarget)
- targetDiag(TryLoc, diag::warn_try_not_valid_on_target) << T.str(false);
+ targetDiag(TryLoc, diag::warn_try_not_valid_on_target) << T.str();
// Exceptions aren't allowed in CUDA device code.
if (getLangOpts().CUDA)
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f340db373c3ec..23db009654f4f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -513,7 +513,7 @@ bool LLParser::parseTargetDefinitions(DataLayoutCallbackTy DataLayoutCallback) {
// Run the override callback to potentially change the data layout string, and
// parse the data layout string.
if (auto LayoutOverride =
- DataLayoutCallback(M->getTargetTriple().str(false), TentativeDLStr)) {
+ DataLayoutCallback(M->getTargetTriple().str(), TentativeDLStr)) {
TentativeDLStr = *LayoutOverride;
DLStrLoc = {};
}
diff --git a/llvm/lib/BinaryFormat/MachO.cpp b/llvm/lib/BinaryFormat/MachO.cpp
index a0d428ce75bcd..f46b9d5147ff1 100644
--- a/llvm/lib/BinaryFormat/MachO.cpp
+++ b/llvm/lib/BinaryFormat/MachO.cpp
@@ -71,7 +71,7 @@ static MachO::CPUSubTypePowerPC getPowerPCSubType(const Triple &T) {
static Error unsupported(const char *Str, const Triple &T) {
return createStringError(std::errc::invalid_argument,
"Unsupported triple for mach-o cpu %s: %s", Str,
- T.str(false).c_str());
+ T.str().c_str());
}
Expected<uint32_t> MachO::getCPUType(const Triple &T) {
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 29a45a6c96e18..105edb943eb7f 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4512,12 +4512,12 @@ Error BitcodeReader::parseModule(uint64_t ResumeBit,
// Auto-upgrade the layout string
TentativeDataLayoutStr = llvm::UpgradeDataLayoutString(
- TentativeDataLayoutStr, TheModule->getTargetTriple().str(false));
+ TentativeDataLayoutStr, TheModule->getTargetTriple().str());
// Apply override
if (Callbacks.DataLayout) {
if (auto LayoutOverride = (*Callbacks.DataLayout)(
- TheModule->getTargetTriple().str(false), TentativeDataLayoutStr))
+ TheModule->getTargetTriple().str(), TentativeDataLayoutStr))
TentativeDataLayoutStr = *LayoutOverride;
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 816fd6c7bf202..fad8ebfad9f9a 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1476,7 +1476,7 @@ void ModuleBitcodeWriter::writeModuleInfo() {
// Emit various pieces of data attached to a module.
if (!M.getTargetTriple().empty())
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
- M.getTargetTriple().str(false), 0 /*TODO*/);
+ M.getTargetTriple().str(), 0 /*TODO*/);
const std::string &DL = M.getDataLayoutStr();
if (!DL.empty())
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index 9913f2a4b242c..4a3503a2da7db 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -44,7 +44,7 @@ static cl::opt<bool> EnableNoTrapAfterNoreturn(
"after noreturn calls, even if --trap-unreachable is set."));
void CodeGenTargetMachineImpl::initAsmInfo() {
- MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str(false)));
+ MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
assert(MRI && "Unable to create reg info");
MII.reset(TheTarget.createMCInstrInfo());
assert(MII && "Unable to create instruction info");
@@ -53,11 +53,11 @@ void CodeGenTargetMachineImpl::initAsmInfo() {
// code generation. This is similar to the hack in the AsmPrinter for
// module level assembly etc.
STI.reset(TheTarget.createMCSubtargetInfo(
- getTargetTriple().str(false), getTargetCPU(), getTargetFeatureString()));
+ getTargetTriple().str(), getTargetCPU(), getTargetFeatureString()));
assert(STI && "Unable to create subtarget info");
MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(
- *MRI, getTargetTriple().str(false), Options.MCOptions);
+ *MRI, getTargetTriple().str(), Options.MCOptions);
// TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0,
// and if the old one gets included then MCAsmInfo will be NULL and
// we'll crash later.
@@ -197,7 +197,7 @@ CodeGenTargetMachineImpl::createMCStreamer(raw_pwrite_stream &Out,
return make_error<StringError>("createMCAsmBackend failed",
inconvertibleErrorCode());
- Triple T(getTargetTriple().str(false));
+ Triple T(getTargetTriple().str());
AsmStreamer.reset(getTarget().createMCObjectStreamer(
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index 2a13f785f5f74..a57bda54f9180 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -253,7 +253,7 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
// Create an empty module when the MIR file is empty.
NoMIRDocuments = true;
auto M = std::make_unique<Module>(Filename, Context);
- if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(false),
+ if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
return M;
@@ -277,7 +277,7 @@ MIRParserImpl::parseIRModule(DataLayoutCallbackTy DataLayoutCallback) {
} else {
// Create an new, empty module.
M = std::make_unique<Module>(Filename, Context);
- if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(false),
+ if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
M->getDataLayoutStr()))
M->setDataLayout(*LayoutOverride);
NoLLVMIR = true;
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
index 61a301ec1d6cf..ff48a938cbd42 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp
@@ -757,7 +757,7 @@ class RuntimeDyldCheckerExprEval {
Expected<TargetInfo> getTargetInfo(const Triple &TT, const StringRef &CPU,
const SubtargetFeatures &TF) const {
- auto TripleName = TT.str(false);
+ auto TripleName = TT.str();
std::string ErrorStr;
const Target *TheTarget =
TargetRegistry::lookupTarget(TripleName, ErrorStr);
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 13dd4cd130837..7223dd845d18d 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -3103,7 +3103,7 @@ void AssemblyWriter::printModule(const Module *M) {
if (!DL.empty())
Out << "target datalayout = \"" << DL << "\"\n";
if (!M->getTargetTriple().empty())
- Out << "target triple = \"" << M->getTargetTriple().str(false) << "\"\n";
+ Out << "target triple = \"" << M->getTargetTriple().str() << "\"\n";
if (!M->getModuleInlineAsm().empty()) {
Out << '\n';
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index eb5de3bebaf5a..1954b44af22ad 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -321,7 +321,7 @@ void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr) {
/*--.. Target triple .......................................................--*/
const char * LLVMGetTarget(LLVMModuleRef M) {
- return unwrap(M)->getTargetTriple().str(false).c_str();
+ return unwrap(M)->getTargetTriple().str().c_str();
}
void LLVMSetTarget(LLVMModuleRef M, const char *TripleStr) {
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index f5f254f3f59e4..ba120a0566834 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -2373,7 +2373,7 @@ class OutOfProcessThinBackend : public CGThinBackend {
JOS.value("-c");
- JOS.value(Saver.save("--target=" + Triple.str(false)));
+ JOS.value(Saver.save("--target=" + Triple.str()));
for (const auto &A : CodegenOptions)
JOS.value(A);
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 9765db53df6bf..09b91d81225a8 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -375,7 +375,7 @@ bool LTOCodeGenerator::determineTarget() {
if (TargetMach)
return true;
- TripleStr = MergedModule->getTargetTriple().str(false);
+ TripleStr = MergedModule->getTargetTriple().str();
llvm::Triple Triple(TripleStr);
if (TripleStr.empty()) {
TripleStr = sys::getDefaultTargetTriple();
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index 0296d24144eb6..4dd5ae81c89c1 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -1492,9 +1492,9 @@ Error IRLinker::run() {
!SrcTriple.isCompatibleWith(DstTriple))
emitWarning("Linking two modules of different target triples: '" +
SrcM->getModuleIdentifier() + "' is '" +
- SrcM->getTargetTriple().str(false) + "' whereas '" +
+ SrcM->getTargetTriple().str() + "' whereas '" +
DstM.getModuleIdentifier() + "' is '" +
- DstM.getTargetTriple().str(false) + "'\n");
+ DstM.getTargetTriple().str() + "'\n");
DstM.setTargetTriple(Triple(SrcTriple.merge(DstTriple)));
diff --git a/llvm/lib/MC/TargetRegistry.cpp b/llvm/lib/MC/TargetRegistry.cpp
index 393a75829933c..9263dda65a8b0 100644
--- a/llvm/lib/MC/TargetRegistry.cpp
+++ b/llvm/lib/MC/TargetRegistry.cpp
@@ -152,7 +152,7 @@ const Target *TargetRegistry::lookupTarget(const Triple &TT,
if (I == targets().end()) {
Error =
- "No available targets are compatible with triple \"" + TT.str(false) + "\"";
+ "No available targets are compatible with triple \"" + TT.str() + "\"";
return nullptr;
}
diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp
index 323ef1e007d25..167fc27cf74ef 100644
--- a/llvm/lib/Object/IRObjectFile.cpp
+++ b/llvm/lib/Object/IRObjectFile.cpp
@@ -66,7 +66,7 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
StringRef IRObjectFile::getTargetTriple() const {
// Each module must have the same target triple, so we arbitrarily access the
// first one.
- return Mods[0]->getTargetTriple().str(false);
+ return Mods[0]->getTargetTriple().str();
}
Expected<MemoryBufferRef>
diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp
index 6954bc71adef1..806477ae3de01 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -349,7 +349,7 @@ Error Builder::build(ArrayRef<Module *> IRMods) {
assert(!IRMods.empty());
Hdr.Version = storage::Header::kCurrentVersion;
setStr(Hdr.Producer, kExpectedProducerName);
- setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str(false));
+ setStr(Hdr.TargetTriple, IRMods[0]->getTargetTriple().str());
setStr(Hdr.SourceFileName, IRMods[0]->getSourceFileName());
TT = IRMods[0]->getTargetTriple();
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index 9e0c8d45193c6..1706772912772 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -81,17 +81,17 @@ initializeRecordStreamer(const Module &M,
const Target *T = TargetRegistry::lookupTarget(TT, Err);
assert(T && T->hasMCAsmParser());
- std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str(false)));
+ std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str()));
if (!MRI)
return;
MCTargetOptions MCOptions;
- std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str(false), MCOptions));
+ std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str(), MCOptions));
if (!MAI)
return;
std::unique_ptr<MCSubtargetInfo> STI(
- T->createMCSubtargetInfo(TT.str(false), "", ""));
+ T->createMCSubtargetInfo(TT.str(), "", ""));
if (!STI)
return;
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 392ef5018f73c..0d019bda36130 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -726,7 +726,7 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
const Triple &TT = TM.getTargetTriple();
assert(TT.isOSBinFormatELF());
std::unique_ptr<MCSubtargetInfo> STI(
- TM.getTarget().createMCSubtargetInfo(TT.str(false), "", ""));
+ TM.getTarget().createMCSubtargetInfo(TT.str(), "", ""));
assert(STI && "Unable to create subtarget info");
this->STI = static_cast<const AArch64Subtarget *>(&*STI);
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 7da5169dadb38..1a3e99ec7f68f 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -972,7 +972,7 @@ void MipsAsmPrinter::EmitFPCallStub(
// freed) and since we're at the global level we can use the default
// constructed subtarget.
std::unique_ptr<MCSubtargetInfo> STI(TM.getTarget().createMCSubtargetInfo(
- TM.getTargetTriple().str(false), TM.getTargetCPU(),
+ TM.getTargetTriple().str(), TM.getTargetCPU(),
TM.getTargetFeatureString()));
//
diff --git a/llvm/lib/Target/SPIRV/SPIRVSubtarget.h b/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
index 61ff61564229c..ad3e38d296ed7 100644
--- a/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
+++ b/llvm/lib/Target/SPIRV/SPIRVSubtarget.h
@@ -101,7 +101,7 @@ class SPIRVSubtarget : public SPIRVGenSubtargetInfo {
return TargetTriple.getArch() == Triple::spirv32 ||
TargetTriple.getArch() == Triple::spirv64;
}
- const std::string &getTargetTripleAsStr() const { return TargetTriple.str(false); }
+ const std::string &getTargetTripleAsStr() const { return TargetTriple.str(); }
VersionTuple getSPIRVVersion() const { return SPIRVVersion; };
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const;
bool isAtLeastOpenCLVer(VersionTuple VerToCompareTo) const;
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index 94ebf6804d7c3..da6d35c8c8b43 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -233,7 +233,7 @@ LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T) {
}
char* LLVMGetTargetMachineTriple(LLVMTargetMachineRef T) {
- std::string StringRep = unwrap(T)->getTargetTriple().str(false);
+ std::string StringRep = unwrap(T)->getTargetTriple().str();
return strdup(StringRep.c_str());
}
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 82b213eae9e0e..14acef116708a 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2285,7 +2285,7 @@ std::string sys::getProcessTriple() {
if (sizeof(void *) == 4 && PT.isArch64Bit())
PT = PT.get32BitArchVariant();
- return PT.str(false);
+ return PT.str();
}
void sys::printDefaultTargetAndDetectedCPU(raw_ostream &OS) {
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index cab05ca87866f..6a559ff023caa 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2102,9 +2102,9 @@ std::string Triple::merge(const Triple &Other) const {
// If vendor is apple, pick the triple with the larger version number.
if (getVendor() == Triple::Apple)
if (Other.isOSVersionLT(*this))
- return str(false);
+ return str();
- return Other.str(false);
+ return Other.str();
}
bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
diff --git a/llvm/lib/TargetParser/Unix/Host.inc b/llvm/lib/TargetParser/Unix/Host.inc
index b3f3a6cfe82c5..a33fe6fff8936 100644
--- a/llvm/lib/TargetParser/Unix/Host.inc
+++ b/llvm/lib/TargetParser/Unix/Host.inc
@@ -65,7 +65,7 @@ static std::string updateTripleOSVersion(std::string TargetTripleString) {
NewOSName += name.release;
NewOSName += ".0.0";
TT.setOSName(NewOSName);
- return TT.str(false);
+ return TT.str();
}
}
}
>From d6878b1b4d172f0821bce019d1af001f738b5270 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 20 Jun 2025 16:19:43 -0700
Subject: [PATCH 4/6] Implement clone and update lldb files
---
lldb/source/API/SBDebugger.cpp | 2 +-
lldb/source/API/SBModule.cpp | 2 +-
lldb/source/API/SBModuleSpec.cpp | 2 +-
lldb/source/API/SBTarget.cpp | 2 +-
lldb/source/Core/Module.cpp | 4 +-
.../DynamicLoaderDarwinKernel.cpp | 2 +-
.../DynamicLoaderFreeBSDKernel.cpp | 2 +-
.../Clang/ClangExpressionParser.cpp | 2 +-
.../Clang/ClangModulesDeclVendor.cpp | 2 +-
.../Clang/CppModuleConfiguration.cpp | 8 +-
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 2 +-
.../gdb-server/PlatformRemoteGDBServer.cpp | 2 +-
.../TypeSystem/Clang/TypeSystemClang.cpp | 6 +-
lldb/source/Target/Platform.cpp | 2 +-
lldb/source/Target/Statistics.cpp | 2 +-
llvm/include/llvm/TargetParser/Triple.h | 21 ++++-
llvm/lib/TargetParser/Triple.cpp | 39 +++++++++
llvm/unittests/TargetParser/TripleTest.cpp | 82 +++++++++++++++++++
18 files changed, 160 insertions(+), 24 deletions(-)
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index d598ae92fec45..282edcc7c694a 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -642,7 +642,7 @@ bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
ArchSpec default_arch = Target::GetDefaultArchitecture();
if (default_arch.IsValid()) {
- const std::string &triple_str = default_arch.GetTriple().str(false);
+ const std::string &triple_str = default_arch.GetTriple().clone(true, false).str();
if (!triple_str.empty())
::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
else
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 1011586a89407..8f93ba1eb0f7c 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -576,7 +576,7 @@ const char *SBModule::GetTriple() {
if (!module_sp)
return nullptr;
- std::string triple(module_sp->GetArchitecture().GetTriple().str(false));
+ std::string triple(module_sp->GetArchitecture().GetTriple().clone(true, false).str());
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index 620d5f91fa0ce..1082fa32f438b 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -112,7 +112,7 @@ void SBModuleSpec::SetObjectName(const char *name) {
const char *SBModuleSpec::GetTriple() {
LLDB_INSTRUMENT_VA(this);
- std::string triple(m_opaque_up->GetArchitecture().GetTriple().str(false));
+ std::string triple(m_opaque_up->GetArchitecture().GetTriple().clone(true, false).str());
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index b99786f388ec5..6f540a35707b6 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1576,7 +1576,7 @@ const char *SBTarget::GetTriple() {
LLDB_INSTRUMENT_VA(this);
if (TargetSP target_sp = GetSP()) {
- std::string triple(target_sp->GetArchitecture().GetTriple().str(false));
+ std::string triple(target_sp->GetArchitecture().GetTriple().clone(true, false).str());
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 5fba6c346afea..0ee9519450c32 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1612,7 +1612,7 @@ bool Module::GetIsDynamicLinkEditor() {
uint32_t Module::Hash() {
std::string identifier;
llvm::raw_string_ostream id_strm(identifier);
- id_strm << m_arch.GetTriple().str(false) << '-' << m_file.GetPath();
+ id_strm << m_arch.GetTriple().clone(true, false).str() << '-' << m_file.GetPath();
if (m_object_name)
id_strm << '(' << m_object_name << ')';
if (m_object_offset > 0)
@@ -1626,7 +1626,7 @@ uint32_t Module::Hash() {
std::string Module::GetCacheKey() {
std::string key;
llvm::raw_string_ostream strm(key);
- strm << m_arch.GetTriple().str(false) << '-' << m_file.GetFilename();
+ strm << m_arch.GetTriple().clone(true, false).str() << '-' << m_file.GetFilename();
if (m_object_name)
strm << '(' << m_object_name << ')';
strm << '-' << llvm::format_hex(Hash(), 10);
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 4a6e039916b93..5b2d3dff9f9b8 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -498,7 +498,7 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr,
log,
"DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str(false).c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().clone(true, false).str().c_str(), uuid_str.c_str());
}
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index f5e94e8113b9a..aee58d748146d 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -236,7 +236,7 @@ lldb_private::UUID DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
LLDB_LOGF(log,
"DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str(false).c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().clone(true, false).str().c_str(), uuid_str.c_str());
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index 9c1c643745869..dc1f04434bba9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -509,7 +509,7 @@ static void SetupTargetOpts(CompilerInstance &compiler,
const auto target_machine = target_arch.GetMachine();
if (target_arch.IsValid()) {
- std::string triple = target_arch.GetTriple().str(false);
+ std::string triple = target_arch.GetTriple().clone(true, false).str();
compiler.getTargetOpts().Triple = triple;
LLDB_LOGF(log, "Using %s as the target triple",
compiler.getTargetOpts().Triple.c_str());
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index 6147ca3719ab0..bfd42194c4e51 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -659,7 +659,7 @@ ClangModulesDeclVendor::Create(Target &target) {
"-fsyntax-only",
"-femit-all-decls",
"-target",
- arch.GetTriple().str(false),
+ arch.GetTriple().clone(true, false).str(),
"-fmodules-validate-system-headers",
"-Werror=non-modular-include-in-framework-module",
"-Xclang=-fincremental-extensions",
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index e8d8a76983f1a..573972a4473c6 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -35,8 +35,8 @@ bool CppModuleConfiguration::SetOncePath::TrySet(llvm::StringRef path) {
static llvm::SmallVector<std::string, 2>
getTargetIncludePaths(const llvm::Triple &triple) {
llvm::SmallVector<std::string, 2> paths;
- if (!triple.str(false).empty()) {
- paths.push_back("/usr/include/" + triple.str(false));
+ if (!triple.clone(true, false).str().empty()) {
+ paths.push_back("/usr/include/" + triple.clone(true, false).str());
if (!triple.getArchName().empty() ||
triple.getOSAndEnvironmentName().empty())
paths.push_back(("/usr/include/" + triple.getArchName() + "-" +
@@ -75,13 +75,13 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
parent_path(posix_dir, Style::posix).ends_with("c++")) {
if (!m_std_inc.TrySet(posix_dir))
return false;
- if (triple.str(false).empty())
+ if (triple.clone(true, false).str().empty())
return true;
posix_dir.consume_back("c++/v1");
// Check if this is a target-specific libc++ include directory.
return m_std_target_inc.TrySet(
- (posix_dir + triple.str(false) + "/c++/v1").str());
+ (posix_dir + triple.clone(true, false).str() + "/c++/v1").str());
}
std::optional<llvm::StringRef> inc_path;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index e2a96512b38b6..f88306aa7c30e 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6746,7 +6746,7 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
break;
default:
error = Status::FromErrorStringWithFormat(
- "unsupported core architecture: %s", target_triple.str(false).c_str());
+ "unsupported core architecture: %s", target_triple.clone(true, false).str().c_str());
break;
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 448db34637601..522a9cc80e25e 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -354,7 +354,7 @@ Status PlatformRemoteGDBServer::LaunchProcess(ProcessLaunchInfo &launch_info) {
m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
ArchSpec arch_spec = launch_info.GetArchitecture();
- const char *arch_triple = arch_spec.GetTriple().str(false).c_str();
+ const char *arch_triple = arch_spec.GetTriple().clone(true, false).str().c_str();
m_gdb_client_up->SendLaunchArchPacket(arch_triple);
LLDB_LOGF(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 6e90e23b72ba5..d16eaabb21e41 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -497,8 +497,8 @@ static void ParseLangArgs(LangOptions &Opts, ArchSpec arch) {
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
llvm::Triple target_triple) {
m_display_name = name.str();
- if (!target_triple.str(false).empty())
- SetTargetTriple(target_triple.str(false));
+ if (!target_triple.clone(true, false).str().empty())
+ SetTargetTriple(target_triple.clone(true, false).str());
// The caller didn't pass an ASTContext so create a new one for this
// TypeSystemClang.
CreateASTContext();
@@ -509,7 +509,7 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
ASTContext &existing_ctxt) {
m_display_name = name.str();
- SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str(false));
+ SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().clone(true, false).str());
m_ast_up.reset(&existing_ctxt);
GetASTMap().Insert(&existing_ctxt, this);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index c36e8a460e10c..e4a0d3937dc01 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -250,7 +250,7 @@ void Platform::GetStatus(Stream &strm) {
ArchSpec arch(GetSystemArchitecture());
if (arch.IsValid()) {
- if (!arch.GetTriple().str(false).empty()) {
+ if (!arch.GetTriple().clone(true, false).str().empty()) {
strm.Printf(" Triple: ");
arch.DumpTriple(strm.AsRawOstream());
strm.EOL();
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index 7c24f54963044..f63558be955c2 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -401,7 +401,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
module_stat.path.append(1, ')');
}
module_stat.uuid = module->GetUUID().GetAsString();
- module_stat.triple = module->GetArchitecture().GetTriple().str(false);
+ module_stat.triple = module->GetArchitecture().GetTriple().clone(true, false).str();
json_modules.emplace_back(module_stat.ToJSON());
}
}
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index 56dfae61c2423..e37a8cec61590 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -461,9 +461,7 @@ class Triple {
/// @name Direct Component Access
/// @{
- // const std::string &str() const { return Data; }
-
- const std::string &str(bool includeObjectFormat) const { return Data; }
+ const std::string &str() const { return Data; }
const std::string &getTriple() const { return Data; }
@@ -1228,6 +1226,23 @@ class Triple {
/// Merge target triples.
std::string merge(const Triple &Other) const;
+ /// Clone the triple. Optionally, only keep the first \p N components.
+ ///
+ /// The original triple string is either emmpty or in the following format:
+ /// > [arch]-[vendor]-[os][-[env][-[objfmt]]]
+ ///
+ /// The cloned triple string will preserve the first \p N components exactly
+ /// the same as the original (including the leading "-" and the value, empty
+ /// or not).
+ ///
+ /// E.g. Triple("arm64-apple-ios").clone(5) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").clone(3) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").clone(4) == "arm64-apple-ios-"
+ /// E.g. Triple("arm64-apple-ios--").clone(5) == "arm64-apple-ios--"
+ ///
+ /// \returns the cloned triple.
+ Triple clone(int N = 5) const;
+
/// Some platforms have different minimum supported OS versions that
/// varies by the architecture specified in the triple. This function
/// returns the minimum supported OS version for this triple if one an exists,
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 6a559ff023caa..46783ef81d031 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2107,6 +2107,45 @@ std::string Triple::merge(const Triple &Other) const {
return Other.str();
}
+Triple Triple::clone(bool IncludeEnvironment, bool IncludeObjectFormat) const {
+ if (str() == "")
+ return Triple();
+ if (IncludeEnvironment && IncludeObjectFormat)
+ return Triple(*this);
+
+ SmallString<64> triple;
+ llvm::StringRef tmp;
+ // arch
+ std::pair<llvm::StringRef, llvm::StringRef> pair = StringRef(Data).split('-'); // pair<arch, vendor/os/env/obj>
+ triple += pair.first;
+ // vendor
+ pair = pair.second.split('-'); // pair<vendor, os/env/obj>
+ triple += "-";
+ triple += pair.first;
+ // os
+ pair = (tmp = pair.second).split('-'); // pair<os, env/obj>
+ triple += "-";
+ triple += pair.first;
+ // environment
+ bool has_environment = tmp != pair.first;
+ pair = (tmp = pair.second).split('-'); // pair<env, obj>
+ bool added_environment = false;
+ if (has_environment && IncludeEnvironment) {
+ triple += "-";
+ triple += pair.first;
+ added_environment = true;
+ }
+ // object format
+ bool has_object_format = tmp != pair.first;
+ if (has_object_format && IncludeObjectFormat) {
+ if (!added_environment)
+ triple += "-";
+ triple += "-";
+ triple += pair.second;
+ }
+ return Triple(triple);
+}
+
bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
unsigned Micro) const {
assert(isMacOSX() && "Not an OS X triple!");
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index bbd12e6d0e412..8c4f3db927476 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2926,4 +2926,86 @@ TEST(TripleTest, isCompatibleWith) {
EXPECT_TRUE(DoTest(C.B, C.A, C.Result));
}
}
+
+TEST(TripleTest, Clone) {
+ // Empty triple
+ {
+ llvm::Triple triple;
+ ASSERT_EQ(triple.str(), "");
+ ASSERT_EQ(triple.clone(true, true).str(), "");
+ ASSERT_EQ(triple.clone(true, false).str(), "");
+ ASSERT_EQ(triple.clone(false, true).str(), "");
+ ASSERT_EQ(triple.clone(false, false).str(), "");
+ }
+
+ // Normal triple with 3 components
+ {
+ llvm::Triple triple("arm64-apple-ios");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ }
+
+ // Normal triple with 4 components
+ {
+ llvm::Triple triple("arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ }
+
+ // Normal triple with 5 components
+ {
+ llvm::Triple triple("arm64-apple-ios-simulator-macho");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator-macho");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator-macho");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios--macho");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ }
+
+ // Empty vendor and os
+ {
+ llvm::Triple triple("arm64---simulator-macho");
+ ASSERT_EQ(triple.str(), "arm64---simulator-macho");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64---simulator-macho");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64---simulator");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64----macho");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64--");
+ }
+
+ // Empty environment, no object format
+ {
+ llvm::Triple triple("arm64-apple-ios-");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios-");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ }
+
+ // Empty object format
+ {
+ llvm::Triple triple("arm64-apple-ios-simulator-");
+ ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator-");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator-");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios--");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ }
+
+ // Empty environment, has object format
+ {
+ llvm::Triple triple("arm64----macho");
+ ASSERT_EQ(triple.str(), "arm64----macho");
+ ASSERT_EQ(triple.clone(true, true).str(), "arm64----macho");
+ ASSERT_EQ(triple.clone(true, false).str(), "arm64---");
+ ASSERT_EQ(triple.clone(false, true).str(), "arm64----macho");
+ ASSERT_EQ(triple.clone(false, false).str(), "arm64--");
+ }
+}
} // end anonymous namespace
>From 2278c19725111792107f3b197eaa9dbef351678a Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Fri, 20 Jun 2025 20:52:31 -0700
Subject: [PATCH 5/6] Change API to str(N)
---
lldb/source/API/SBDebugger.cpp | 4 +-
lldb/source/API/SBModule.cpp | 2 +-
lldb/source/API/SBModuleSpec.cpp | 2 +-
lldb/source/API/SBTarget.cpp | 2 +-
lldb/source/Core/Module.cpp | 4 +-
.../DynamicLoaderDarwinKernel.cpp | 11 +--
.../DynamicLoaderFreeBSDKernel.cpp | 3 +-
.../Clang/ClangExpressionParser.cpp | 2 +-
.../Clang/ClangModulesDeclVendor.cpp | 2 +-
.../Clang/CppModuleConfiguration.cpp | 10 ++-
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 3 +-
.../gdb-server/PlatformRemoteGDBServer.cpp | 2 +-
.../TypeSystem/Clang/TypeSystemClang.cpp | 6 +-
lldb/source/Target/Platform.cpp | 2 +-
lldb/source/Target/Statistics.cpp | 2 +-
llvm/include/llvm/TargetParser/Triple.h | 38 +++++----
llvm/lib/TargetParser/Triple.cpp | 57 +++++--------
llvm/unittests/TargetParser/TripleTest.cpp | 81 +++++++++++--------
18 files changed, 119 insertions(+), 114 deletions(-)
diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp
index 282edcc7c694a..e5e324589ce81 100644
--- a/lldb/source/API/SBDebugger.cpp
+++ b/lldb/source/API/SBDebugger.cpp
@@ -642,9 +642,9 @@ bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) {
ArchSpec default_arch = Target::GetDefaultArchitecture();
if (default_arch.IsValid()) {
- const std::string &triple_str = default_arch.GetTriple().clone(true, false).str();
+ const llvm::StringRef triple_str = default_arch.GetTriple().str(4);
if (!triple_str.empty())
- ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str());
+ ::snprintf(arch_name, arch_name_len, "%s", triple_str.str().c_str());
else
::snprintf(arch_name, arch_name_len, "%s",
default_arch.GetArchitectureName());
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 8f93ba1eb0f7c..0ecc7a07b4337 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -576,7 +576,7 @@ const char *SBModule::GetTriple() {
if (!module_sp)
return nullptr;
- std::string triple(module_sp->GetArchitecture().GetTriple().clone(true, false).str());
+ std::string triple(module_sp->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBModuleSpec.cpp b/lldb/source/API/SBModuleSpec.cpp
index 1082fa32f438b..8db9e2acae894 100644
--- a/lldb/source/API/SBModuleSpec.cpp
+++ b/lldb/source/API/SBModuleSpec.cpp
@@ -112,7 +112,7 @@ void SBModuleSpec::SetObjectName(const char *name) {
const char *SBModuleSpec::GetTriple() {
LLDB_INSTRUMENT_VA(this);
- std::string triple(m_opaque_up->GetArchitecture().GetTriple().clone(true, false).str());
+ std::string triple(m_opaque_up->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 6f540a35707b6..98ea441c2a428 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -1576,7 +1576,7 @@ const char *SBTarget::GetTriple() {
LLDB_INSTRUMENT_VA(this);
if (TargetSP target_sp = GetSP()) {
- std::string triple(target_sp->GetArchitecture().GetTriple().clone(true, false).str());
+ std::string triple(target_sp->GetArchitecture().GetTriple().str(4));
// Unique the string so we don't run into ownership issues since the const
// strings put the string into the string pool once and the strings never
// comes out
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index 0ee9519450c32..b842531924e12 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1612,7 +1612,7 @@ bool Module::GetIsDynamicLinkEditor() {
uint32_t Module::Hash() {
std::string identifier;
llvm::raw_string_ostream id_strm(identifier);
- id_strm << m_arch.GetTriple().clone(true, false).str() << '-' << m_file.GetPath();
+ id_strm << m_arch.GetTriple().str(4) << '-' << m_file.GetPath();
if (m_object_name)
id_strm << '(' << m_object_name << ')';
if (m_object_offset > 0)
@@ -1626,7 +1626,7 @@ uint32_t Module::Hash() {
std::string Module::GetCacheKey() {
std::string key;
llvm::raw_string_ostream strm(key);
- strm << m_arch.GetTriple().clone(true, false).str() << '-' << m_file.GetFilename();
+ strm << m_arch.GetTriple().str(4) << '-' << m_file.GetFilename();
if (m_object_name)
strm << '(' << m_object_name << ')';
strm << '-' << llvm::format_hex(Hash(), 10);
diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
index 5b2d3dff9f9b8..0b0d0d3b57463 100644
--- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp
@@ -494,11 +494,12 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress(lldb::addr_t addr,
} else {
uuid_str = "and no LC_UUID found in load commands ";
}
- LLDB_LOGF(
- log,
- "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
- "kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().clone(true, false).str().c_str(), uuid_str.c_str());
+ LLDB_LOGF(log,
+ "DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress: "
+ "kernel binary image found at 0x%" PRIx64
+ " with arch '%s' %s",
+ addr, kernel_arch.GetTriple().str(4).str().c_str(),
+ uuid_str.c_str());
}
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index aee58d748146d..1504fe1756a46 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -236,7 +236,8 @@ lldb_private::UUID DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
LLDB_LOGF(log,
"DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().clone(true, false).str().c_str(), uuid_str.c_str());
+ addr, kernel_arch.GetTriple().str(4),
+ uuid_str.c_str());
return memory_module_sp->GetUUID();
}
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
index dc1f04434bba9..40780ccf0410b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -509,7 +509,7 @@ static void SetupTargetOpts(CompilerInstance &compiler,
const auto target_machine = target_arch.GetMachine();
if (target_arch.IsValid()) {
- std::string triple = target_arch.GetTriple().clone(true, false).str();
+ std::string triple(target_arch.GetTriple().str(4));
compiler.getTargetOpts().Triple = triple;
LLDB_LOGF(log, "Using %s as the target triple",
compiler.getTargetOpts().Triple.c_str());
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
index bfd42194c4e51..81269ac026f58 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp
@@ -659,7 +659,7 @@ ClangModulesDeclVendor::Create(Target &target) {
"-fsyntax-only",
"-femit-all-decls",
"-target",
- arch.GetTriple().clone(true, false).str(),
+ arch.GetTriple().str(4).str(),
"-fmodules-validate-system-headers",
"-Werror=non-modular-include-in-framework-module",
"-Xclang=-fincremental-extensions",
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
index 573972a4473c6..463374579aca9 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/CppModuleConfiguration.cpp
@@ -35,8 +35,9 @@ bool CppModuleConfiguration::SetOncePath::TrySet(llvm::StringRef path) {
static llvm::SmallVector<std::string, 2>
getTargetIncludePaths(const llvm::Triple &triple) {
llvm::SmallVector<std::string, 2> paths;
- if (!triple.clone(true, false).str().empty()) {
- paths.push_back("/usr/include/" + triple.clone(true, false).str());
+ llvm::StringRef triple_no_objfmt = triple.str(4);
+ if (!triple_no_objfmt.empty()) {
+ paths.push_back(("/usr/include/" + triple_no_objfmt).str());
if (!triple.getArchName().empty() ||
triple.getOSAndEnvironmentName().empty())
paths.push_back(("/usr/include/" + triple.getArchName() + "-" +
@@ -75,13 +76,14 @@ bool CppModuleConfiguration::analyzeFile(const FileSpec &f,
parent_path(posix_dir, Style::posix).ends_with("c++")) {
if (!m_std_inc.TrySet(posix_dir))
return false;
- if (triple.clone(true, false).str().empty())
+ llvm::StringRef triple_no_objfmt = triple.str(4);
+ if (triple_no_objfmt.empty())
return true;
posix_dir.consume_back("c++/v1");
// Check if this is a target-specific libc++ include directory.
return m_std_target_inc.TrySet(
- (posix_dir + triple.clone(true, false).str() + "/c++/v1").str());
+ (posix_dir + triple_no_objfmt + "/c++/v1").str());
}
std::optional<llvm::StringRef> inc_path;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index f88306aa7c30e..a3af44f7719f6 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -6746,7 +6746,8 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
break;
default:
error = Status::FromErrorStringWithFormat(
- "unsupported core architecture: %s", target_triple.clone(true, false).str().c_str());
+ "unsupported core architecture: %s",
+ target_triple.str(4).str().c_str());
break;
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 522a9cc80e25e..a8b9717bbf359 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -354,7 +354,7 @@ Status PlatformRemoteGDBServer::LaunchProcess(ProcessLaunchInfo &launch_info) {
m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
ArchSpec arch_spec = launch_info.GetArchitecture();
- const char *arch_triple = arch_spec.GetTriple().clone(true, false).str().c_str();
+ const char *arch_triple = arch_spec.GetTriple().str(4).str().c_str();
m_gdb_client_up->SendLaunchArchPacket(arch_triple);
LLDB_LOGF(
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index d16eaabb21e41..2faef32637164 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -497,8 +497,8 @@ static void ParseLangArgs(LangOptions &Opts, ArchSpec arch) {
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
llvm::Triple target_triple) {
m_display_name = name.str();
- if (!target_triple.clone(true, false).str().empty())
- SetTargetTriple(target_triple.clone(true, false).str());
+ if (!target_triple.str(4).empty())
+ SetTargetTriple(target_triple.str(4));
// The caller didn't pass an ASTContext so create a new one for this
// TypeSystemClang.
CreateASTContext();
@@ -509,7 +509,7 @@ TypeSystemClang::TypeSystemClang(llvm::StringRef name,
TypeSystemClang::TypeSystemClang(llvm::StringRef name,
ASTContext &existing_ctxt) {
m_display_name = name.str();
- SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().clone(true, false).str());
+ SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str(4));
m_ast_up.reset(&existing_ctxt);
GetASTMap().Insert(&existing_ctxt, this);
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index e4a0d3937dc01..bb1314c0520a8 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -250,7 +250,7 @@ void Platform::GetStatus(Stream &strm) {
ArchSpec arch(GetSystemArchitecture());
if (arch.IsValid()) {
- if (!arch.GetTriple().clone(true, false).str().empty()) {
+ if (!arch.GetTriple().str(4).empty()) {
strm.Printf(" Triple: ");
arch.DumpTriple(strm.AsRawOstream());
strm.EOL();
diff --git a/lldb/source/Target/Statistics.cpp b/lldb/source/Target/Statistics.cpp
index f63558be955c2..94af058d42641 100644
--- a/lldb/source/Target/Statistics.cpp
+++ b/lldb/source/Target/Statistics.cpp
@@ -401,7 +401,7 @@ llvm::json::Value DebuggerStats::ReportStatistics(
module_stat.path.append(1, ')');
}
module_stat.uuid = module->GetUUID().GetAsString();
- module_stat.triple = module->GetArchitecture().GetTriple().clone(true, false).str();
+ module_stat.triple = module->GetArchitecture().GetTriple().str(4);
json_modules.emplace_back(module_stat.ToJSON());
}
}
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index e37a8cec61590..6b9e80dc8743a 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -463,6 +463,27 @@ class Triple {
const std::string &str() const { return Data; }
+ /// Return the triple string but only keep the first \p N components.
+ ///
+ /// The returned string will preserve the first \p N components exactly the
+ /// same as the original (including the leading "-" and the value, empty or
+ /// not).
+ ///
+ /// E.g. Triple("arm64-apple-ios").str(5) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(5) == "arm64-apple-ios--"
+ /// E.g. Triple("arm64-apple-ios--").str(4) == "arm64-apple-ios-"
+ /// E.g. Triple("arm64-apple-ios--").str(3) == "arm64-apple-ios"
+ /// E.g. Triple("arm64-apple-ios--").str(2) == "arm64-apple"
+ /// E.g. Triple("arm64-apple-ios--").str(1) == "arm64"
+ /// E.g. Triple("arm64-apple-ios--").str(0) == ""
+ ///
+ /// This method does not normalize any triple strings. Clients that need to
+ /// handle the non-canonical triples that users often specify should use the
+ /// normalize method.
+ ///
+ /// \returns the (shorterned) triple string.
+ StringRef str(size_t N) const;
+
const std::string &getTriple() const { return Data; }
/// Whether the triple is empty / default constructed.
@@ -1226,23 +1247,6 @@ class Triple {
/// Merge target triples.
std::string merge(const Triple &Other) const;
- /// Clone the triple. Optionally, only keep the first \p N components.
- ///
- /// The original triple string is either emmpty or in the following format:
- /// > [arch]-[vendor]-[os][-[env][-[objfmt]]]
- ///
- /// The cloned triple string will preserve the first \p N components exactly
- /// the same as the original (including the leading "-" and the value, empty
- /// or not).
- ///
- /// E.g. Triple("arm64-apple-ios").clone(5) == "arm64-apple-ios"
- /// E.g. Triple("arm64-apple-ios--").clone(3) == "arm64-apple-ios"
- /// E.g. Triple("arm64-apple-ios--").clone(4) == "arm64-apple-ios-"
- /// E.g. Triple("arm64-apple-ios--").clone(5) == "arm64-apple-ios--"
- ///
- /// \returns the cloned triple.
- Triple clone(int N = 5) const;
-
/// Some platforms have different minimum supported OS versions that
/// varies by the architecture specified in the triple. This function
/// returns the minimum supported OS version for this triple if one an exists,
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 46783ef81d031..0fdb62c473e73 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -2107,43 +2107,28 @@ std::string Triple::merge(const Triple &Other) const {
return Other.str();
}
-Triple Triple::clone(bool IncludeEnvironment, bool IncludeObjectFormat) const {
- if (str() == "")
- return Triple();
- if (IncludeEnvironment && IncludeObjectFormat)
- return Triple(*this);
-
- SmallString<64> triple;
- llvm::StringRef tmp;
- // arch
- std::pair<llvm::StringRef, llvm::StringRef> pair = StringRef(Data).split('-'); // pair<arch, vendor/os/env/obj>
- triple += pair.first;
- // vendor
- pair = pair.second.split('-'); // pair<vendor, os/env/obj>
- triple += "-";
- triple += pair.first;
- // os
- pair = (tmp = pair.second).split('-'); // pair<os, env/obj>
- triple += "-";
- triple += pair.first;
- // environment
- bool has_environment = tmp != pair.first;
- pair = (tmp = pair.second).split('-'); // pair<env, obj>
- bool added_environment = false;
- if (has_environment && IncludeEnvironment) {
- triple += "-";
- triple += pair.first;
- added_environment = true;
- }
- // object format
- bool has_object_format = tmp != pair.first;
- if (has_object_format && IncludeObjectFormat) {
- if (!added_environment)
- triple += "-";
- triple += "-";
- triple += pair.second;
+StringRef Triple::str(size_t N) const {
+ // If empty, return empty
+ if (N == 0 || Data == "")
+ return "";
+
+ // If keeping all components, return a full clone
+ if (N >= 5)
+ return Data;
+
+ // Find the N-th separator (which is after the N'th component)
+ size_t p = StringRef::npos;
+ for (uint32_t i = 0; i < N; ++i) {
+ p = Data.find('-', p + 1);
+ if (p == StringRef::npos)
+ break;
}
- return Triple(triple);
+
+ // Create a triple
+ if (p == StringRef::npos)
+ return Data;
+ else
+ return StringRef(Data).substr(0, p);
}
bool Triple::isMacOSXVersionLT(unsigned Major, unsigned Minor,
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index 8c4f3db927476..ba91e91d08a21 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -2927,85 +2927,96 @@ TEST(TripleTest, isCompatibleWith) {
}
}
-TEST(TripleTest, Clone) {
+TEST(TripleTest, StrFirstN) {
// Empty triple
{
llvm::Triple triple;
ASSERT_EQ(triple.str(), "");
- ASSERT_EQ(triple.clone(true, true).str(), "");
- ASSERT_EQ(triple.clone(true, false).str(), "");
- ASSERT_EQ(triple.clone(false, true).str(), "");
- ASSERT_EQ(triple.clone(false, false).str(), "");
+ ASSERT_EQ(triple.str(5), "");
}
// Normal triple with 3 components
{
llvm::Triple triple("arm64-apple-ios");
ASSERT_EQ(triple.str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
// Normal triple with 4 components
{
llvm::Triple triple("arm64-apple-ios-simulator");
ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
// Normal triple with 5 components
{
llvm::Triple triple("arm64-apple-ios-simulator-macho");
ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator-macho");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator-macho");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios--macho");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios-simulator-macho");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
// Empty vendor and os
{
llvm::Triple triple("arm64---simulator-macho");
ASSERT_EQ(triple.str(), "arm64---simulator-macho");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64---simulator-macho");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64---simulator");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64----macho");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64--");
+ ASSERT_EQ(triple.str(5), "arm64---simulator-macho");
+ ASSERT_EQ(triple.str(4), "arm64---simulator");
+ ASSERT_EQ(triple.str(3), "arm64--");
+ ASSERT_EQ(triple.str(2), "arm64-");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
- // Empty environment, no object format
+ // Empty environment
{
llvm::Triple triple("arm64-apple-ios-");
ASSERT_EQ(triple.str(), "arm64-apple-ios-");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios-");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios-");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
// Empty object format
{
llvm::Triple triple("arm64-apple-ios-simulator-");
ASSERT_EQ(triple.str(), "arm64-apple-ios-simulator-");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64-apple-ios-simulator-");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64-apple-ios-simulator");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64-apple-ios--");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(5), "arm64-apple-ios-simulator-");
+ ASSERT_EQ(triple.str(4), "arm64-apple-ios-simulator");
+ ASSERT_EQ(triple.str(3), "arm64-apple-ios");
+ ASSERT_EQ(triple.str(2), "arm64-apple");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
- // Empty environment, has object format
+ // Empty environment, but has object format
{
llvm::Triple triple("arm64----macho");
ASSERT_EQ(triple.str(), "arm64----macho");
- ASSERT_EQ(triple.clone(true, true).str(), "arm64----macho");
- ASSERT_EQ(triple.clone(true, false).str(), "arm64---");
- ASSERT_EQ(triple.clone(false, true).str(), "arm64----macho");
- ASSERT_EQ(triple.clone(false, false).str(), "arm64--");
+ ASSERT_EQ(triple.str(5), "arm64----macho");
+ ASSERT_EQ(triple.str(4), "arm64---");
+ ASSERT_EQ(triple.str(3), "arm64--");
+ ASSERT_EQ(triple.str(2), "arm64-");
+ ASSERT_EQ(triple.str(1), "arm64");
+ ASSERT_EQ(triple.str(0), "");
}
}
} // end anonymous namespace
>From 3ea1296b3724ec5c05f616c98dd883b54b672ff9 Mon Sep 17 00:00:00 2001
From: Roy Shi <royshi at meta.com>
Date: Sat, 21 Jun 2025 00:50:58 -0700
Subject: [PATCH 6/6] Fix Mach-O object format
---
.../DynamicLoaderFreeBSDKernel.cpp | 2 +-
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 7 +-
.../gdb-server/PlatformRemoteGDBServer.cpp | 6 +-
.../ObjectFile/MachO/TestObjectFileMachO.cpp | 116 ++++++++++++++++++
4 files changed, 124 insertions(+), 7 deletions(-)
diff --git a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 1504fe1756a46..04b8114782d64 100644
--- a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -236,7 +236,7 @@ lldb_private::UUID DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
LLDB_LOGF(log,
"DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress: "
"kernel binary image found at 0x%" PRIx64 " with arch '%s' %s",
- addr, kernel_arch.GetTriple().str(4),
+ addr, kernel_arch.GetTriple().str(4).str().c_str(),
uuid_str.c_str());
return memory_module_sp->GetUUID();
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index a3af44f7719f6..672ca3f7e82a7 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5148,6 +5148,7 @@ void ObjectFileMachO::GetAllArchSpecs(const llvm::MachO::mach_header &header,
llvm::Triple base_triple = base_arch.GetTriple();
base_triple.setOS(llvm::Triple::UnknownOS);
base_triple.setOSName(llvm::StringRef());
+ base_triple.setObjectFormat(llvm::Triple::MachO);
if (header.filetype == MH_PRELOAD) {
if (header.cputype == CPU_TYPE_ARM) {
@@ -6745,9 +6746,9 @@ bool ObjectFileMachO::SaveCore(const lldb::ProcessSP &process_sp,
make_core = true;
break;
default:
- error = Status::FromErrorStringWithFormat(
- "unsupported core architecture: %s",
- target_triple.str(4).str().c_str());
+ error =
+ Status::FromErrorStringWithFormat("unsupported core architecture: %s",
+ target_triple.str(4).str().c_str());
break;
}
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index a8b9717bbf359..7c3b41e99d574 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -354,13 +354,13 @@ Status PlatformRemoteGDBServer::LaunchProcess(ProcessLaunchInfo &launch_info) {
m_gdb_client_up->SendEnvironment(launch_info.GetEnvironment());
ArchSpec arch_spec = launch_info.GetArchitecture();
- const char *arch_triple = arch_spec.GetTriple().str(4).str().c_str();
+ const std::string arch_triple = arch_spec.GetTriple().str(4).str();
- m_gdb_client_up->SendLaunchArchPacket(arch_triple);
+ m_gdb_client_up->SendLaunchArchPacket(arch_triple.c_str());
LLDB_LOGF(
log,
"PlatformRemoteGDBServer::%s() set launch architecture triple to '%s'",
- __FUNCTION__, arch_triple ? arch_triple : "<NULL>");
+ __FUNCTION__, !arch_triple.empty() ? arch_triple.c_str() : "<NULL>");
{
// Scope for the scoped timeout object
diff --git a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
index 0ef2d0b85fd36..e39a5398ab3e4 100644
--- a/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
+++ b/lldb/unittests/ObjectFile/MachO/TestObjectFileMachO.cpp
@@ -94,4 +94,120 @@ TEST_F(ObjectFileMachOTest, IndirectSymbolsInTheSharedCache) {
for (size_t i = 0; i < 10; i++)
OF->ParseSymtab(symtab);
}
+
+TEST_F(ObjectFileMachOTest, ObjectFormatWithVersionLoadCommand) {
+ // A Mach-O file of arm64 CPU type and macOS 10.14.0
+ const char *yamldata = R"(
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ filetype: 0x00000001
+ ncmds: 1
+ sizeofcmds: 176
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_BUILD_VERSION
+ cmdsize: 24
+ platform: 1
+ minos: 658944
+ sdk: 658944
+ ntools: 0
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __TEXT
+ vmaddr: 0
+ vmsize: 4
+ fileoff: 208
+ filesize: 4
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ content: 'AABBCCDD'
+ size: 4
+ offset: 208
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+...
+)";
+
+ // Perform setup.
+ llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata);
+ EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
+ auto module_sp = std::make_shared<Module>(file->moduleSpec());
+ ASSERT_NE(module_sp, nullptr);
+ auto object_file = module_sp->GetObjectFile();
+ ASSERT_NE(object_file, nullptr);
+
+ // Verify that the object file is recognized as Mach-O.
+ ASSERT_EQ(object_file->GetArchitecture().GetTriple().getObjectFormat(),
+ llvm::Triple::MachO);
+}
+
+TEST_F(ObjectFileMachOTest, ObjectFormatWithoutVersionLoadCommand) {
+ // A Mach-O file of arm64 CPU type, without load command LC_BUILD_VERSION.
+ const char *yamldata = R"(
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x0100000C
+ cpusubtype: 0x00000000
+ filetype: 0x00000001
+ ncmds: 1
+ sizeofcmds: 152
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __TEXT
+ vmaddr: 0
+ vmsize: 4
+ fileoff: 184
+ filesize: 4
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ content: 'AABBCCDD'
+ size: 4
+ offset: 184
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+...
+)";
+
+ // Perform setup.
+ llvm::Expected<TestFile> file = TestFile::fromYaml(yamldata);
+ EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
+ auto module_sp = std::make_shared<Module>(file->moduleSpec());
+ ASSERT_NE(module_sp, nullptr);
+ auto object_file = module_sp->GetObjectFile();
+ ASSERT_NE(object_file, nullptr);
+
+ // Verify that the object file is recognized as Mach-O.
+ ASSERT_EQ(object_file->GetArchitecture().GetTriple().getObjectFormat(),
+ llvm::Triple::MachO);
+}
#endif
More information about the llvm-commits
mailing list