Skip to content

Commit 586ecdf

Browse files
[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)
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.
1 parent d5fb4c0 commit 586ecdf

File tree

191 files changed

+645
-655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+645
-655
lines changed

llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ inline bool IsObjCIdentifiedObject(const Value *V) {
203203
StringRef Name = GV->getName();
204204
// These special variables are known to hold values which are not
205205
// reference-counted pointers.
206-
if (Name.startswith("\01l_objc_msgSend_fixup_"))
206+
if (Name.starts_with("\01l_objc_msgSend_fixup_"))
207207
return true;
208208

209209
StringRef Section = GV->getSection();

llvm/include/llvm/CodeGen/IndirectThunks.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ template <typename Derived, typename InsertedThunksTy>
4848
void ThunkInserter<Derived, InsertedThunksTy>::createThunkFunction(
4949
MachineModuleInfo &MMI, StringRef Name, bool Comdat,
5050
StringRef TargetAttrs) {
51-
assert(Name.startswith(getDerived().getThunkPrefix()) &&
51+
assert(Name.starts_with(getDerived().getThunkPrefix()) &&
5252
"Created a thunk with an unexpected prefix!");
5353

5454
Module &M = const_cast<Module &>(*MMI.getModule());
@@ -94,7 +94,7 @@ template <typename Derived, typename InsertedThunksTy>
9494
bool ThunkInserter<Derived, InsertedThunksTy>::run(MachineModuleInfo &MMI,
9595
MachineFunction &MF) {
9696
// If MF is not a thunk, check to see if we need to insert a thunk.
97-
if (!MF.getName().startswith(getDerived().getThunkPrefix())) {
97+
if (!MF.getName().starts_with(getDerived().getThunkPrefix())) {
9898
// Only add a thunk if one of the functions has the corresponding feature
9999
// enabled in its subtarget, and doesn't enable external thunks. The target
100100
// can use InsertedThunks to detect whether relevant thunks have already

llvm/include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ template <> struct ScalarTraits<FrameIndex> {
433433
static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI) {
434434
FI.IsFixed = false;
435435
StringRef Num;
436-
if (Scalar.startswith("%stack.")) {
436+
if (Scalar.starts_with("%stack.")) {
437437
Num = Scalar.substr(7);
438-
} else if (Scalar.startswith("%fixed-stack.")) {
438+
} else if (Scalar.starts_with("%fixed-stack.")) {
439439
Num = Scalar.substr(13);
440440
FI.IsFixed = true;
441441
} else {

llvm/include/llvm/MC/MCSectionCOFF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class MCSectionCOFF final : public MCSection {
8383
}
8484

8585
static bool isImplicitlyDiscardable(StringRef Name) {
86-
return Name.startswith(".debug");
86+
return Name.starts_with(".debug");
8787
}
8888

8989
static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
742742
if (EF.getHeader().e_machine == ELF::EM_AARCH64) {
743743
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
744744
StringRef Name = *NameOrErr;
745-
if (Name.startswith("$d") || Name.startswith("$x"))
745+
if (Name.starts_with("$d") || Name.starts_with("$x"))
746746
Result |= SymbolRef::SF_FormatSpecific;
747747
} else {
748748
// TODO: Actually report errors helpfully.
@@ -752,8 +752,8 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
752752
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
753753
StringRef Name = *NameOrErr;
754754
// TODO Investigate why empty name symbols need to be marked.
755-
if (Name.empty() || Name.startswith("$d") || Name.startswith("$t") ||
756-
Name.startswith("$a"))
755+
if (Name.empty() || Name.starts_with("$d") || Name.starts_with("$t") ||
756+
Name.starts_with("$a"))
757757
Result |= SymbolRef::SF_FormatSpecific;
758758
} else {
759759
// TODO: Actually report errors helpfully.
@@ -764,7 +764,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
764764
} else if (EF.getHeader().e_machine == ELF::EM_CSKY) {
765765
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
766766
StringRef Name = *NameOrErr;
767-
if (Name.startswith("$d") || Name.startswith("$t"))
767+
if (Name.starts_with("$d") || Name.starts_with("$t"))
768768
Result |= SymbolRef::SF_FormatSpecific;
769769
} else {
770770
// TODO: Actually report errors helpfully.
@@ -775,7 +775,7 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
775775
StringRef Name = *NameOrErr;
776776
// Mark empty name symbols (used for label differences) and mapping
777777
// symbols.
778-
if (Name.empty() || Name.startswith("$d") || Name.startswith("$x"))
778+
if (Name.empty() || Name.starts_with("$d") || Name.starts_with("$x"))
779779
Result |= SymbolRef::SF_FormatSpecific;
780780
} else {
781781
// TODO: Actually report errors helpfully.
@@ -973,8 +973,8 @@ bool ELFObjectFile<ELFT>::isDebugSection(DataRefImpl Sec) const {
973973
return false;
974974
}
975975
StringRef SectionName = SectionNameOrErr.get();
976-
return SectionName.startswith(".debug") ||
977-
SectionName.startswith(".zdebug") || SectionName == ".gdb_index";
976+
return SectionName.starts_with(".debug") ||
977+
SectionName.starts_with(".zdebug") || SectionName == ".gdb_index";
978978
}
979979

980980
template <class ELFT>

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,10 @@ template <typename AnalysisT, typename IRUnitT, typename AnalysisManagerT,
720720
bool parseAnalysisUtilityPasses(
721721
StringRef AnalysisName, StringRef PipelineName,
722722
PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...> &PM) {
723-
if (!PipelineName.endswith(">"))
723+
if (!PipelineName.ends_with(">"))
724724
return false;
725725
// See if this is an invalidate<> pass name
726-
if (PipelineName.startswith("invalidate<")) {
726+
if (PipelineName.starts_with("invalidate<")) {
727727
PipelineName = PipelineName.substr(11, PipelineName.size() - 12);
728728
if (PipelineName != AnalysisName)
729729
return false;
@@ -732,7 +732,7 @@ bool parseAnalysisUtilityPasses(
732732
}
733733

734734
// See if this is a require<> pass name
735-
if (PipelineName.startswith("require<")) {
735+
if (PipelineName.starts_with("require<")) {
736736
PipelineName = PipelineName.substr(8, PipelineName.size() - 9);
737737
if (PipelineName != AnalysisName)
738738
return false;

llvm/include/llvm/ProfileData/SampleProf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class SampleContext {
548548
assert(!ContextStr.empty());
549549
// Note that `[]` wrapped input indicates a full context string, otherwise
550550
// it's treated as context-less function name only.
551-
bool HasContext = ContextStr.startswith("[");
551+
bool HasContext = ContextStr.starts_with("[");
552552
if (!HasContext) {
553553
State = UnknownContext;
554554
Func = FunctionId(ContextStr);

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ struct Attributor {
21612161
Function *F = I->getFunction();
21622162
auto &ORE = Configuration.OREGetter(F);
21632163

2164-
if (RemarkName.startswith("OMP"))
2164+
if (RemarkName.starts_with("OMP"))
21652165
ORE.emit([&]() {
21662166
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, I))
21672167
<< " [" << RemarkName << "]";
@@ -2181,7 +2181,7 @@ struct Attributor {
21812181

21822182
auto &ORE = Configuration.OREGetter(F);
21832183

2184-
if (RemarkName.startswith("OMP"))
2184+
if (RemarkName.starts_with("OMP"))
21852185
ORE.emit([&]() {
21862186
return RemarkCB(RemarkKind(Configuration.PassName, RemarkName, F))
21872187
<< " [" << RemarkName << "]";

llvm/lib/Analysis/LoopInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ MDNode *llvm::makePostTransformationMetadata(LLVMContext &Context,
11431143
if (S)
11441144
IsVectorMetadata =
11451145
llvm::any_of(RemovePrefixes, [S](StringRef Prefix) -> bool {
1146-
return S->getString().startswith(Prefix);
1146+
return S->getString().starts_with(Prefix);
11471147
});
11481148
}
11491149
if (!IsVectorMetadata)

llvm/lib/Analysis/VFABIDemangling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static ParseRet tryParseISA(StringRef &MangledName, VFISAKind &ISA) {
3232
if (MangledName.empty())
3333
return ParseRet::Error;
3434

35-
if (MangledName.startswith(VFABI::_LLVM_)) {
35+
if (MangledName.starts_with(VFABI::_LLVM_)) {
3636
MangledName = MangledName.drop_front(strlen(VFABI::_LLVM_));
3737
ISA = VFISAKind::LLVM;
3838
} else {

0 commit comments

Comments
 (0)