Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/ObjCARCAnalysisUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/IndirectThunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/MIRYamlMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/MCSectionCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
14 changes: 7 additions & 7 deletions llvm/include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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>
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Passes/PassBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/SampleProf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "]";
Expand All @@ -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 << "]";
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/LoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/VFABIDemangling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/AsmParser/LLLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/BinaryFormat/Magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/GlobalMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,7 @@ 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:
Expand Down
16 changes: 8 additions & 8 deletions llvm/lib/CodeGen/MIRParser/MILexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 14 additions & 19 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,26 +478,21 @@ static SectionKind getELFKindForNamedSection(StringRef Name, SectionKind K) {
if (Name.empty() || Name[0] != '.') return 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 == ".sbss" ||
Name.startswith(".sbss.") ||
Name.startswith(".gnu.linkonce.sb.") ||
Name.startswith(".llvm.linkonce.sb."))
if (Name == ".bss" || Name.starts_with(".bss.") ||
Name.starts_with(".gnu.linkonce.b.") ||
Name.starts_with(".llvm.linkonce.b.") || Name == ".sbss" ||
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."))
if (Name == ".tdata" || 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."))
if (Name == ".tbss" || Name.starts_with(".tbss.") ||
Name.starts_with(".gnu.linkonce.tb.") ||
Name.starts_with(".llvm.linkonce.tb."))
return SectionKind::getThreadBSS();

return K;
Expand All @@ -512,7 +507,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"))
Expand Down Expand Up @@ -752,7 +747,7 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
getELFSectionNameForGlobal(GO, Kind, Mang, TM, EntrySize, false);
if (SymbolMergeable &&
Ctx.isELFImplicitMergeableSectionNamePrefix(SectionName) &&
SectionName.startswith(ImplicitSectionNameStem))
SectionName.starts_with(ImplicitSectionNameStem))
return MCContext::GenericSectionID;

// We have seen this section name before, but with different flags or entity
Expand Down Expand Up @@ -1036,7 +1031,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForMachineBasicBlock(
SmallString<128> Name;
StringRef FunctionSectionName = MBB.getParent()->getSection()->getName();
if (FunctionSectionName.equals(".text") ||
FunctionSectionName.startswith(".text.")) {
FunctionSectionName.starts_with(".text.")) {
// Function is in a regular .text section.
StringRef FunctionName = MBB.getParent()->getName();
if (MBB.getSectionID() == MBBSectionID::ColdSectionID) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/WinEHPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void llvm::calculateSEHStateForAsynchEH(const BasicBlock *BB, int State,
const Constant *FilterOrNull = cast<Constant>(
cast<CatchPadInst>(I)->getArgOperand(0)->stripPointerCasts());
const Function *Filter = dyn_cast<Function>(FilterOrNull);
if (!Filter || !Filter->getName().startswith("__IsLocalUnwind"))
if (!Filter || !Filter->getName().starts_with("__IsLocalUnwind"))
State = EHInfo.SEHUnwindMap[State].ToState; // Retrive next State
} else if ((isa<CleanupReturnInst>(TI) || isa<CatchReturnInst>(TI)) &&
State > 0) {
Expand Down
Loading