[Mlir-commits] [llvm] [mlir] [Support][FileCheck] C++26 fixes for P2591 (PR #223284)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Sep 19 20:25:55 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/4] [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/4] [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/4] [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/4] [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(
More information about the Mlir-commits
mailing list