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 <[email protected]> Date: Sun, 13 Sep 2026 23:18:41 +0000 Subject: [PATCH 1/8] [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 <[email protected]> Date: Mon, 14 Sep 2026 06:28:46 +0000 Subject: [PATCH 2/8] [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 <[email protected]> Date: Sun, 20 Sep 2026 02:02:35 +0000 Subject: [PATCH 3/8] [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 <[email protected]> Date: Sun, 20 Sep 2026 03:24:55 +0000 Subject: [PATCH 4/8] [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 <[email protected]> Date: Sun, 20 Sep 2026 04:40:21 +0000 Subject: [PATCH 5/8] [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 <[email protected]> Date: Sun, 20 Sep 2026 18:18:32 +0000 Subject: [PATCH 6/8] [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; } >From 54e424f6259b592bd281dc9e802418e02b6c41a0 Mon Sep 17 00:00:00 2001 From: Richard Dong <[email protected]> Date: Mon, 21 Sep 2026 07:21:26 +0000 Subject: [PATCH 7/8] [Clang] C++26 fixes --- clang/include/clang/Frontend/FrontendAction.h | 3 ++- clang/include/clang/Sema/CodeCompleteConsumer.h | 13 +++++++++++-- clang/lib/Basic/DiagnosticIDs.cpp | 4 ++-- clang/lib/Basic/Targets/AArch64.cpp | 15 ++++++++------- clang/lib/Basic/Targets/AMDGPU.cpp | 2 +- clang/lib/Basic/Targets/ARM.cpp | 12 ++++++------ clang/lib/Basic/Targets/AVR.cpp | 3 ++- clang/lib/Basic/Targets/BPF.cpp | 2 +- clang/lib/Basic/Targets/DirectX.cpp | 2 +- clang/lib/Basic/Targets/Hexagon.cpp | 2 +- clang/lib/Basic/Targets/LoongArch.cpp | 8 ++++---- clang/lib/Basic/Targets/Mips.cpp | 2 +- clang/lib/Basic/Targets/NVPTX.cpp | 2 +- clang/lib/Basic/Targets/PPC.cpp | 2 +- clang/lib/Basic/Targets/RISCV.cpp | 10 +++++----- clang/lib/Basic/Targets/SPIR.cpp | 2 +- clang/lib/Basic/Targets/SystemZ.cpp | 4 ++-- clang/lib/Basic/Targets/VE.cpp | 2 +- clang/lib/Basic/Targets/WebAssembly.cpp | 2 +- clang/lib/Basic/Targets/X86.cpp | 6 +++--- clang/lib/Basic/Targets/XCore.cpp | 2 +- clang/lib/CodeGen/CGDecl.cpp | 2 +- clang/lib/CodeGen/CGExpr.cpp | 2 +- clang/lib/CodeGen/CGExprAgg.cpp | 2 +- clang/lib/CodeGen/CGObjCGNU.cpp | 12 ++++++------ clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++-- clang/lib/Driver/Driver.cpp | 4 ++-- clang/lib/Driver/ToolChains/Gnu.cpp | 9 +++++---- clang/lib/Driver/ToolChains/MinGW.cpp | 11 +++++++---- clang/lib/Frontend/FrontendAction.cpp | 4 ++++ .../Checkers/ExprInspectionChecker.cpp | 10 +++++----- clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp | 2 +- clang/lib/Tooling/Core/Replacement.cpp | 2 +- clang/lib/Tooling/Tooling.cpp | 2 +- clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 3 ++- 35 files changed, 95 insertions(+), 74 deletions(-) diff --git a/clang/include/clang/Frontend/FrontendAction.h b/clang/include/clang/Frontend/FrontendAction.h index 8be732ceb40a0..19718f5a2582d 100644 --- a/clang/include/clang/Frontend/FrontendAction.h +++ b/clang/include/clang/Frontend/FrontendAction.h @@ -161,8 +161,9 @@ class FrontendAction { std::unique_ptr<ASTUnit> takeCurrentASTUnit(); + void setCurrentInput(const FrontendInputFile &CurrentInput); void setCurrentInput(const FrontendInputFile &CurrentInput, - std::unique_ptr<ASTUnit> AST = nullptr); + std::unique_ptr<ASTUnit> AST); /// @} /// @name Supported Modes diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h b/clang/include/clang/Sema/CodeCompleteConsumer.h index c26f4e33d289c..e5772f80d5f40 100644 --- a/clang/include/clang/Sema/CodeCompleteConsumer.h +++ b/clang/include/clang/Sema/CodeCompleteConsumer.h @@ -50,7 +50,7 @@ class UsingShadowDecl; /// Default priority values for code-completion results based /// on their kind. -enum { +enum CodeCompletionPriority { /// Priority for the next initialization in a constructor initializer /// list. CCP_NextInitializer = 7, @@ -101,7 +101,7 @@ enum { /// Priority value deltas that are added to code-completion results /// based on the context of the result. -enum { +enum CodeCompletionDelta { /// The result is in a base class. CCD_InBaseClass = 2, @@ -130,6 +130,15 @@ enum { CCD_BlockPropertySetter = 3 }; +constexpr unsigned operator+(CodeCompletionPriority P, CodeCompletionDelta D) { + return static_cast<unsigned>(llvm::to_underlying(P) + + llvm::to_underlying(D)); +} + +constexpr unsigned operator+(CodeCompletionDelta D, CodeCompletionPriority P) { + return P + D; +} + /// Priority value factors by which we will divide or multiply the /// priority of a code-completion result. enum { diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index 3709528e497d2..b7c6b722494ec 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -248,8 +248,8 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { unsigned ID = DiagID - DIAG_START_COMMON - 1; #define CATEGORY(NAME, PREV) \ if (DiagID > DIAG_START_##NAME) { \ - Offset += NUM_BUILTIN_##PREV##_DIAGNOSTICS - DIAG_START_##PREV - 1; \ - ID -= DIAG_START_##NAME - DIAG_START_##PREV; \ + Offset += llvm::to_underlying(NUM_BUILTIN_##PREV##_DIAGNOSTICS) - DIAG_START_##PREV - 1; \ + ID -= llvm::to_underlying(DIAG_START_##NAME) - DIAG_START_##PREV; \ } CATEGORY(DRIVER, COMMON) CATEGORY(FRONTEND, DRIVER) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index a4841514be35e..a1d5b02cdaecb 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -26,18 +26,19 @@ using namespace clang; using namespace clang::targets; static constexpr int NumNeonBuiltins = - NEON::FirstFp16Builtin - Builtin::FirstTSBuiltin; + llvm::to_underlying(NEON::FirstFp16Builtin) - Builtin::FirstTSBuiltin; static constexpr int NumFp16Builtins = - NEON::FirstTSBuiltin - NEON::FirstFp16Builtin; + llvm::to_underlying(NEON::FirstTSBuiltin) - NEON::FirstFp16Builtin; static constexpr int NumSVEBuiltins = - SVE::FirstNeonBridgeBuiltin - NEON::FirstTSBuiltin; + llvm::to_underlying(SVE::FirstNeonBridgeBuiltin) - NEON::FirstTSBuiltin; static constexpr int NumSVENeonBridgeBuiltins = - SVE::FirstTSBuiltin - SVE::FirstNeonBridgeBuiltin; -static constexpr int NumSMEBuiltins = SME::FirstTSBuiltin - SVE::FirstTSBuiltin; + llvm::to_underlying(SVE::FirstTSBuiltin) - SVE::FirstNeonBridgeBuiltin; +static constexpr int NumSMEBuiltins = + llvm::to_underlying(SME::FirstTSBuiltin) - SVE::FirstTSBuiltin; static constexpr int NumAArch64Builtins = - AArch64::LastTSBuiltin - SME::FirstTSBuiltin; + llvm::to_underlying(AArch64::LastTSBuiltin) - SME::FirstTSBuiltin; static constexpr int NumBuiltins = - AArch64::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(AArch64::LastTSBuiltin) - Builtin::FirstTSBuiltin; static_assert(NumBuiltins == (NumNeonBuiltins + NumFp16Builtins + NumSVEBuiltins + NumSVENeonBridgeBuiltins + NumSMEBuiltins + NumAArch64Builtins)); diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp index c01e4c8074b24..1c2c2ecf44355 100644 --- a/clang/lib/Basic/Targets/AMDGPU.cpp +++ b/clang/lib/Basic/Targets/AMDGPU.cpp @@ -66,7 +66,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUAddrSpaceMap = { } // namespace clang static constexpr int NumBuiltins = - clang::AMDGPU::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::AMDGPU::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsAMDGPU.inc" diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp index 0e424d031700b..15508f9a3a525 100644 --- a/clang/lib/Basic/Targets/ARM.cpp +++ b/clang/lib/Basic/Targets/ARM.cpp @@ -1045,16 +1045,16 @@ void ARMTargetInfo::getTargetDefines(const LangOptions &Opts, } } -static constexpr int NumBuiltins = ARM::LastTSBuiltin - Builtin::FirstTSBuiltin; +static constexpr int NumBuiltins = llvm::to_underlying(ARM::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr int NumNeonBuiltins = - NEON::FirstFp16Builtin - Builtin::FirstTSBuiltin; + llvm::to_underlying(NEON::FirstFp16Builtin) - Builtin::FirstTSBuiltin; static constexpr int NumFp16Builtins = - NEON::FirstTSBuiltin - NEON::FirstFp16Builtin; + llvm::to_underlying(NEON::FirstTSBuiltin) - NEON::FirstFp16Builtin; static constexpr int NumMVEBuiltins = - ARM::FirstCDEBuiltin - NEON::FirstTSBuiltin; + llvm::to_underlying(ARM::FirstCDEBuiltin) - NEON::FirstTSBuiltin; static constexpr int NumCDEBuiltins = - ARM::FirstARMBuiltin - ARM::FirstCDEBuiltin; -static constexpr int NumARMBuiltins = ARM::LastTSBuiltin - ARM::FirstARMBuiltin; + llvm::to_underlying(ARM::FirstARMBuiltin) - ARM::FirstCDEBuiltin; +static constexpr int NumARMBuiltins = llvm::to_underlying(ARM::LastTSBuiltin) - ARM::FirstARMBuiltin; static_assert(NumBuiltins == (NumNeonBuiltins + NumFp16Builtins + NumMVEBuiltins + NumCDEBuiltins + NumARMBuiltins)); diff --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp index 18db0a7807b53..2603fc149eee9 100644 --- a/clang/lib/Basic/Targets/AVR.cpp +++ b/clang/lib/Basic/Targets/AVR.cpp @@ -19,7 +19,8 @@ using namespace clang; using namespace clang::targets; -static constexpr int NumBuiltins = AVR::LastTSBuiltin - Builtin::FirstTSBuiltin; +static constexpr int NumBuiltins = + llvm::to_underlying(AVR::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp index 100769ea4cdb1..eb476c64b55e2 100644 --- a/clang/lib/Basic/Targets/BPF.cpp +++ b/clang/lib/Basic/Targets/BPF.cpp @@ -19,7 +19,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::BPF::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::BPF::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsBPF.inc" diff --git a/clang/lib/Basic/Targets/DirectX.cpp b/clang/lib/Basic/Targets/DirectX.cpp index ef8998dab0840..148fb7106d5f8 100644 --- a/clang/lib/Basic/Targets/DirectX.cpp +++ b/clang/lib/Basic/Targets/DirectX.cpp @@ -18,7 +18,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::DirectX::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::DirectX::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsDirectX.inc" diff --git a/clang/lib/Basic/Targets/Hexagon.cpp b/clang/lib/Basic/Targets/Hexagon.cpp index 615114f0fd1ea..4fb4e1f5f3e11 100644 --- a/clang/lib/Basic/Targets/Hexagon.cpp +++ b/clang/lib/Basic/Targets/Hexagon.cpp @@ -220,7 +220,7 @@ ArrayRef<TargetInfo::GCCRegAlias> HexagonTargetInfo::getGCCRegAliases() const { } static constexpr int NumBuiltins = - clang::Hexagon::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::Hexagon::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsHexagon.inc" diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index eabb1498a4935..d85105772960c 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -296,13 +296,13 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, } static constexpr int NumBaseBuiltins = - LoongArch::FirstLSXBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(LoongArch::FirstLSXBuiltin) - Builtin::FirstTSBuiltin; static constexpr int NumLSXBuiltins = - LoongArch::FirstLASXBuiltin - LoongArch::FirstLSXBuiltin; + llvm::to_underlying(LoongArch::FirstLASXBuiltin) - LoongArch::FirstLSXBuiltin; static constexpr int NumLASXBuiltins = - LoongArch::LastTSBuiltin - LoongArch::FirstLASXBuiltin; + llvm::to_underlying(LoongArch::LastTSBuiltin) - LoongArch::FirstLASXBuiltin; static constexpr int NumBuiltins = - LoongArch::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(LoongArch::LastTSBuiltin) - Builtin::FirstTSBuiltin; static_assert(NumBuiltins == (NumBaseBuiltins + NumLSXBuiltins + NumLASXBuiltins)); diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp index 76c9081567053..f9c046aac1bad 100644 --- a/clang/lib/Basic/Targets/Mips.cpp +++ b/clang/lib/Basic/Targets/Mips.cpp @@ -20,7 +20,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::Mips::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::Mips::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/Basic/Targets/NVPTX.cpp b/clang/lib/Basic/Targets/NVPTX.cpp index de99a6718f26c..0185db5d1e65e 100644 --- a/clang/lib/Basic/Targets/NVPTX.cpp +++ b/clang/lib/Basic/Targets/NVPTX.cpp @@ -20,7 +20,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::NVPTX::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::NVPTX::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsNVPTX.inc" diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp index b293bdb05f241..bd1711e15de04 100644 --- a/clang/lib/Basic/Targets/PPC.cpp +++ b/clang/lib/Basic/Targets/PPC.cpp @@ -21,7 +21,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::PPC::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::PPC::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index c282136cf5fcf..fce1f46090d82 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -267,15 +267,15 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, } static constexpr int NumRVVBuiltins = - RISCVVector::FirstSiFiveBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(RISCVVector::FirstSiFiveBuiltin) - Builtin::FirstTSBuiltin; static constexpr int NumRVVSiFiveBuiltins = - RISCVVector::FirstAndesBuiltin - RISCVVector::FirstSiFiveBuiltin; + llvm::to_underlying(RISCVVector::FirstAndesBuiltin) - RISCVVector::FirstSiFiveBuiltin; static constexpr int NumRVVAndesBuiltins = - RISCVVector::FirstTSBuiltin - RISCVVector::FirstAndesBuiltin; + llvm::to_underlying(RISCVVector::FirstTSBuiltin) - RISCVVector::FirstAndesBuiltin; static constexpr int NumRISCVBuiltins = - RISCV::LastTSBuiltin - RISCVVector::FirstTSBuiltin; + llvm::to_underlying(RISCV::LastTSBuiltin) - RISCVVector::FirstTSBuiltin; static constexpr int NumBuiltins = - RISCV::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(RISCV::LastTSBuiltin) - Builtin::FirstTSBuiltin; static_assert(NumBuiltins == (NumRVVBuiltins + NumRVVSiFiveBuiltins + NumRVVAndesBuiltins + NumRISCVBuiltins)); diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp index 3eb62c9051b58..546f063f8414f 100644 --- a/clang/lib/Basic/Targets/SPIR.cpp +++ b/clang/lib/Basic/Targets/SPIR.cpp @@ -20,7 +20,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::SPIRV::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::SPIRV::LastTSBuiltin) - Builtin::FirstTSBuiltin; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsSPIRVCommon.inc" diff --git a/clang/lib/Basic/Targets/SystemZ.cpp b/clang/lib/Basic/Targets/SystemZ.cpp index 080a961b95d0d..96c1c5e9d822e 100644 --- a/clang/lib/Basic/Targets/SystemZ.cpp +++ b/clang/lib/Basic/Targets/SystemZ.cpp @@ -22,9 +22,9 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::SystemZ::LastSystemZBuiltin - Builtin::FirstTSBuiltin + 1; + llvm::to_underlying(clang::SystemZ::LastSystemZBuiltin) - Builtin::FirstTSBuiltin + 1; static constexpr int NumBuiltinsZOS = - clang::SystemZ::LastTSBuiltin - clang::SystemZ::LastSystemZBuiltin - 1; + llvm::to_underlying(clang::SystemZ::LastTSBuiltin) - clang::SystemZ::LastSystemZBuiltin - 1; #define GET_BUILTIN_STR_TABLE #include "clang/Basic/BuiltinsSystemZ.inc" diff --git a/clang/lib/Basic/Targets/VE.cpp b/clang/lib/Basic/Targets/VE.cpp index 5451f3c303637..329a809e36bc6 100644 --- a/clang/lib/Basic/Targets/VE.cpp +++ b/clang/lib/Basic/Targets/VE.cpp @@ -19,7 +19,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::VE::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::VE::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp b/clang/lib/Basic/Targets/WebAssembly.cpp index a483e3d6f9b10..ab18d3330a74f 100644 --- a/clang/lib/Basic/Targets/WebAssembly.cpp +++ b/clang/lib/Basic/Targets/WebAssembly.cpp @@ -21,7 +21,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - clang::WebAssembly::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(clang::WebAssembly::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp index 8ab39b750dc99..2d20c59722b4a 100644 --- a/clang/lib/Basic/Targets/X86.cpp +++ b/clang/lib/Basic/Targets/X86.cpp @@ -24,10 +24,10 @@ namespace targets { // The x86-32 builtins are a subset and prefix of the x86-64 builtins. static constexpr int NumX86Builtins = - X86::LastX86CommonBuiltin - Builtin::FirstTSBuiltin + 1; + llvm::to_underlying(X86::LastX86CommonBuiltin) - Builtin::FirstTSBuiltin + 1; static constexpr int NumX86_64Builtins = - X86::LastTSBuiltin - X86::FirstX86_64Builtin; -static constexpr int NumBuiltins = X86::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(X86::LastTSBuiltin) - X86::FirstX86_64Builtin; +static constexpr int NumBuiltins = llvm::to_underlying(X86::LastTSBuiltin) - Builtin::FirstTSBuiltin; static_assert(NumBuiltins == (NumX86Builtins + NumX86_64Builtins)); namespace X86 { diff --git a/clang/lib/Basic/Targets/XCore.cpp b/clang/lib/Basic/Targets/XCore.cpp index c725703ede5b0..2adc2bde7aa9b 100644 --- a/clang/lib/Basic/Targets/XCore.cpp +++ b/clang/lib/Basic/Targets/XCore.cpp @@ -19,7 +19,7 @@ using namespace clang; using namespace clang::targets; static constexpr int NumBuiltins = - XCore::LastTSBuiltin - Builtin::FirstTSBuiltin; + llvm::to_underlying(XCore::LastTSBuiltin) - Builtin::FirstTSBuiltin; static constexpr llvm::StringTable BuiltinStrings = CLANG_BUILTIN_STR_TABLE_START diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 1ed8989d3f627..6365744f2254c 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1170,7 +1170,7 @@ Address CodeGenModule::createUnnamedGlobalFrom(const VarDecl &D, if (D.hasGlobalStorage()) Name = getMangledName(&D).str() + ".const"; else if (const DeclContext *DC = D.getParentFunctionOrMethod()) - Name = ("__const." + FunctionName(DC) + "." + D.getName()).str(); + Name = (Twine("__const.") + FunctionName(DC) + "." + D.getName()).str(); else llvm_unreachable("local variable has no parent function or method"); llvm::GlobalVariable *GV = new llvm::GlobalVariable( diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index eba802e187beb..6dee25dbf7eb7 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -6105,7 +6105,7 @@ LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr *E){ if (QualType::DestructionKind DtorKind = E->getType().isDestructedType()) pushLifetimeExtendedDestroy(getCleanupKind(DtorKind), DeclPtr, E->getType(), getDestroyer(DtorKind), - DtorKind & EHCleanup); + needsEHCleanup(DtorKind)); return Result; } diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index f18978c7a936e..411c3b95bf6e1 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -816,7 +816,7 @@ void AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { if (QualType::DestructionKind DtorKind = E->getType().isDestructedType()) CGF.pushLifetimeExtendedDestroy( CGF.getCleanupKind(DtorKind), Slot.getAddress(), E->getType(), - CGF.getDestroyer(DtorKind), DtorKind & EHCleanup); + CGF.getDestroyer(DtorKind), CGF.needsEHCleanup(DtorKind)); } /// Attempt to look through various unimportant expressions to find a diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 43e4c02411d15..29fdb49bbd5e1 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -188,7 +188,7 @@ class CGObjCGNU : public CGObjCRuntime { } std::string SymbolForProtocolRef(StringRef Name) { - return (ManglePublicSymbol("OBJC_REF_PROTOCOL_") + Name).str(); + return (Twine(ManglePublicSymbol("OBJC_REF_PROTOCOL_")) + Name).str(); } @@ -986,13 +986,13 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { std::string SymbolForClassRef(StringRef Name, bool isWeak) { if (isWeak) - return (ManglePublicSymbol("OBJC_WEAK_REF_CLASS_") + Name).str(); + return (Twine(ManglePublicSymbol("OBJC_WEAK_REF_CLASS_")) + Name).str(); else - return (ManglePublicSymbol("OBJC_REF_CLASS_") + Name).str(); + return (Twine(ManglePublicSymbol("OBJC_REF_CLASS_")) + Name).str(); } /// Generate the name of a class symbol. std::string SymbolForClass(StringRef Name) { - return (ManglePublicSymbol("OBJC_CLASS_") + Name).str(); + return (Twine(ManglePublicSymbol("OBJC_CLASS_")) + Name).str(); } void CallRuntimeFunction(CGBuilderTy &B, StringRef FunctionName, ArrayRef<llvm::Value*> Args) { @@ -1496,8 +1496,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep { llvm::Constant *GetConstantSelector(Selector Sel, const std::string &TypeEncoding) override { std::string MangledTypes = GetSymbolNameForTypeEncoding(TypeEncoding); - auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" + - MangledTypes).str(); + auto SelVarName = (Twine(".objc_selector_") + Sel.getAsString() + "_" + + MangledTypes).str(); if (auto *GV = TheModule.getNamedGlobal(SelVarName)) return GV; ConstantInitBuilder builder(CGM); diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 1ad07936e6f05..a9e2511138e91 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1260,7 +1260,7 @@ static llvm::Function *emitParallelOrTeamsOutlinedFunction( std::string CGOpenMPRuntime::getOutlinedHelperName(StringRef Name) const { std::string Suffix = getName({"omp_outlined"}); - return (Name + Suffix).str(); + return (Twine(Name) + Suffix).str(); } std::string CGOpenMPRuntime::getOutlinedHelperName(CodeGenFunction &CGF) const { @@ -1269,7 +1269,7 @@ std::string CGOpenMPRuntime::getOutlinedHelperName(CodeGenFunction &CGF) const { std::string CGOpenMPRuntime::getReductionFuncName(StringRef Name) const { std::string Suffix = getName({"omp", "reduction", "reduction_func"}); - return (Name + Suffix).str(); + return (Twine(Name) + Suffix).str(); } llvm::Function *CGOpenMPRuntime::emitParallelOutlinedFunction( diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 7a742e404bf5c..4f57db27bd2de 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5938,7 +5938,7 @@ void Driver::generatePrefixedToolNames( StringRef Tool, const ToolChain &TC, SmallVectorImpl<std::string> &Names) const { // FIXME: Needs a better variable than TargetTriple - Names.emplace_back((TargetTriple + "-" + Tool).str()); + Names.emplace_back((Twine(TargetTriple) + "-" + Tool).str()); Names.emplace_back(Tool); } @@ -5962,7 +5962,7 @@ std::string Driver::GetProgramPath(StringRef Name, const ToolChain &TC) const { if (ScanDirForExecutable(P, Name)) return std::string(P); } else { - SmallString<128> P((PrefixDir + Name).str()); + SmallString<128> P((Twine(PrefixDir) + Name).str()); if (llvm::sys::fs::can_execute(Twine(P))) return std::string(P); } diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 7591d9f7fa418..0aa46b1a58b63 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2122,11 +2122,11 @@ void Generic_GCC::GCCInstallationDetector::init( StringRef OSEnv = TargetTriple.getOSAndEnvironmentName(); if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32) OSEnv = "linux-gnu"; - TripleNoVendor = (TargetTriple.getArchName().str() + '-' + OSEnv).str(); + TripleNoVendor = (TargetTriple.getArchName() + "-" + OSEnv).str(); CandidateTripleAliases.push_back(TripleNoVendor); if (BiarchVariantTriple.getArch() != llvm::Triple::UnknownArch) { BiarchTripleNoVendor = - (BiarchVariantTriple.getArchName().str() + '-' + OSEnv).str(); + (BiarchVariantTriple.getArchName() + "-" + OSEnv).str(); CandidateBiarchTripleAliases.push_back(BiarchTripleNoVendor); } } @@ -2939,9 +2939,10 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( // using LI to ensure stable path separators across Windows and // Linux. Installation.GCCInstallPath = - (LibDir + "/" + LibSuffix + "/" + VersionText).str(); + (Twine(LibDir) + "/" + LibSuffix + "/" + VersionText).str(); Installation.GCCParentLibPath = - (Installation.GCCInstallPath + "/../" + Suffix.ReversePath).str(); + (Twine(Installation.GCCInstallPath) + "/../" + Suffix.ReversePath) + .str(); Installation.SelectedMultilib = getMultilib(); Installations.push_back(Installation); diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index 2ab9ba4ea7cda..e93f7b0a7862d 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -564,11 +564,14 @@ toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, SubdirName = CandidateSubdir; getFilePaths().push_back( - (Base + SubdirName + llvm::sys::path::get_separator() + "lib").str()); + (Twine(Base) + SubdirName + llvm::sys::path::get_separator() + "lib") + .str()); // Gentoo getFilePaths().push_back( - (Base + SubdirName + llvm::sys::path::get_separator() + "mingw/lib").str()); + (Twine(Base) + SubdirName + llvm::sys::path::get_separator() + + "mingw/lib") + .str()); // Only include <base>/lib if we're not cross compiling (not even for // windows->windows to a different arch), or if the sysroot has been set @@ -829,8 +832,8 @@ void toolchains::MinGW::AddClangCXXStdlibIncludeArgs( switch (GetCXXStdlibType(DriverArgs)) { case ToolChain::CST_Libcxx: { - std::string TargetDir = (Base + "include" + Slash + getTripleString() + - Slash + "c++" + Slash + "v1") + std::string TargetDir = (Twine(Base) + "include" + Slash + + getTripleString() + Slash + "c++" + Slash + "v1") .str(); if (getDriver().getVFS().exists(TargetDir)) addSystemInclude(DriverArgs, CC1Args, TargetDir); diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 877ef662fe8da..4e94ab834366f 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -389,6 +389,10 @@ void FrontendAction::EndSourceFileAction() { getCompilerInstance().getPreprocessor().SetEnableMacroExpansion(); } +void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput) { + setCurrentInput(CurrentInput, nullptr); +} + void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr<ASTUnit> AST) { this->CurrentInput = CurrentInput; diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp index 93e3e3ca2322a..9e2bdd1e074b8 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp @@ -483,8 +483,8 @@ class SymbolExpressor if (std::optional<std::string> Str = lookup(S)) return Str; if (std::optional<std::string> Str = Visit(S->getLHS())) - return (*Str + " " + BinaryOperator::getOpcodeStr(S->getOpcode()) + " " + - std::to_string(S->getRHS()->getLimitedValue()) + + return (Twine(*Str) + " " + BinaryOperator::getOpcodeStr(S->getOpcode()) + + " " + std::to_string(S->getRHS()->getLimitedValue()) + (S->getRHS()->isUnsigned() ? "U" : "")) .str(); return std::nullopt; @@ -495,8 +495,8 @@ class SymbolExpressor return Str; if (std::optional<std::string> Str1 = Visit(S->getLHS())) if (std::optional<std::string> Str2 = Visit(S->getRHS())) - return (*Str1 + " " + BinaryOperator::getOpcodeStr(S->getOpcode()) + - " " + *Str2) + return (Twine(*Str1) + " " + + BinaryOperator::getOpcodeStr(S->getOpcode()) + " " + *Str2) .str(); return std::nullopt; } @@ -505,7 +505,7 @@ class SymbolExpressor if (std::optional<std::string> Str = lookup(S)) return Str; if (std::optional<std::string> Str = Visit(S->getOperand())) - return (UnaryOperator::getOpcodeStr(S->getOpcode()) + *Str).str(); + return (Twine(UnaryOperator::getOpcodeStr(S->getOpcode())) + *Str).str(); return std::nullopt; } diff --git a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp index 43500f619896a..cfec79ff61586 100644 --- a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp @@ -87,7 +87,7 @@ class TextDiagnostics : public PathDiagnosticConsumer { : "") .str(); reportPiece(WarnID, PD->getLocation().asLocation(), - (PD->getShortDescription() + WarningMsg).str(), + (Twine(PD->getShortDescription()) + WarningMsg).str(), PD->path.back()->getRanges(), PD->path.back()->getFixits()); // First, add extra notes, even if paths should not be included. diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index 10bdc223e33f2..30ecf9ff7df04 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/lib/Tooling/Core/Replacement.cpp @@ -393,7 +393,7 @@ class MergedReplacement { unsigned End = Offset + Length; StringRef RText = R.getReplacementText(); StringRef Tail = RText.substr(End - R.getOffset()); - Text = (Text + Tail).str(); + Text += Tail; if (R.getOffset() + RText.size() > End) { Length = R.getOffset() + R.getLength() - Offset; MergeSecond = true; diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp index 71307d1fe7307..100078e902400 100644 --- a/clang/lib/Tooling/Tooling.cpp +++ b/clang/lib/Tooling/Tooling.cpp @@ -299,7 +299,7 @@ void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine, } if (ShouldAddTarget) { CommandLine.insert(++CommandLine.begin(), - (TargetOPT + TargetMode.TargetPrefix).str()); + (Twine(TargetOPT) + TargetMode.TargetPrefix).str()); } } diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp index 22c81522f9e41..83fdec71f4a73 100644 --- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp +++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp @@ -480,7 +480,8 @@ void collectBuiltins(const Record *BuiltinRecord, for (StringRef Spelling : BuiltinRecord->getValueAsListOfStrings("Spellings")) { auto FullSpelling = - (Templates.IsPrefix ? Affix + Spelling : Spelling + Affix).str(); + (Templates.IsPrefix ? Twine(Affix) + Spelling : Twine(Spelling) + Affix) + .str(); BuiltinType BT = BuiltinType::Builtin; if (BuiltinRecord->isSubClassOf("AtomicBuiltin")) { BT = BuiltinType::AtomicBuiltin; >From 9da9a97ca0af05bcb05a6095b9aad9a4f6fa7c9a Mon Sep 17 00:00:00 2001 From: Richard Dong <[email protected]> Date: Mon, 21 Sep 2026 07:21:34 +0000 Subject: [PATCH 8/8] [llvm] C++26 fixes --- llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp | 3 ++- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 3 ++- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 3 ++- llvm/lib/MC/MCObjectFileInfo.cpp | 4 ++-- llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 8 ++++---- llvm/lib/Target/AMDGPU/SIFrameLowering.cpp | 4 ++-- llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 2 +- .../LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp | 2 +- .../LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp | 2 +- .../lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp | 2 +- llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h | 10 ++++++++++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp | 2 +- .../SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp | 2 +- llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp | 2 +- 14 files changed, 31 insertions(+), 18 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp index 14ce305376459..899fd887ca7a7 100644 --- a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp @@ -69,7 +69,8 @@ class ExtraFlags { Flags |= InlineAsm::Extra_MayUnwind; if (CB.isConvergent()) Flags |= InlineAsm::Extra_IsConvergent; - Flags |= IA->getDialect() * InlineAsm::Extra_AsmDialect; + if (IA->getDialect() == InlineAsm::AD_Intel) + Flags |= InlineAsm::Extra_AsmDialect; } void update(const TargetLowering::AsmOperandInfo &OpInfo) { diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 8f1869b5e03a1..f431b5150d333 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -1171,7 +1171,8 @@ bool FastISel::selectCall(const User *I) { ExtraInfo |= InlineAsm::Extra_MayUnwind; if (Call->isConvergent()) ExtraInfo |= InlineAsm::Extra_IsConvergent; - ExtraInfo |= IA->getDialect() * InlineAsm::Extra_AsmDialect; + if (IA->getDialect() == InlineAsm::AD_Intel) + ExtraInfo |= InlineAsm::Extra_AsmDialect; MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD, TII.get(TargetOpcode::INLINEASM)); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 065347d903033..4e39bdb74fc56 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -10243,7 +10243,8 @@ class ExtraFlags { Flags |= InlineAsm::Extra_MayUnwind; if (Call.isConvergent()) Flags |= InlineAsm::Extra_IsConvergent; - Flags |= IA->getDialect() * InlineAsm::Extra_AsmDialect; + if (IA->getDialect() == InlineAsm::AD_Intel) + Flags |= InlineAsm::Extra_AsmDialect; } void update(const TargetLowering::AsmOperandInfo &OpInfo) { diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp index 5dd5a63fda9cf..3435df0762490 100644 --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -66,7 +66,7 @@ static bool useCompactUnwind(const Triple &T) { void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { EHFrameSection = Ctx->getMachOSection( "__TEXT", "__eh_frame", - MachO::S_COALESCED | MachO::S_ATTR_NO_TOC | + llvm::to_underlying(MachO::S_COALESCED) | MachO::S_ATTR_NO_TOC | MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT, SectionKind::getReadOnly()); @@ -160,7 +160,7 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { TextCoalSection = Ctx->getMachOSection("__TEXT", "__textcoal_nt", - MachO::S_COALESCED | + llvm::to_underlying(MachO::S_COALESCED) | MachO::S_ATTR_PURE_INSTRUCTIONS, SectionKind::getText()); ConstTextCoalSection diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp index ba6813c142266..25e6cab7d9fee 100644 --- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp @@ -269,7 +269,7 @@ class DarwinAsmParser : public MCAsmParserExtension { bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) { return parseSectionSwitch("__TEXT","__symbol_stub", - MachO::S_SYMBOL_STUBS | + llvm::to_underlying(MachO::S_SYMBOL_STUBS) | MachO::S_ATTR_PURE_INSTRUCTIONS, // FIXME: Different on PPC and ARM. 0, 16); @@ -277,7 +277,7 @@ class DarwinAsmParser : public MCAsmParserExtension { bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) { return parseSectionSwitch("__TEXT","__picsymbol_stub", - MachO::S_SYMBOL_STUBS | + llvm::to_underlying(MachO::S_SYMBOL_STUBS) | MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26); } @@ -365,13 +365,13 @@ class DarwinAsmParser : public MCAsmParserExtension { bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) { return parseSectionSwitch("__OBJC", "__cls_refs", MachO::S_ATTR_NO_DEAD_STRIP | - MachO::S_LITERAL_POINTERS, 4); + llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4); } bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) { return parseSectionSwitch("__OBJC", "__message_refs", MachO::S_ATTR_NO_DEAD_STRIP | - MachO::S_LITERAL_POINTERS, 4); + llvm::to_underlying(MachO::S_LITERAL_POINTERS), 4); } bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) { diff --git a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp index 92fb77b1e6436..5a018a1b46d3d 100644 --- a/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp @@ -81,7 +81,7 @@ static MCCFIInstruction createScaledCFAInPrivateWave(const GCNSubtarget &ST, << uint8_t(dwarf::DW_OP_lit0 + WavefrontSizeLog2) << uint8_t(dwarf::DW_OP_shl) << uint8_t(dwarf::DW_OP_lit0 + - dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave) + llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)) << uint8_t(dwarf::DW_OP_LLVM_user) << uint8_t(dwarf::DW_OP_LLVM_form_aspace_address); @@ -780,7 +780,7 @@ void SIFrameLowering::emitEntryFunctionPrologue(MachineFunction &MF, 4, // length static_cast<char>(dwarf::DW_OP_lit0), static_cast<char>(dwarf::DW_OP_lit0 + - dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave), + llvm::to_underlying(dwarf::DW_ASPACE_LLVM_AMDGPU_private_wave)), static_cast<char>(dwarf::DW_OP_LLVM_user), static_cast<char>(dwarf::DW_OP_LLVM_form_aspace_address)}; static StringRef CFAEncodedInstUserOps = diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp index 129f3071a3a88..088cebe1d53d5 100644 --- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp +++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp @@ -628,7 +628,7 @@ struct OpRef { assert(!R.isValue()); return OpRef(R.OpN & (Undef | Index | HiHalf)); } - static OpRef undef(MVT Ty) { return OpRef(Undef | Ty.SimpleTy); } + static OpRef undef(MVT Ty) { return OpRef(Undef | llvm::to_underlying(Ty.SimpleTy)); } // Direct value. SDValue OpV = SDValue(); diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp index 4581da3c7b9c3..1895fa2eb9920 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp @@ -252,7 +252,7 @@ bool LoongArchAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) { Ctx); } MCFixup Fixup = - MCFixup::create(0, Expr, FirstLiteralRelocationKind + ELF::R_LARCH_ALIGN); + MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_ALIGN)); F.setVarFixups({Fixup}); F.setLinkerRelaxable(); return true; diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp index 8146a15eba295..3a77bd154ca2c 100644 --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp @@ -166,7 +166,7 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO, // `la.abs`. Fixups.push_back( MCFixup::create(0, MCConstantExpr::create(0, Ctx), - FirstLiteralRelocationKind + ELF::R_LARCH_MARK_LA)); + FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_LARCH_MARK_LA))); [[fallthrough]]; case ELF::R_LARCH_ABS_HI20: FixupKind = LoongArch::fixup_loongarch_abs_hi20; diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp index 7b2d2be503d72..0a64998a213c7 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFStreamer.cpp @@ -157,7 +157,7 @@ void PPCELFStreamer::emitGOTToPCRelReloc(const MCInst &Inst) { MCFragment *F = LabelSym->getFragment(); F->addFixup( MCFixup::create(LabelSym->getOffset() - 8, SubExpr2, - FirstLiteralRelocationKind + ELF::R_PPC64_PCREL_OPT)); + FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_PPC64_PCREL_OPT))); emitLabel(CurrentLocation, Inst.getLoc()); } diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h index d686a8ea2a228..cd73179274110 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCPredicates.h @@ -13,6 +13,8 @@ #ifndef LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H #define LLVM_LIB_TARGET_POWERPC_MCTARGETDESC_PPCPREDICATES_H +#include "llvm/ADT/STLForwardCompat.h" + // GCC #defines PPC on Linux but we use it as our namespace name #undef PPC @@ -66,6 +68,14 @@ namespace PPC { BR_HINT_MASK = 0X3 }; + inline unsigned operator&(Predicate P, BranchHintBit B) { + return llvm::to_underlying(P) & llvm::to_underlying(B); + } + + inline unsigned operator&(BranchHintBit B, Predicate P) { + return P & B; + } + /// Invert the specified predicate. != -> ==, < -> >=. Predicate InvertPredicate(Predicate Opcode); diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp index 315d129aeb5fb..9c9fb67968a7d 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -350,7 +350,7 @@ bool RISCVAsmBackend::relaxAlign(MCFragment &F, unsigned &Size) { Size = F.getAlignment().value() - MinNopLen; auto *Expr = MCConstantExpr::create(Size, getContext()); MCFixup Fixup = - MCFixup::create(0, Expr, FirstLiteralRelocationKind + ELF::R_RISCV_ALIGN); + MCFixup::create(0, Expr, FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_RISCV_ALIGN)); F.setVarFixups({Fixup}); F.setLinkerRelaxable(); return true; diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp index 383c96e8cca73..bd0bcabb0e239 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp @@ -172,7 +172,7 @@ uint64_t SystemZMCCodeEmitter::getImmOpValue(const MCInst &MI, unsigned OpNum, unsigned MIBitSize = MCII.get(MI.getOpcode()).getSize() * 8; uint32_t RawBitOffset = getOperandBitOffset(MI, OpNum, STI); unsigned OpBitSize = - SystemZ::MCFixupKindInfos[Kind - FirstTargetFixupKind].TargetSize; + SystemZ::MCFixupKindInfos[llvm::to_underlying(Kind) - FirstTargetFixupKind].TargetSize; uint32_t BitOffset = MIBitSize - RawBitOffset - OpBitSize; addFixup(Fixups, BitOffset >> 3, MO.getExpr(), Kind); return 0; diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp index ab535c81dbf42..8f2374426b806 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp @@ -542,7 +542,7 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc, assert(ImmOffset == 0); if (Size == 8) { - FixupKind = FirstLiteralRelocationKind + ELF::R_X86_64_GOTPC64; + FixupKind = FirstLiteralRelocationKind + llvm::to_underlying(ELF::R_X86_64_GOTPC64); } else { assert(Size == 4); FixupKind = X86::reloc_global_offset_table; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
