[llvm] [llvm] Use StringRef::{starts,ends}_with (NFC) (PR #74956)

via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 9 16:35:18 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-backend-arm

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.


---

Patch is 234.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/74956.diff


191 Files Affected:

- (modified) llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h (+1-1) 
- (modified) llvm/include/llvm/CodeGen/IndirectThunks.h (+2-2) 
- (modified) llvm/include/llvm/CodeGen/MIRYamlMapping.h (+2-2) 
- (modified) llvm/include/llvm/MC/MCSectionCOFF.h (+1-1) 
- (modified) llvm/include/llvm/Object/ELFObjectFile.h (+7-7) 
- (modified) llvm/include/llvm/Passes/PassBuilder.h (+3-3) 
- (modified) llvm/include/llvm/ProfileData/SampleProf.h (+1-1) 
- (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+2-2) 
- (modified) llvm/lib/Analysis/LoopInfo.cpp (+1-1) 
- (modified) llvm/lib/Analysis/VFABIDemangling.cpp (+1-1) 
- (modified) llvm/lib/AsmParser/LLLexer.cpp (+3-3) 
- (modified) llvm/lib/BinaryFormat/Magic.cpp (+3-3) 
- (modified) llvm/lib/Bitcode/Reader/MetadataLoader.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalMerge.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/MIRParser/MILexer.cpp (+8-8) 
- (modified) llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+15-15) 
- (modified) llvm/lib/CodeGen/WinEHPrepare.cpp (+1-1) 
- (modified) llvm/lib/DWARFLinker/DWARFLinker.cpp (+3-3) 
- (modified) llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.cpp (+3-3) 
- (modified) llvm/lib/DWARFLinkerParallel/SyntheticTypeNameBuilder.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/JITLink/ELF_x86_64.cpp (+2-2) 
- (modified) llvm/lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/Debugging/DebugInfoSupport.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/Debugging/DebuggerSupportPlugin.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (+3-3) 
- (modified) llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/LLJIT.cpp (+2-2) 
- (modified) llvm/lib/ExecutionEngine/Orc/ObjectFileInterface.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/Shared/ObjectFormats.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/JITSymbol.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldCOFF.cpp (+2-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp (+26-26) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h (+1-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h (+1-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFThumb.h (+1-1) 
- (modified) llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFX86_64.h (+1-1) 
- (modified) llvm/lib/FileCheck/FileCheck.cpp (+16-16) 
- (modified) llvm/lib/FuzzMutate/FuzzerCLI.cpp (+2-2) 
- (modified) llvm/lib/IR/AutoUpgrade.cpp (+1-1) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+1-1) 
- (modified) llvm/lib/IR/Function.cpp (+3-3) 
- (modified) llvm/lib/IR/Mangler.cpp (+2-2) 
- (modified) llvm/lib/IR/PassInstrumentation.cpp (+2-1) 
- (modified) llvm/lib/IR/Type.cpp (+1-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+1-1) 
- (modified) llvm/lib/InterfaceStub/IFSHandler.cpp (+1-1) 
- (modified) llvm/lib/LTO/LTOModule.cpp (+4-4) 
- (modified) llvm/lib/Linker/IRMover.cpp (+1-1) 
- (modified) llvm/lib/MC/ELFObjectWriter.cpp (+6-6) 
- (modified) llvm/lib/MC/MCAsmStreamer.cpp (+3-3) 
- (modified) llvm/lib/MC/MCContext.cpp (+5-5) 
- (modified) llvm/lib/MC/MCDwarf.cpp (+1-1) 
- (modified) llvm/lib/MC/MCParser/AsmLexer.cpp (+2-2) 
- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+1-1) 
- (modified) llvm/lib/MC/MCParser/COFFMasmParser.cpp (+1-1) 
- (modified) llvm/lib/MC/MCParser/ELFAsmParser.cpp (+2-2) 
- (modified) llvm/lib/MC/MCParser/MasmParser.cpp (+2-2) 
- (modified) llvm/lib/MC/StringTableBuilder.cpp (+1-1) 
- (modified) llvm/lib/MC/WasmObjectWriter.cpp (+6-6) 
- (modified) llvm/lib/MC/WinCOFFObjectWriter.cpp (+1-1) 
- (modified) llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp (+1-1) 
- (modified) llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp (+8-8) 
- (modified) llvm/lib/ObjCopy/MachO/MachOObject.h (+2-2) 
- (modified) llvm/lib/ObjCopy/wasm/WasmObjcopy.cpp (+2-2) 
- (modified) llvm/lib/Object/Archive.cpp (+8-8) 
- (modified) llvm/lib/Object/COFFImportFile.cpp (+3-3) 
- (modified) llvm/lib/Object/COFFModuleDefinition.cpp (+2-2) 
- (modified) llvm/lib/Object/COFFObjectFile.cpp (+3-3) 
- (modified) llvm/lib/Object/MachOObjectFile.cpp (+5-5) 
- (modified) llvm/lib/Object/ModuleSymbolTable.cpp (+1-1) 
- (modified) llvm/lib/Object/RecordStreamer.cpp (+1-1) 
- (modified) llvm/lib/Object/WasmObjectFile.cpp (+1-1) 
- (modified) llvm/lib/ObjectYAML/ELFEmitter.cpp (+1-1) 
- (modified) llvm/lib/ObjectYAML/ELFYAML.cpp (+3-3) 
- (modified) llvm/lib/Option/ArgList.cpp (+1-1) 
- (modified) llvm/lib/Option/OptTable.cpp (+6-6) 
- (modified) llvm/lib/Passes/PassBuilder.cpp (+3-3) 
- (modified) llvm/lib/ProfileData/GCOV.cpp (+1-1) 
- (modified) llvm/lib/ProfileData/InstrProf.cpp (+1-1) 
- (modified) llvm/lib/ProfileData/InstrProfCorrelator.cpp (+1-1) 
- (modified) llvm/lib/ProfileData/InstrProfReader.cpp (+4-4) 
- (modified) llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp (+3-3) 
- (modified) llvm/lib/ProfileData/SampleProfReader.cpp (+2-2) 
- (modified) llvm/lib/ProfileData/SymbolRemappingReader.cpp (+1-1) 
- (modified) llvm/lib/Remarks/YAMLRemarkParser.cpp (+1-1) 
- (modified) llvm/lib/Support/Unix/Path.inc (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64SLSHardening.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+16-16) 
- (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+5-5) 
- (modified) llvm/lib/Target/ARM/ARMSLSHardening.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.cpp (+2-2) 
- (modified) llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (+49-49) 
- (modified) llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/AVR/AVRAsmPrinter.cpp (+3-3) 
- (modified) llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp (+6-6) 
- (modified) llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp (+2-2) 
- (modified) llvm/lib/Target/BPF/BPFPreserveDIType.cpp (+1-1) 
- (modified) llvm/lib/Target/BPF/BTFDebug.cpp (+3-3) 
- (modified) llvm/lib/Target/Hexagon/HexagonSubtarget.cpp (+3-3) 
- (modified) llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+1-1) 
- (modified) llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp (+7-7) 
- (modified) llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp (+2-2) 
- (modified) llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp (+3-3) 
- (modified) llvm/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp (+3-3) 
- (modified) llvm/lib/Target/Mips/MipsISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp (+2-2) 
- (modified) llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXReplaceImageHandles.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCTargetMachine.cpp (+2-2) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+2-2) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp (+2-2) 
- (modified) llvm/lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp (+15-15) 
- (modified) llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (+2-2) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+35-35) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/X86InsertPrefetch.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86Subtarget.cpp (+2-2) 
- (modified) llvm/lib/Target/XCore/XCoreISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/AArch64TargetParser.cpp (+2-2) 
- (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+2-2) 
- (modified) llvm/lib/TargetParser/ARMTargetParserCommon.cpp (+13-13) 
- (modified) llvm/lib/TargetParser/CSKYTargetParser.cpp (+1-1) 
- (modified) llvm/lib/TargetParser/Host.cpp (+7-7) 
- (modified) llvm/lib/TargetParser/Triple.cpp (+15-14) 
- (modified) llvm/lib/TextAPI/Symbol.cpp (+5-5) 
- (modified) llvm/lib/TextAPI/Target.cpp (+1-1) 
- (modified) llvm/lib/TextAPI/TextStub.cpp (+9-9) 
- (modified) llvm/tools/dsymutil/BinaryHolder.cpp (+1-1) 
- (modified) llvm/tools/dsymutil/DwarfLinkerForBinary.cpp (+2-2) 
- (modified) llvm/tools/dsymutil/MachODebugMapParser.cpp (+2-2) 
- (modified) llvm/tools/dsymutil/MachOUtils.cpp (+1-1) 
- (modified) llvm/tools/dsymutil/SymbolMap.cpp (+2-2) 
- (modified) llvm/tools/llc/llc.cpp (+3-3) 
- (modified) llvm/tools/lli/lli.cpp (+1-1) 
- (modified) llvm/tools/llvm-ar/llvm-ar.cpp (+2-2) 
- (modified) llvm/tools/llvm-as/llvm-as.cpp (+1-1) 
- (modified) llvm/tools/llvm-config/llvm-config.cpp (+5-5) 
- (modified) llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp (+14-14) 
- (modified) llvm/tools/llvm-diff/llvm-diff.cpp (+2-1) 
- (modified) llvm/tools/llvm-dis/llvm-dis.cpp (+1-1) 
- (modified) llvm/tools/llvm-dwarfutil/DebugInfoLinker.h (+1-1) 
- (modified) llvm/tools/llvm-exegesis/lib/X86/Target.cpp (+3-3) 
- (modified) llvm/tools/llvm-jitlink/llvm-jitlink.cpp (+3-3) 
- (modified) llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp (+1-1) 
- (modified) llvm/tools/llvm-nm/llvm-nm.cpp (+7-7) 
- (modified) llvm/tools/llvm-objcopy/ObjcopyOptions.cpp (+1-1) 
- (modified) llvm/tools/llvm-objdump/COFFDump.cpp (+1-1) 
- (modified) llvm/tools/llvm-objdump/MachODump.cpp (+2-2) 
- (modified) llvm/tools/llvm-objdump/SourcePrinter.cpp (+1-1) 
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+1-1) 
- (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+1-1) 
- (modified) llvm/tools/llvm-profgen/PerfReader.cpp (+6-6) 
- (modified) llvm/tools/llvm-rc/ResourceScriptCppFilter.cpp (+1-1) 
- (modified) llvm/tools/llvm-rc/ResourceScriptToken.cpp (+3-3) 
- (modified) llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp (+1-1) 
- (modified) llvm/tools/llvm-readobj/COFFDumper.cpp (+1-1) 
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+3-3) 
- (modified) llvm/tools/llvm-readobj/Win64EHDumper.cpp (+1-1) 
- (modified) llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp (+1-1) 
- (modified) llvm/tools/llvm-reduce/llvm-reduce.cpp (+1-1) 
- (modified) llvm/tools/llvm-stress/llvm-stress.cpp (+1-1) 
- (modified) llvm/tools/llvm-undname/llvm-undname.cpp (+1-1) 
- (modified) llvm/tools/obj2yaml/archive2yaml.cpp (+1-1) 
- (modified) llvm/tools/obj2yaml/elf2yaml.cpp (+1-1) 
- (modified) llvm/tools/obj2yaml/macho2yaml.cpp (+3-3) 
- (modified) llvm/tools/obj2yaml/wasm2yaml.cpp (+1-1) 
- (modified) llvm/tools/opt/opt.cpp (+1-1) 
- (modified) llvm/tools/yaml2obj/yaml2obj.cpp (+3-3) 
- (modified) llvm/utils/split-file/split-file.cpp (+2-2) 
- (modified) llvm/utils/yaml-bench/YAMLBench.cpp (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
index 20ff5a5bc6e034..ccf859922e1634 100644
--- a/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
+++ b/llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
@@ -203,7 +203,7 @@ inline bool IsObjCIdentifiedObject(const Value *V) {
       StringRef Name = GV->getName();
       // These special variables are known to hold values which are not
       // reference-counted pointers.
-      if (Name.startswith("\01l_objc_msgSend_fixup_"))
+      if (Name.starts_with("\01l_objc_msgSend_fixup_"))
         return true;
 
       StringRef Section = GV->getSection();
diff --git a/llvm/include/llvm/CodeGen/IndirectThunks.h b/llvm/include/llvm/CodeGen/IndirectThunks.h
index b0a8e3043be5cc..9b064ab788bf78 100644
--- a/llvm/include/llvm/CodeGen/IndirectThunks.h
+++ b/llvm/include/llvm/CodeGen/IndirectThunks.h
@@ -48,7 +48,7 @@ template <typename Derived, typename InsertedThunksTy>
 void ThunkInserter<Derived, InsertedThunksTy>::createThunkFunction(
     MachineModuleInfo &MMI, StringRef Name, bool Comdat,
     StringRef TargetAttrs) {
-  assert(Name.startswith(getDerived().getThunkPrefix()) &&
+  assert(Name.starts_with(getDerived().getThunkPrefix()) &&
          "Created a thunk with an unexpected prefix!");
 
   Module &M = const_cast<Module &>(*MMI.getModule());
@@ -94,7 +94,7 @@ template <typename Derived, typename InsertedThunksTy>
 bool ThunkInserter<Derived, InsertedThunksTy>::run(MachineModuleInfo &MMI,
                                                    MachineFunction &MF) {
   // If MF is not a thunk, check to see if we need to insert a thunk.
-  if (!MF.getName().startswith(getDerived().getThunkPrefix())) {
+  if (!MF.getName().starts_with(getDerived().getThunkPrefix())) {
     // Only add a thunk if one of the functions has the corresponding feature
     // enabled in its subtarget, and doesn't enable external thunks. The target
     // can use InsertedThunks to detect whether relevant thunks have already
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index bf35febb805762..bb8dbb0478ff54 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -433,9 +433,9 @@ template <> struct ScalarTraits<FrameIndex> {
   static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI) {
     FI.IsFixed = false;
     StringRef Num;
-    if (Scalar.startswith("%stack.")) {
+    if (Scalar.starts_with("%stack.")) {
       Num = Scalar.substr(7);
-    } else if (Scalar.startswith("%fixed-stack.")) {
+    } else if (Scalar.starts_with("%fixed-stack.")) {
       Num = Scalar.substr(13);
       FI.IsFixed = true;
     } else {
diff --git a/llvm/include/llvm/MC/MCSectionCOFF.h b/llvm/include/llvm/MC/MCSectionCOFF.h
index 373863e21ff02e..2faf84f0372cb0 100644
--- a/llvm/include/llvm/MC/MCSectionCOFF.h
+++ b/llvm/include/llvm/MC/MCSectionCOFF.h
@@ -83,7 +83,7 @@ class MCSectionCOFF final : public MCSection {
   }
 
   static bool isImplicitlyDiscardable(StringRef Name) {
-    return Name.startswith(".debug");
+    return Name.starts_with(".debug");
   }
 
   static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 8e16fc148a3c78..761c532b9bf1f4 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -742,7 +742,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
   if (EF.getHeader().e_machine == ELF::EM_AARCH64) {
     if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
       StringRef Name = *NameOrErr;
-      if (Name.startswith("$d") || Name.startswith("$x"))
+      if (Name.starts_with("$d") || Name.starts_with("$x"))
         Result |= SymbolRef::SF_FormatSpecific;
     } else {
       // TODO: Actually report errors helpfully.
@@ -752,8 +752,8 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
     if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
       StringRef Name = *NameOrErr;
       // TODO Investigate why empty name symbols need to be marked.
-      if (Name.empty() || Name.startswith("$d") || Name.startswith("$t") ||
-          Name.startswith("$a"))
+      if (Name.empty() || Name.starts_with("$d") || Name.starts_with("$t") ||
+          Name.starts_with("$a"))
         Result |= SymbolRef::SF_FormatSpecific;
     } else {
       // TODO: Actually report errors helpfully.
@@ -764,7 +764,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
   } else if (EF.getHeader().e_machine == ELF::EM_CSKY) {
     if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
       StringRef Name = *NameOrErr;
-      if (Name.startswith("$d") || Name.startswith("$t"))
+      if (Name.starts_with("$d") || Name.starts_with("$t"))
         Result |= SymbolRef::SF_FormatSpecific;
     } else {
       // TODO: Actually report errors helpfully.
@@ -775,7 +775,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
       StringRef Name = *NameOrErr;
       // Mark empty name symbols (used for label differences) and mapping
       // symbols.
-      if (Name.empty() || Name.startswith("$d") || Name.startswith("$x"))
+      if (Name.empty() || Name.starts_with("$d") || Name.starts_with("$x"))
         Result |= SymbolRef::SF_FormatSpecific;
     } else {
       // TODO: Actually report errors helpfully.
@@ -973,8 +973,8 @@ bool ELFObjectFile<ELFT>::isDebugSection(DataRefImpl Sec) const {
     return false;
   }
   StringRef SectionName = SectionNameOrErr.get();
-  return SectionName.startswith(".debug") ||
-         SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
+  return SectionName.starts_with(".debug") ||
+         SectionName.starts_with(".zdebug") || SectionName == ".gdb_index";
 }
 
 template <class ELFT>
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 19ac90842bcb08..61417431f8a8f3 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -720,10 +720,10 @@ template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
 bool parseAnalysisUtilityPasses(
     StringRef AnalysisName, StringRef PipelineName,
     PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...> &PM) {
-  if (!PipelineName.endswith(">"))
+  if (!PipelineName.ends_with(">"))
     return false;
   // See if this is an invalidate<> pass name
-  if (PipelineName.startswith("invalidate<")) {
+  if (PipelineName.starts_with("invalidate<")) {
     PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
     if (PipelineName != AnalysisName)
       return false;
@@ -732,7 +732,7 @@ bool parseAnalysisUtilityPasses(
   }
 
   // See if this is a require<> pass name
-  if (PipelineName.startswith("require<")) {
+  if (PipelineName.starts_with("require<")) {
     PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
     if (PipelineName != AnalysisName)
       return false;
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index f001f5ee9d39b6..d995cc69af894a 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -548,7 +548,7 @@ class SampleContext {
     assert(!ContextStr.empty());
     // Note that `[]` wrapped input indicates a full context string, otherwise
     // it's treated as context-less function name only.
-    bool HasContext = ContextStr.startswith("[");
+    bool HasContext = ContextStr.starts_with("[");
     if (!HasContext) {
       State = UnknownContext;
       Func = FunctionId(ContextStr);
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 97b18e51beeeeb..50167708163ef0 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -2161,7 +2161,7 @@ struct Attributor {
     Function *F = I->getFunction();
     auto &ORE = Configuration.OREGetter(F);
 
-    if (RemarkName.startswith("OMP"))
+    if (RemarkName.starts_with("OMP"))
       ORE.emit([&]() {
         return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I))
                << " [" << RemarkName << "]";
@@ -2181,7 +2181,7 @@ struct Attributor {
 
     auto &ORE = Configuration.OREGetter(F);
 
-    if (RemarkName.startswith("OMP"))
+    if (RemarkName.starts_with("OMP"))
       ORE.emit([&]() {
         return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F))
                << " [" << RemarkName << "]";
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 7567efbedfb027..87ddfe3e92ae9a 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -1143,7 +1143,7 @@ MDNode *llvm::makePostTransformationMetadata(LLVMContext &Context,
         if (S)
           IsVectorMetadata =
               llvm::any_of(RemovePrefixes, [S](StringRef Prefix) -> bool {
-                return S->getString().startswith(Prefix);
+                return S->getString().starts_with(Prefix);
               });
       }
       if (!IsVectorMetadata)
diff --git a/llvm/lib/Analysis/VFABIDemangling.cpp b/llvm/lib/Analysis/VFABIDemangling.cpp
index 92af314a41caad..ad918ef7245b00 100644
--- a/llvm/lib/Analysis/VFABIDemangling.cpp
+++ b/llvm/lib/Analysis/VFABIDemangling.cpp
@@ -32,7 +32,7 @@ static ParseRet tryParseISA(StringRef &MangledName, VFISAKind &ISA) {
   if (MangledName.empty())
     return ParseRet::Error;
 
-  if (MangledName.startswith(VFABI::_LLVM_)) {
+  if (MangledName.starts_with(VFABI::_LLVM_)) {
     MangledName = MangledName.drop_front(strlen(VFABI::_LLVM_));
     ISA = VFISAKind::LLVM;
   } else {
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp
index 919c69fe2783e7..fcb25f5f1d49df 100644
--- a/llvm/lib/AsmParser/LLLexer.cpp
+++ b/llvm/lib/AsmParser/LLLexer.cpp
@@ -922,17 +922,17 @@ lltok::Kind LLLexer::LexIdentifier() {
 
 #undef DWKEYWORD
 
-  if (Keyword.startswith("DIFlag")) {
+  if (Keyword.starts_with("DIFlag")) {
     StrVal.assign(Keyword.begin(), Keyword.end());
     return lltok::DIFlag;
   }
 
-  if (Keyword.startswith("DISPFlag")) {
+  if (Keyword.starts_with("DISPFlag")) {
     StrVal.assign(Keyword.begin(), Keyword.end());
     return lltok::DISPFlag;
   }
 
-  if (Keyword.startswith("CSK_")) {
+  if (Keyword.starts_with("CSK_")) {
     StrVal.assign(Keyword.begin(), Keyword.end());
     return lltok::ChecksumKind;
   }
diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp
index 420224df57df41..255937a5bdd04a 100644
--- a/llvm/lib/BinaryFormat/Magic.cpp
+++ b/llvm/lib/BinaryFormat/Magic.cpp
@@ -26,7 +26,7 @@ using namespace llvm::sys::fs;
 
 template <size_t N>
 static bool startswith(StringRef Magic, const char (&S)[N]) {
-  return Magic.startswith(StringRef(S, N - 1));
+  return Magic.starts_with(StringRef(S, N - 1));
 }
 
 /// Identify the magic in magic.
@@ -217,11 +217,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
     if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) {
       uint32_t off = read32le(Magic.data() + 0x3c);
       // PE/COFF file, either EXE or DLL.
-      if (Magic.substr(off).startswith(
+      if (Magic.substr(off).starts_with(
               StringRef(COFF::PEMagic, sizeof(COFF::PEMagic))))
         return file_magic::pecoff_executable;
     }
-    if (Magic.startswith("Microsoft C/C++ MSF 7.00\r\n"))
+    if (Magic.starts_with("Microsoft C/C++ MSF 7.00\r\n"))
       return file_magic::pdb;
     if (startswith(Magic, "MDMP"))
       return file_magic::minidump;
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 1a4b55ea381826..910e97489dbbe0 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1633,7 +1633,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
         // DICompositeType flag specifying whether template parameters are
         // required on declarations of this type.
         StringRef NameStr = Name->getString();
-        if (!NameStr.contains('<') || NameStr.startswith("_STN|"))
+        if (!NameStr.contains('<') || NameStr.starts_with("_STN|"))
           TemplateParams = getMDOrNull(Record[14]);
       }
     } else {
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 96662378a86931..15b6f63e86327a 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -302,7 +302,7 @@ Error BasicBlockSectionsProfileReader::ReadV0Profile() {
       // specifier starting with `M=`.
       auto [AliasesStr, DIFilenameStr] = S.split(' ');
       SmallString<128> DIFilename;
-      if (DIFilenameStr.startswith("M=")) {
+      if (DIFilenameStr.starts_with("M=")) {
         DIFilename =
             sys::path::remove_leading_dotslash(DIFilenameStr.substr(2));
         if (DIFilename.empty())
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp
index 339019923c00bd..ab4b26e294106d 100644
--- a/llvm/lib/CodeGen/GlobalMerge.cpp
+++ b/llvm/lib/CodeGen/GlobalMerge.cpp
@@ -643,8 +643,8 @@ bool GlobalMerge::doInitialization(Module &M) {
     StringRef Section = GV.getSection();
 
     // Ignore all 'special' globals.
-    if (GV.getName().startswith("llvm.") ||
-        GV.getName().startswith(".llvm."))
+    if (GV.getName().starts_with("llvm.") ||
+        GV.getName().starts_with(".llvm."))
       continue;
 
     // Ignore all "required" globals:
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
index 0a0e386cde6100..870611248466f5 100644
--- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp
@@ -300,8 +300,8 @@ static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) {
 
 static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token,
                                         ErrorCallbackType ErrorCallback) {
-  bool IsReference = C.remaining().startswith("%bb.");
-  if (!IsReference && !C.remaining().startswith("bb."))
+  bool IsReference = C.remaining().starts_with("%bb.");
+  if (!IsReference && !C.remaining().starts_with("bb."))
     return std::nullopt;
   auto Range = C;
   unsigned PrefixLength = IsReference ? 4 : 3;
@@ -335,7 +335,7 @@ static Cursor maybeLexMachineBasicBlock(Cursor C, MIToken &Token,
 
 static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule,
                             MIToken::TokenKind Kind) {
-  if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
+  if (!C.remaining().starts_with(Rule) || !isdigit(C.peek(Rule.size())))
     return std::nullopt;
   auto Range = C;
   C.advance(Rule.size());
@@ -348,7 +348,7 @@ static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule,
 
 static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule,
                                    MIToken::TokenKind Kind) {
-  if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size())))
+  if (!C.remaining().starts_with(Rule) || !isdigit(C.peek(Rule.size())))
     return std::nullopt;
   auto Range = C;
   C.advance(Rule.size());
@@ -388,7 +388,7 @@ static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token) {
 static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token,
                                        ErrorCallbackType ErrorCallback) {
   const StringRef Rule = "%subreg.";
-  if (!C.remaining().startswith(Rule))
+  if (!C.remaining().starts_with(Rule))
     return std::nullopt;
   return lexName(C, Token, MIToken::SubRegisterIndex, Rule.size(),
                  ErrorCallback);
@@ -397,7 +397,7 @@ static Cursor maybeLexSubRegisterIndex(Cursor C, MIToken &Token,
 static Cursor maybeLexIRBlock(Cursor C, MIToken &Token,
                               ErrorCallbackType ErrorCallback) {
   const StringRef Rule = "%ir-block.";
-  if (!C.remaining().startswith(Rule))
+  if (!C.remaining().starts_with(Rule))
     return std::nullopt;
   if (isdigit(C.peek(Rule.size())))
     return maybeLexIndex(C, Token, Rule, MIToken::IRBlock);
@@ -407,7 +407,7 @@ static Cursor maybeLexIRBlock(Cursor C, MIToken &Token,
 static Cursor maybeLexIRValue(Cursor C, MIToken &Token,
                               ErrorCallbackType ErrorCallback) {
   const StringRef Rule = "%ir.";
-  if (!C.remaining().startswith(Rule))
+  if (!C.remaining().starts_with(Rule))
     return std::nullopt;
   if (isdigit(C.peek(Rule.size())))
     return maybeLexIndex(C, Token, Rule, MIToken::IRValue);
@@ -501,7 +501,7 @@ static Cursor maybeLexExternalSymbol(Cursor C, MIToken &Token,
 static Cursor maybeLexMCSymbol(Cursor C, MIToken &Token,
                                ErrorCallbackType ErrorCallback) {
   const StringRef Rule = "<mcsymbol ";
-  if (!C.remaining().startswith(Rule))
+  if (!C.remaining().starts_with(Rule))
     return std::nullopt;
   auto Start = C;
   C.advance(Rule.size());
diff --git a/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp b/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
index cc29bdce1210f6..9002a707684018 100644
--- a/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
+++ b/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
@@ -52,7 +52,7 @@ bool MachineSanitizerBinaryMetadata::runOnMachineFunction(MachineFunction &MF) {
   if (!MD)
     return false;
   const auto &Section = *cast<MDString>(MD->getOperand(0));
-  if (!Section.getString().startswith(kSanitizerBinaryMetadataCoveredSection))
+  if (!Section.getString().starts_with(kSanitizerBinaryMetadataCoveredSection))
     return false;
   auto &AuxMDs = *cast<MDTuple>(MD->getOperand(1));
   // Assume it currently only has features.
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 9827bd3ff4f1ba..c71ba4d71efaf5 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -479,25 +479,25 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
 
   // Default implementation based on some magic section names.
   if (Name == ".bss" ||
-      Name.startswith(".bss.") ||
-      Name.startswith(".gnu.linkonce.b.") ||
-      Name.startswith(".llvm.linkonce.b.") ||
+      Name.starts_with(".bss.") ||
+      Name.starts_with(".gnu.linkonce.b.") ||
+      Name.starts_with(".llvm.linkonce.b.") ||
       Name == ".sbss" ||
-      Name.startswith(".sbss.") ||
-      Name.startswith(".gnu.linkonce.sb.") ||
-      Name.startswith(".llvm.linkonce.sb."))
+      Name.starts_with(".sbss.") ||
+      Name.starts_with(".gnu.linkonce.sb.") ||
+      Name.starts_with(".llvm.linkonce.sb."))
     return SectionKind::getBSS();
 
   if (Name == ".tdata" ||
-      Name.startswith(".tdata.") ||
-      Name.startswith(".gnu.linkonce.td.") ||
-      Name.startswith(".llvm.linkonce.td."))
+      Name.starts_with(".tdata.") ||
+      Name.starts_with(".gnu.linkonce.td.") ||
+      Name.starts_with(".llvm.linkonce.td."))
     return SectionKind::getThreadData();
 
   if (Name == ".tbss" ||
-      Name.startswith(".tbss.") ||
-      Name.startswith(".gnu.linkonce.tb.") ||
-      Name.startswith(".llvm.linkonce.tb."))
+      Name.starts_with(".tbss.") ||
+      Name.starts_with(".gnu.linkonce.tb.") ||
+      Name.starts_with(".llvm.linkonce.tb."))
     return SectionKind::getThreadBSS();
 
   return K;
@@ -512,7 +512,7 @@ static unsigned getELFSectionType(StringRef Name, SectionKind K) {
   // Use SHT_NOTE for section whose name starts with ".note" to allow
   // emitting ELF notes from C variable declaration.
   // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77609
-  if (Name.startswith(".note"))
+  if (Name.starts_with(".note"))
     return ELF::SHT_NOTE;
 
   if (hasPrefix(Name, ".init_array"))
@@ -752,7 +752,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
       getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false);
   if (SymbolMergeable &&
       Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
-      SectionName.startswith(ImplicitSectionNameStem))
+      SectionName.star...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/74956


More information about the llvm-commits mailing list