[Mlir-commits] [llvm] [mlir] [LLVM][MLIR] Treewide C++26/2d fixes (PR #223284)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Sep 20 11:18:51 PDT 2026
https://github.com/rdong8 updated https://github.com/llvm/llvm-project/pull/223284
>From 1fd8f3fbd7d4f0934d3861a2a4ecef3ef8410844 Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 13 Sep 2026 23:18:41 +0000
Subject: [PATCH 1/6] [Support] C++26 fixes for P2591
---
llvm/lib/Support/CodeGenCoverage.cpp | 6 +++---
llvm/lib/Support/VirtualFileSystem.cpp | 15 ++++++++++-----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Support/CodeGenCoverage.cpp b/llvm/lib/Support/CodeGenCoverage.cpp
index 2e35019e12c16..4f665ec9889ff 100644
--- a/llvm/lib/Support/CodeGenCoverage.cpp
+++ b/llvm/lib/Support/CodeGenCoverage.cpp
@@ -13,6 +13,7 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Process.h"
@@ -83,9 +84,8 @@ bool CodeGenCoverage::emit(StringRef CoveragePrefix,
// We can handle locking within a process easily enough but we don't want to
// manage it between multiple processes. Use the process ID to ensure no
// more than one process is ever writing to the same file at the same time.
- std::string Pid = llvm::to_string(sys::Process::getProcessId());
-
- std::string CoverageFilename = (CoveragePrefix + Pid).str();
+ std::string CoverageFilename =
+ formatv("{0}{1}", CoveragePrefix, sys::Process::getProcessId()).str();
std::error_code EC;
sys::fs::OpenFlags OpenFlags = sys::fs::OF_Append;
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 04e2c3cdbcae7..4cf8c0cd9c6ea 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -31,6 +31,8 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/FormatAdapters.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -708,7 +710,7 @@ class InMemoryFile : public InMemoryNode {
llvm::MemoryBuffer *getBuffer() const { return Buffer.get(); }
std::string toString(unsigned Indent) const override {
- return (std::string(Indent, ' ') + Stat.getName() + "\n").str();
+ return formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
}
static bool classof(const InMemoryNode *N) {
@@ -731,8 +733,9 @@ class InMemoryHardLink : public InMemoryNode {
}
std::string toString(unsigned Indent) const override {
- return std::string(Indent, ' ') + "HardLink to -> " +
- ResolvedFile.toString(0);
+ return formatv("{0}HardLink to -> {1}", fmt_repeat(' ', Indent),
+ ResolvedFile.toString(0))
+ .str();
}
static bool classof(const InMemoryNode *N) {
@@ -750,7 +753,9 @@ class InMemorySymbolicLink : public InMemoryNode {
Stat(Stat) {}
std::string toString(unsigned Indent) const override {
- return std::string(Indent, ' ') + "SymbolicLink to -> " + TargetPath;
+ return formatv("{0}SymbolicLink to -> {1}", fmt_repeat(' ', Indent),
+ TargetPath)
+ .str();
}
Status getStatus(const Twine &RequestedName) const override {
@@ -830,7 +835,7 @@ class InMemoryDirectory : public InMemoryNode {
std::string toString(unsigned Indent) const override {
std::string Result =
- (std::string(Indent, ' ') + Stat.getName() + "\n").str();
+ formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
for (const auto &Entry : Entries)
Result += Entry.second->toString(Indent + 2);
return Result;
>From ad79019bd42b2a0cc6eb91c3165997621ce2feee Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Mon, 14 Sep 2026 06:28:46 +0000
Subject: [PATCH 2/6] [FileCheck] C++26 fixes for P2591
---
llvm/lib/FileCheck/FileCheck.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 9889f5d68a52f..68377b631380e 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1850,7 +1850,8 @@ bool FileCheck::readCheckFile(
std::string Prefix = "-implicit-check-not='";
std::string Suffix = "'";
std::unique_ptr<MemoryBuffer> CmdLine = MemoryBuffer::getMemBufferCopy(
- (Prefix + PatternString + Suffix).str(), "command line");
+ formatv("{0}{1}{2}", Prefix, PatternString, Suffix).str(),
+ "command line");
StringRef PatternInBuffer =
CmdLine->getBuffer().substr(Prefix.size(), PatternString.size());
@@ -2596,7 +2597,8 @@ Error FileCheckPatternContext::defineCmdlineVariables(
// Append a copy of the command-line definition adapted to use the same
// format as in the input file to be able to reuse
// parseNumericSubstitutionBlock.
- CmdlineDefsDiag += (DefPrefix + CmdlineDef + " (parsed as: [[").str();
+ CmdlineDefsDiag +=
+ formatv("{0}{1} (parsed as: [[", DefPrefix, CmdlineDef).str();
std::string SubstitutionStr = std::string(CmdlineDef);
SubstitutionStr[EqIdx] = ':';
CmdlineDefsIndices.push_back(
>From 5a08a9564de7c20bfbb9be96789cae7b1e20d709 Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 20 Sep 2026 02:02:35 +0000
Subject: [PATCH 3/6] [Support][FileCheck][IR] cast concat operands to Twine
---
llvm/lib/FileCheck/FileCheck.cpp | 9 ++++-----
llvm/lib/IR/AutoUpgrade.cpp | 2 +-
llvm/lib/Support/CodeGenCoverage.cpp | 3 +--
llvm/lib/Support/VirtualFileSystem.cpp | 15 +++++----------
4 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 68377b631380e..677331bda2f61 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1847,11 +1847,10 @@ bool FileCheck::readCheckFile(
for (StringRef PatternString : Req.ImplicitCheckNot) {
// Create a buffer with fake command line content in order to display the
// command line option responsible for the specific implicit CHECK-NOT.
- std::string Prefix = "-implicit-check-not='";
- std::string Suffix = "'";
+ StringRef Prefix = "-implicit-check-not='";
+ StringRef Suffix = "'";
std::unique_ptr<MemoryBuffer> CmdLine = MemoryBuffer::getMemBufferCopy(
- formatv("{0}{1}{2}", Prefix, PatternString, Suffix).str(),
- "command line");
+ (Prefix + PatternString + Suffix).str(), "command line");
StringRef PatternInBuffer =
CmdLine->getBuffer().substr(Prefix.size(), PatternString.size());
@@ -2598,7 +2597,7 @@ Error FileCheckPatternContext::defineCmdlineVariables(
// format as in the input file to be able to reuse
// parseNumericSubstitutionBlock.
CmdlineDefsDiag +=
- formatv("{0}{1} (parsed as: [[", DefPrefix, CmdlineDef).str();
+ (Twine(DefPrefix) + CmdlineDef + " (parsed as: [[").str();
std::string SubstitutionStr = std::string(CmdlineDef);
SubstitutionStr[EqIdx] = ':';
CmdlineDefsIndices.push_back(
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 75fc03c22222b..a91fbef8b0f8a 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -7873,7 +7873,7 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) {
// to fix more IR than it breaks.
// Intel MCU is an exception and uses 4-byte-alignment.
if (!T.isOSIAMCU()) {
- std::string I128 = "-i128:128";
+ StringRef I128 = "-i128:128";
if (StringRef Ref = Res; !Ref.contains(I128)) {
SmallVector<StringRef, 4> Groups;
Regex R("^(e(-[mpi][^-]*)*)((-[^mpi][^-]*)*)$");
diff --git a/llvm/lib/Support/CodeGenCoverage.cpp b/llvm/lib/Support/CodeGenCoverage.cpp
index 4f665ec9889ff..e1b04bbc64e16 100644
--- a/llvm/lib/Support/CodeGenCoverage.cpp
+++ b/llvm/lib/Support/CodeGenCoverage.cpp
@@ -13,7 +13,6 @@
#include "llvm/Support/Endian.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Process.h"
@@ -85,7 +84,7 @@ bool CodeGenCoverage::emit(StringRef CoveragePrefix,
// manage it between multiple processes. Use the process ID to ensure no
// more than one process is ever writing to the same file at the same time.
std::string CoverageFilename =
- formatv("{0}{1}", CoveragePrefix, sys::Process::getProcessId()).str();
+ (CoveragePrefix + Twine(sys::Process::getProcessId())).str();
std::error_code EC;
sys::fs::OpenFlags OpenFlags = sys::fs::OF_Append;
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 4e4592310b553..38c77ab8fd817 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -31,8 +31,6 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileSystem/UniqueID.h"
-#include "llvm/Support/FormatAdapters.h"
-#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
@@ -710,7 +708,7 @@ class InMemoryFile : public InMemoryNode {
llvm::MemoryBuffer *getBuffer() const { return Buffer.get(); }
std::string toString(unsigned Indent) const override {
- return formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
+ return (Twine(std::string(Indent, ' ')) + Stat.getName() + "\n").str();
}
static bool classof(const InMemoryNode *N) {
@@ -733,9 +731,8 @@ class InMemoryHardLink : public InMemoryNode {
}
std::string toString(unsigned Indent) const override {
- return formatv("{0}HardLink to -> {1}", fmt_repeat(' ', Indent),
- ResolvedFile.toString(0))
- .str();
+ return std::string(Indent, ' ') + "HardLink to -> " +
+ ResolvedFile.toString(0);
}
static bool classof(const InMemoryNode *N) {
@@ -753,9 +750,7 @@ class InMemorySymbolicLink : public InMemoryNode {
Stat(Stat) {}
std::string toString(unsigned Indent) const override {
- return formatv("{0}SymbolicLink to -> {1}", fmt_repeat(' ', Indent),
- TargetPath)
- .str();
+ return std::string(Indent, ' ') + "SymbolicLink to -> " + TargetPath;
}
Status getStatus(const Twine &RequestedName) const override {
@@ -835,7 +830,7 @@ class InMemoryDirectory : public InMemoryNode {
std::string toString(unsigned Indent) const override {
std::string Result =
- formatv("{0}{1}\n", fmt_repeat(' ', Indent), Stat.getName()).str();
+ (Twine(std::string(Indent, ' ')) + Stat.getName() + "\n").str();
for (const auto &Entry : Entries)
Result += Entry.second->toString(Indent + 2);
return Result;
>From adcc1377b0c58e36e58b6636dcc9015e1410edf3 Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 20 Sep 2026 03:24:55 +0000
Subject: [PATCH 4/6] [MLIR] C++26 fixes for P2591
---
.../Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 2 +-
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index e5e3e0cc6d944..5a0411b68d20d 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -7056,7 +7056,7 @@ getRefPtrIfDeclareTarget(Value value,
gOp.getSymName());
return moduleTranslation.getLLVMModule()->getNamedValue(
- (gOp.getSymName().str() + suffix.str()).str());
+ (gOp.getSymName() + suffix).str());
}
}
return nullptr;
diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
index 81c598ebbef0a..6f771130b23be 100644
--- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
@@ -1162,7 +1162,8 @@ static void populateBuilderRegions(const Operator &op,
const NamedRegion ®ion = op.getRegion(op.getNumRegions() - 1);
std::string name =
- ("num_" + region.name.take_front().lower() + region.name.drop_front())
+ (Twine("num_") + region.name.take_front().lower() +
+ region.name.drop_front())
.str();
builderArgs.push_back(name);
builderLines.push_back(
>From 447d82459d4544a1b9af48f0d3c01169f3292f47 Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 20 Sep 2026 04:40:21 +0000
Subject: [PATCH 5/6] [llvm] C++26 fixes
---
llvm/include/llvm/Analysis/ReleaseModeModelRunner.h | 3 ++-
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h | 4 +---
llvm/lib/Analysis/CFGPrinter.cpp | 2 +-
llvm/lib/Analysis/ReplayInlineAdvisor.cpp | 3 ++-
llvm/lib/CodeGen/MachineCFGPrinter.cpp | 3 ++-
llvm/lib/Frontend/OpenMP/OMP.cpp | 3 ++-
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 8 ++++++--
llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp | 4 +++-
.../LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp | 6 ++++++
.../Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.h | 3 +--
llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp | 3 ++-
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 5 +++--
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 3 ++-
.../Instrumentation/SanitizerBinaryMetadata.cpp | 3 ++-
14 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h b/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
index ff423a9155b14..3ca3205406946 100644
--- a/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
+++ b/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
@@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_RELEASEMODEMODELRUNNER_H
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/MLModelRunner.h"
#include "llvm/Analysis/TensorSpec.h"
#include "llvm/Support/ErrorHandling.h"
@@ -119,7 +120,7 @@ class ReleaseModeModelRunner final : public MLModelRunner {
void populateTensor(size_t Pos, const TensorSpec &Spec, StringRef Prefix,
bool &InputIsPresent) {
const int Index =
- CompiledModel->LookupArgIndex((Prefix + Spec.name()).str());
+ CompiledModel->LookupArgIndex((Twine(Prefix) + Spec.name()).str());
void *Buffer = nullptr;
InputIsPresent = Index >= 0;
if (InputIsPresent)
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 30eb42a2f5c38..391740de4861b 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -512,9 +512,7 @@ class OpenMPIRBuilder {
public:
/// Create a new OpenMPIRBuilder operating on the given module \p M. This will
/// not have an effect on \p M (see initialize)
- OpenMPIRBuilder(Module &M)
- : M(M), Builder(M.getContext()), OffloadInfoManager(this),
- T(M.getTargetTriple()), IsFinalized(false) {}
+ LLVM_ABI OpenMPIRBuilder(Module &M);
LLVM_ABI ~OpenMPIRBuilder();
class AtomicInfo : public llvm::AtomicInfo {
diff --git a/llvm/lib/Analysis/CFGPrinter.cpp b/llvm/lib/Analysis/CFGPrinter.cpp
index 39108a906f081..25f3f95e47485 100644
--- a/llvm/lib/Analysis/CFGPrinter.cpp
+++ b/llvm/lib/Analysis/CFGPrinter.cpp
@@ -62,7 +62,7 @@ static void writeCFGToDotFile(Function &F, BlockFrequencyInfo *BFI,
BranchProbabilityInfo *BPI, uint64_t MaxFreq,
bool CFGOnly = false) {
std::string Filename =
- (CFGDotFilenamePrefix + "." + F.getName() + ".dot").str();
+ (Twine(CFGDotFilenamePrefix) + "." + F.getName() + ".dot").str();
errs() << "Writing '" << Filename << "'...";
std::error_code EC;
diff --git a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
index 7253478a0eedf..1b4f159105342 100644
--- a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/ReplayInlineAdvisor.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/LineIterator.h"
@@ -107,7 +108,7 @@ std::unique_ptr<InlineAdvice> ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) {
std::string CallSiteLoc =
formatCallSiteLocation(CB.getDebugLoc(), ReplaySettings.ReplayFormat);
StringRef Callee = CB.getCalledFunction()->getName();
- std::string Combined = (Callee + CallSiteLoc).str();
+ std::string Combined = (Twine(Callee) + CallSiteLoc).str();
// Replay decision, if it has one
auto Iter = InlineSitesFromRemarks.find(Combined);
diff --git a/llvm/lib/CodeGen/MachineCFGPrinter.cpp b/llvm/lib/CodeGen/MachineCFGPrinter.cpp
index c604d4fd6e1e6..dec83d49b99cb 100644
--- a/llvm/lib/CodeGen/MachineCFGPrinter.cpp
+++ b/llvm/lib/CodeGen/MachineCFGPrinter.cpp
@@ -17,6 +17,7 @@
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/GraphWriter.h"
using namespace llvm;
@@ -38,7 +39,7 @@ static cl::opt<bool>
static void writeMCFGToDotFile(MachineFunction &MF) {
std::string Filename =
- (MCFGDotFilenamePrefix + "." + MF.getName() + ".dot").str();
+ (Twine(MCFGDotFilenamePrefix) + "." + MF.getName() + ".dot").str();
errs() << "Writing '" << Filename << "'...";
std::error_code EC;
diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp
index 8bfe3a6a7cc4a..ff584568d3cd9 100644
--- a/llvm/lib/Frontend/OpenMP/OMP.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMP.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/Support/ErrorHandling.h"
@@ -241,7 +242,7 @@ std::string prettifyFunctionName(StringRef FunctionName) {
auto ParentName = deconstructOpenMPKernelName(FunctionName, LineNo);
if (LineNo == 0)
return FunctionName.str();
- return ("omp target in " + ParentName + " @ " + std::to_string(LineNo) +
+ return (Twine("omp target in ") + ParentName + " @ " + Twine(LineNo) +
" (" + FunctionName + ")")
.str();
}
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 8b196c461f195..57d313f7b0abf 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -1180,6 +1180,10 @@ void OpenMPIRBuilder::applyDeclareTargetGlobalReplacements() {
DeclareTargetGlobalReplacements.clear();
}
+OpenMPIRBuilder::OpenMPIRBuilder(Module &M)
+ : M(M), Builder(M.getContext()), OffloadInfoManager(this),
+ T(M.getTargetTriple()), IsFinalized(false) {}
+
OpenMPIRBuilder::~OpenMPIRBuilder() {
assert(OutlineInfos.empty() && "There must be no outstanding outlinings");
}
@@ -4655,7 +4659,7 @@ Expected<Function *> OpenMPIRBuilder::emitGlobalToListReduceFunction(
std::string OpenMPIRBuilder::getReductionFuncName(StringRef Name) const {
std::string Suffix =
createPlatformSpecificName({"omp", "reduction", "reduction_func"});
- return (Name + Suffix).str();
+ return (Twine(Name) + Suffix).str();
}
Expected<Function *> OpenMPIRBuilder::createReductionFunction(
@@ -13420,4 +13424,4 @@ void CanonicalLoopInfo::invalidate() {
Cond = nullptr;
Latch = nullptr;
Exit = nullptr;
-}
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
index 467fdbfd0e05b..e30c2a262eede 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
@@ -16,6 +16,7 @@
#include "ARMInstPrinter.h"
#include "ARMMCAsmInfo.h"
#include "TargetInfo/ARMTargetInfo.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCCodeEmitter.h"
@@ -144,7 +145,8 @@ std::string ARM_MC::ParseARMTriple(const Triple &TT, StringRef CPU) {
ARM::ArchKind ArchID = ARM::parseArch(TT.getArchName());
if (ArchID != ARM::ArchKind::INVALID && (CPU.empty() || CPU == "generic"))
- ARMArchFeature = (ARMArchFeature + "+" + ARM::getArchName(ArchID)).str();
+ ARMArchFeature =
+ (Twine(ARMArchFeature) + "+" + ARM::getArchName(ArchID)).str();
if (TT.isThumb()) {
if (!ARMArchFeature.empty())
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
index 91433d8eaddc5..7dc31e4b8cc17 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp
@@ -89,6 +89,12 @@ void LoongArchTargetELFStreamer::finish() {
W.setELFHeaderEFlags(EFlags);
}
+LoongArchELFStreamer::LoongArchELFStreamer(MCContext &C,
+ std::unique_ptr<MCAsmBackend> MAB,
+ std::unique_ptr<MCObjectWriter> MOW,
+ std::unique_ptr<MCCodeEmitter> MCE)
+ : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
+
void LoongArchELFStreamer::emitCodeAlignment(Align Alignment,
const MCSubtargetInfo &STI,
unsigned MaxBytesToEmit) {
diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.h
index a9e5ec2bb527c..46c359000134d 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.h
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.h
@@ -33,8 +33,7 @@ class LoongArchELFStreamer : public MCELFStreamer {
public:
LoongArchELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
std::unique_ptr<MCObjectWriter> MOW,
- std::unique_ptr<MCCodeEmitter> MCE)
- : MCELFStreamer(C, std::move(MAB), std::move(MOW), std::move(MCE)) {}
+ std::unique_ptr<MCCodeEmitter> MCE);
void emitCodeAlignment(Align Alignment, const MCSubtargetInfo &STI,
unsigned MaxBytesToEmit) override;
diff --git a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp
index 9d2904dec0ad0..0599796dc79dc 100644
--- a/llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp
+++ b/llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp
@@ -16,6 +16,7 @@
#include "M68kMCAsmInfo.h"
#include "TargetInfo/M68kTargetInfo.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCELFStreamer.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCInstrInfo.h"
@@ -62,7 +63,7 @@ static MCSubtargetInfo *createM68kMCSubtargetInfo(const Triple &TT,
std::string ArchFS = ParseM68kTriple(TT, CPU);
if (!FS.empty()) {
if (!ArchFS.empty()) {
- ArchFS = (ArchFS + "," + FS).str();
+ ArchFS = (Twine(ArchFS) + "," + FS).str();
} else {
ArchFS = FS.str();
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 20cf9275af8df..4c8bb7feb408b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -17,6 +17,7 @@
#include "SPIRVUtils.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringTable.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/IntrinsicsSPIRV.h"
#include <regex>
@@ -339,12 +340,12 @@ lookupBuiltin(StringRef DemangledCall,
// If argument-type name prefix was added, look up the builtin again.
if (!Prefix.empty() &&
- (Builtin = SPIRV::lookupBuiltin((Prefix + BuiltinName).str(), Set)))
+ (Builtin = SPIRV::lookupBuiltin((Twine(Prefix) + BuiltinName).str(), Set)))
return std::make_unique<SPIRV::IncomingCall>(
BuiltinName, Builtin, ReturnRegister, ReturnType, Arguments);
if (!Suffix.empty() &&
- (Builtin = SPIRV::lookupBuiltin((BuiltinName + Suffix).str(), Set)))
+ (Builtin = SPIRV::lookupBuiltin((Twine(BuiltinName) + Suffix).str(), Set)))
return std::make_unique<SPIRV::IncomingCall>(
BuiltinName, Builtin, ReturnRegister, ReturnType, Arguments);
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 6bb03c614af19..35d4e8dc4e177 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -29,6 +29,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/CodeGen/Analysis.h"
@@ -588,7 +589,7 @@ void WebAssemblyAsmPrinter::EmitTargetFeatures(Module &M) {
// Read target features and linkage policies from module metadata
SmallVector<FeatureEntry, 4> EmittedFeatures;
auto EmitFeature = [&](std::string Feature) {
- std::string MDKey = (StringRef("wasm-feature-") + Feature).str();
+ std::string MDKey = (Twine("wasm-feature-") + Feature).str();
Metadata *Policy = M.getModuleFlag(MDKey);
if (Policy == nullptr)
return;
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
index 210b1266de23c..c45c804ad6cca 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -213,7 +213,8 @@ bool SanitizerBinaryMetadata::run() {
// Calls to the initialization functions with different versions cannot be
// merged. Give the structors unique names based on the version, which will
// also be used as the COMDAT key.
- const std::string StructorPrefix = (MI->FunctionPrefix + VersionStr).str();
+ const std::string StructorPrefix =
+ (Twine(MI->FunctionPrefix) + VersionStr).str();
// We declare the _add and _del functions as weak, and only call them if
// there is a valid symbol linked. This allows building binaries with
>From 12379fdbc351ec8cad5126e95c2e88da740e5ebd Mon Sep 17 00:00:00 2001
From: Richard Dong <66289396+rdong8 at users.noreply.github.com>
Date: Sun, 20 Sep 2026 18:18:32 +0000
Subject: [PATCH 6/6] [MC] Fix ELF symbol info computation
---
llvm/lib/MC/ELFObjectWriter.cpp | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 3af4851d39d94..d57b1abf6f5c1 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -406,6 +406,10 @@ static bool isIFunc(const MCSymbolELF *Symbol) {
return true;
}
+static uint8_t getSymbolInfo(uint8_t Binding, uint8_t Type) {
+ return (Binding << 4) | (Type & 0x0f);
+}
+
void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
ELFSymbolData &MSD) {
auto &Symbol = static_cast<const MCSymbolELF &>(*MSD.Symbol);
@@ -423,7 +427,7 @@ void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
if (Base) {
Type = mergeTypeForSet(Type, Base->getType());
}
- uint8_t Info = (Binding << 4) | Type;
+ uint8_t Info = getSymbolInfo(Binding, Type);
// Other and Visibility share the same byte with Visibility using the lower
// 2 bits
@@ -610,8 +614,8 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
for (; FileNameIt != FileNames.end() && FileNameIt->second <= MSD.Order;
++FileNameIt) {
Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
- ELF::STT_FILE | ELF::STB_LOCAL, 0, 0, ELF::STV_DEFAULT,
- ELF::SHN_ABS, true);
+ getSymbolInfo(ELF::STB_LOCAL, ELF::STT_FILE), 0, 0,
+ ELF::STV_DEFAULT, ELF::SHN_ABS, true);
++Index;
}
@@ -623,8 +627,8 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
}
for (; FileNameIt != FileNames.end(); ++FileNameIt) {
Writer.writeSymbol(StrTabBuilder.getOffset(FileNameIt->first),
- ELF::STT_FILE | ELF::STB_LOCAL, 0, 0, ELF::STV_DEFAULT,
- ELF::SHN_ABS, true);
+ getSymbolInfo(ELF::STB_LOCAL, ELF::STT_FILE), 0, 0,
+ ELF::STV_DEFAULT, ELF::SHN_ABS, true);
++Index;
}
More information about the Mlir-commits
mailing list