[clang] [clang] Use StringRef::{starts,ends}_with (NFC) (PR #75149)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 12 00:16:54 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-backend-amdgpu
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 202.92 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75149.diff
155 Files Affected:
- (modified) clang/include/clang/Basic/Attr.td (+3-3)
- (modified) clang/include/clang/Basic/IdentifierTable.h (+1-1)
- (modified) clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (+2-2)
- (modified) clang/lib/APINotes/APINotesManager.cpp (+1-1)
- (modified) clang/lib/APINotes/APINotesYAMLCompiler.cpp (+1-1)
- (modified) clang/lib/ARCMigrate/ARCMT.cpp (+1-1)
- (modified) clang/lib/ARCMigrate/ObjCMT.cpp (+7-7)
- (modified) clang/lib/ARCMigrate/TransUnbridgedCasts.cpp (+1-1)
- (modified) clang/lib/ARCMigrate/TransformActions.cpp (+1-1)
- (modified) clang/lib/ARCMigrate/Transforms.cpp (+1-1)
- (modified) clang/lib/AST/ASTContext.cpp (+2-2)
- (modified) clang/lib/AST/DeclPrinter.cpp (+1-1)
- (modified) clang/lib/AST/Mangle.cpp (+1-1)
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+1-1)
- (modified) clang/lib/AST/PrintfFormatString.cpp (+1-1)
- (modified) clang/lib/AST/RawCommentList.cpp (+2-2)
- (modified) clang/lib/AST/Stmt.cpp (+4-3)
- (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (+6-6)
- (modified) clang/lib/ASTMatchers/Dynamic/Parser.cpp (+3-3)
- (modified) clang/lib/Analysis/BodyFarm.cpp (+2-2)
- (modified) clang/lib/Analysis/CallGraph.cpp (+1-1)
- (modified) clang/lib/Analysis/CalledOnceCheck.cpp (+1-1)
- (modified) clang/lib/Analysis/CocoaConventions.cpp (+5-6)
- (modified) clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp (+1-1)
- (modified) clang/lib/Analysis/RetainSummaryManager.cpp (+7-7)
- (modified) clang/lib/Basic/Attributes.cpp (+3-3)
- (modified) clang/lib/Basic/DiagnosticIDs.cpp (+1-1)
- (modified) clang/lib/Basic/IdentifierTable.cpp (+2-2)
- (modified) clang/lib/Basic/Module.cpp (+2-1)
- (modified) clang/lib/Basic/Sarif.cpp (+1-1)
- (modified) clang/lib/Basic/TargetInfo.cpp (+5-5)
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+8-8)
- (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+1-1)
- (modified) clang/lib/Basic/Targets/Mips.cpp (+1-1)
- (modified) clang/lib/Basic/Targets/NVPTX.cpp (+1-1)
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+4-4)
- (modified) clang/lib/Basic/Warnings.cpp (+4-4)
- (modified) clang/lib/CodeGen/CGCall.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+4-3)
- (modified) clang/lib/CodeGen/CGException.cpp (+3-3)
- (modified) clang/lib/CodeGen/CGExpr.cpp (+2-2)
- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+2-2)
- (modified) clang/lib/CodeGen/CGRecordLayoutBuilder.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGStmt.cpp (+1-1)
- (modified) clang/lib/CodeGen/CodeGenAction.cpp (+1-1)
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+8-8)
- (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+3-3)
- (modified) clang/lib/Driver/Distro.cpp (+6-6)
- (modified) clang/lib/Driver/Driver.cpp (+11-11)
- (modified) clang/lib/Driver/Job.cpp (+4-4)
- (modified) clang/lib/Driver/ToolChain.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/AIX.cpp (+3-3)
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+9-9)
- (modified) clang/lib/Driver/ToolChains/Arch/AArch64.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+9-9)
- (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (+5-5)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+43-43)
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+8-8)
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+16-15)
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+3-3)
- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+4-4)
- (modified) clang/lib/Driver/ToolChains/Hurd.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/MSP430.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/MSVC.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+3-3)
- (modified) clang/lib/Driver/ToolChains/PPCLinux.cpp (+2-2)
- (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+1-1)
- (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+2-2)
- (modified) clang/lib/Edit/Commit.cpp (+1-1)
- (modified) clang/lib/Edit/RewriteObjCFoundationAPI.cpp (+3-3)
- (modified) clang/lib/ExtractAPI/ExtractAPIConsumer.cpp (+2-2)
- (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp (+1-1)
- (modified) clang/lib/Format/BreakableToken.cpp (+22-22)
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+18-15)
- (modified) clang/lib/Format/Format.cpp (+13-13)
- (modified) clang/lib/Format/FormatToken.h (+5-5)
- (modified) clang/lib/Format/FormatTokenLexer.cpp (+4-4)
- (modified) clang/lib/Format/SortJavaScriptImports.cpp (+2-2)
- (modified) clang/lib/Format/TokenAnnotator.cpp (+10-10)
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+5-5)
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+8-8)
- (modified) clang/lib/Frontend/DependencyGraph.cpp (+1-1)
- (modified) clang/lib/Frontend/Rewrite/InclusionRewriter.cpp (+1-1)
- (modified) clang/lib/Frontend/VerifyDiagnosticConsumer.cpp (+10-11)
- (modified) clang/lib/Index/IndexSymbol.cpp (+1-1)
- (modified) clang/lib/IndexSerialization/SerializablePathCollection.cpp (+2-2)
- (modified) clang/lib/Lex/HeaderSearch.cpp (+5-5)
- (modified) clang/lib/Lex/InitHeaderSearch.cpp (+2-2)
- (modified) clang/lib/Lex/Lexer.cpp (+2-2)
- (modified) clang/lib/Lex/ModuleMap.cpp (+6-6)
- (modified) clang/lib/Lex/PPDirectives.cpp (+6-6)
- (modified) clang/lib/Lex/PPExpressions.cpp (+1-1)
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+6-5)
- (modified) clang/lib/Parse/ParseDecl.cpp (+2-2)
- (modified) clang/lib/Parse/Parser.cpp (+1-1)
- (modified) clang/lib/Rewrite/Rewriter.cpp (+2-2)
- (modified) clang/lib/Sema/CodeCompleteConsumer.cpp (+6-5)
- (modified) clang/lib/Sema/SemaChecking.cpp (+5-6)
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+2-2)
- (modified) clang/lib/Sema/SemaDecl.cpp (+2-2)
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+8-8)
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (+1-1)
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-7)
- (modified) clang/lib/Sema/SemaModule.cpp (+1-1)
- (modified) clang/lib/Sema/SemaType.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp (+2-2)
- (modified) clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp (+2-2)
- (modified) clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Checkers/GCDAntipatternChecker.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (+3-3)
- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+5-5)
- (modified) clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp (+2-2)
- (modified) clang/lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+9-11)
- (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/CallEvent.cpp (+3-3)
- (modified) clang/lib/StaticAnalyzer/Core/CheckerContext.cpp (+3-2)
- (modified) clang/lib/StaticAnalyzer/Core/CheckerRegistryData.cpp (+3-3)
- (modified) clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Frontend/CheckerRegistry.cpp (+2-2)
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+1-1)
- (modified) clang/lib/Tooling/ASTDiff/ASTDiff.cpp (+1-1)
- (modified) clang/lib/Tooling/ArgumentsAdjusters.cpp (+7-7)
- (modified) clang/lib/Tooling/CompilationDatabase.cpp (+1-1)
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp (+2-2)
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+2-2)
- (modified) clang/lib/Tooling/Inclusions/HeaderAnalysis.cpp (+3-3)
- (modified) clang/lib/Tooling/Inclusions/HeaderIncludes.cpp (+9-9)
- (modified) clang/lib/Tooling/Refactoring/AtomicChange.cpp (+1-1)
- (modified) clang/lib/Tooling/Refactoring/Lookup.cpp (+7-7)
- (modified) clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp (+4-4)
- (modified) clang/lib/Tooling/Tooling.cpp (+4-4)
- (modified) clang/lib/Tooling/Transformer/SourceCode.cpp (+1-1)
- (modified) clang/tools/arcmt-test/arcmt-test.cpp (+1-1)
- (modified) clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp (+1-1)
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2-2)
- (modified) clang/tools/clang-refactor/ClangRefactor.cpp (+1-1)
- (modified) clang/tools/clang-repl/ClangRepl.cpp (+1-1)
- (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+2-2)
- (modified) clang/tools/diagtool/TreeView.cpp (+1-1)
- (modified) clang/tools/driver/driver.cpp (+2-2)
- (modified) clang/tools/libclang/CIndexUSRs.cpp (+1-1)
- (modified) clang/unittests/Analysis/CloneDetectionTest.cpp (+1-1)
- (modified) clang/unittests/Driver/ModuleCacheTest.cpp (+1-1)
- (modified) clang/unittests/Driver/MultilibBuilderTest.cpp (+2-2)
- (modified) clang/unittests/Driver/ToolChainTest.cpp (+1-1)
- (modified) clang/unittests/Frontend/OutputStreamTest.cpp (+1-1)
- (modified) clang/unittests/Interpreter/IncrementalProcessingTest.cpp (+1-1)
- (modified) clang/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp (+2-2)
- (modified) clang/unittests/Tooling/HeaderIncludesTest.cpp (+6-5)
- (modified) clang/unittests/libclang/LibclangTest.cpp (+3-3)
- (modified) clang/utils/TableGen/ASTTableGen.cpp (+1-1)
- (modified) clang/utils/TableGen/MveEmitter.cpp (+4-4)
``````````diff
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 0d94ea2851c9ab..c8b17cbe8ab7e7 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2878,7 +2878,7 @@ def Target : InheritableAttr {
for (auto &Feature : AttrFeatures) {
Feature = Feature.trim();
- if (Feature.startswith("arch="))
+ if (Feature.starts_with("arch="))
return Feature.drop_front(sizeof("arch=") - 1);
}
return "";
@@ -2896,8 +2896,8 @@ def Target : InheritableAttr {
for (auto &Feature : AttrFeatures) {
Feature = Feature.trim();
- if (!Feature.startswith("no-") && !Feature.startswith("arch=") &&
- !Feature.startswith("fpmath=") && !Feature.startswith("tune="))
+ if (!Feature.starts_with("no-") && !Feature.starts_with("arch=") &&
+ !Feature.starts_with("fpmath=") && !Feature.starts_with("tune="))
Out.push_back(Feature);
}
}
diff --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h
index 0898e7d39dd7de..1ac182d4fce26f 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -511,7 +511,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
/// function(<#int x#>);
/// \endcode
bool isEditorPlaceholder() const {
- return getName().startswith("<#") && getName().endswith("#>");
+ return getName().starts_with("<#") && getName().ends_with("#>");
}
/// Determine whether \p this is a name reserved for the implementation (C99
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index a947bd0867025c..276d11e80a5b21 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -409,8 +409,8 @@ AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental) {
};
std::vector<StringRef> Checkers;
for (StringRef CheckerName : StaticAnalyzerCheckerNames) {
- if (!CheckerName.startswith("debug.") &&
- (IncludeExperimental || !CheckerName.startswith("alpha.")))
+ if (!CheckerName.starts_with("debug.") &&
+ (IncludeExperimental || !CheckerName.starts_with("alpha.")))
Checkers.push_back(CheckerName);
}
return Checkers;
diff --git a/clang/lib/APINotes/APINotesManager.cpp b/clang/lib/APINotes/APINotesManager.cpp
index ec1fb3ffa961c9..a921c8b9fce3e0 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -198,7 +198,7 @@ static void checkPrivateAPINotesName(DiagnosticsEngine &Diags,
StringRef RealFileName =
llvm::sys::path::filename(File->tryGetRealPathName());
StringRef RealStem = llvm::sys::path::stem(RealFileName);
- if (RealStem.endswith("_private"))
+ if (RealStem.ends_with("_private"))
return;
unsigned DiagID = diag::warn_apinotes_private_case;
diff --git a/clang/lib/APINotes/APINotesYAMLCompiler.cpp b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
index 4dfd01dae05f2c..57d6da7a177596 100644
--- a/clang/lib/APINotes/APINotesYAMLCompiler.cpp
+++ b/clang/lib/APINotes/APINotesYAMLCompiler.cpp
@@ -745,7 +745,7 @@ class YAMLConverter {
convertCommonEntity(M, MI, M.Selector);
// Check if the selector ends with ':' to determine if it takes arguments.
- bool takesArguments = M.Selector.endswith(":");
+ bool takesArguments = M.Selector.ends_with(":");
// Split the selector into pieces.
llvm::SmallVector<StringRef, 4> Args;
diff --git a/clang/lib/ARCMigrate/ARCMT.cpp b/clang/lib/ARCMigrate/ARCMT.cpp
index 8e398977dcd65d..b410d5f3b42a7e 100644
--- a/clang/lib/ARCMigrate/ARCMT.cpp
+++ b/clang/lib/ARCMigrate/ARCMT.cpp
@@ -201,7 +201,7 @@ createInvocationForMigration(CompilerInvocation &origCI,
for (std::vector<std::string>::iterator
I = CInvok->getDiagnosticOpts().Warnings.begin(),
E = CInvok->getDiagnosticOpts().Warnings.end(); I != E; ++I) {
- if (!StringRef(*I).startswith("error"))
+ if (!StringRef(*I).starts_with("error"))
WarnOpts.push_back(*I);
}
WarnOpts.push_back("error=arc-unsafe-retained-assign");
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index 5a25c88c65f64b..ed363a46a20044 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -562,7 +562,7 @@ static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
static bool IsCategoryNameWithDeprecatedSuffix(ObjCContainerDecl *D) {
if (ObjCCategoryDecl *CatDecl = dyn_cast<ObjCCategoryDecl>(D)) {
StringRef Name = CatDecl->getName();
- return Name.endswith("Deprecated");
+ return Name.ends_with("Deprecated");
}
return false;
}
@@ -1176,12 +1176,12 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
if (!SetterMethod) {
// try a different naming convention for getter: isXxxxx
StringRef getterNameString = getterName->getName();
- bool IsPrefix = getterNameString.startswith("is");
+ bool IsPrefix = getterNameString.starts_with("is");
// Note that we don't want to change an isXXX method of retainable object
// type to property (readonly or otherwise).
if (IsPrefix && GRT->isObjCRetainableType())
return false;
- if (IsPrefix || getterNameString.startswith("get")) {
+ if (IsPrefix || getterNameString.starts_with("get")) {
LengthOfPrefix = (IsPrefix ? 2 : 3);
const char *CGetterName = getterNameString.data() + LengthOfPrefix;
// Make sure that first character after "is" or "get" prefix can
@@ -1320,11 +1320,11 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
if (OIT_Family == OIT_Singleton || OIT_Family == OIT_ReturnsSelf) {
StringRef STRefMethodName(MethodName);
size_t len = 0;
- if (STRefMethodName.startswith("standard"))
+ if (STRefMethodName.starts_with("standard"))
len = strlen("standard");
- else if (STRefMethodName.startswith("shared"))
+ else if (STRefMethodName.starts_with("shared"))
len = strlen("shared");
- else if (STRefMethodName.startswith("default"))
+ else if (STRefMethodName.starts_with("default"))
len = strlen("default");
else
return;
@@ -1341,7 +1341,7 @@ void ObjCMigrateASTConsumer::migrateFactoryMethod(ASTContext &Ctx,
StringRef LoweredMethodName(MethodName);
std::string StringLoweredMethodName = LoweredMethodName.lower();
LoweredMethodName = StringLoweredMethodName;
- if (!LoweredMethodName.startswith(ClassNamePostfix))
+ if (!LoweredMethodName.starts_with(ClassNamePostfix))
return;
if (OIT_Family == OIT_ReturnsSelf)
ReplaceWithClasstype(*this, OM);
diff --git a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
index 40220a2eef4910..1e6354f71e294a 100644
--- a/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
+++ b/clang/lib/ARCMigrate/TransUnbridgedCasts.cpp
@@ -146,7 +146,7 @@ class UnbridgedCastRewriter : public RecursiveASTVisitor<UnbridgedCastRewriter>{
ento::cocoa::isRefType(E->getSubExpr()->getType(), "CF",
FD->getIdentifier()->getName())) {
StringRef fname = FD->getIdentifier()->getName();
- if (fname.endswith("Retain") || fname.contains("Create") ||
+ if (fname.ends_with("Retain") || fname.contains("Create") ||
fname.contains("Copy")) {
// Do not migrate to couple of bridge transfer casts which
// cancel each other out. Leave it unchanged so error gets user
diff --git a/clang/lib/ARCMigrate/TransformActions.cpp b/clang/lib/ARCMigrate/TransformActions.cpp
index bd5c793568671d..6bc6fed1a90320 100644
--- a/clang/lib/ARCMigrate/TransformActions.cpp
+++ b/clang/lib/ARCMigrate/TransformActions.cpp
@@ -431,7 +431,7 @@ bool TransformActionsImpl::canReplaceText(SourceLocation loc, StringRef text) {
if (invalidTemp)
return false;
- return file.substr(locInfo.second).startswith(text);
+ return file.substr(locInfo.second).starts_with(text);
}
void TransformActionsImpl::commitInsert(SourceLocation loc, StringRef text) {
diff --git a/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp
index 90b2b32b6b1be2..2808e35135dc35 100644
--- a/clang/lib/ARCMigrate/Transforms.cpp
+++ b/clang/lib/ARCMigrate/Transforms.cpp
@@ -95,7 +95,7 @@ bool trans::isPlusOne(const Expr *E) {
ento::cocoa::isRefType(callE->getType(), "CF",
FD->getIdentifier()->getName())) {
StringRef fname = FD->getIdentifier()->getName();
- if (fname.endswith("Retain") || fname.contains("Create") ||
+ if (fname.ends_with("Retain") || fname.contains("Create") ||
fname.contains("Copy"))
return true;
}
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e877f903b34c6b..0395b3e47ab6f8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -8223,7 +8223,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string &S,
// Another legacy compatibility encoding. Some ObjC qualifier and type
// combinations need to be rearranged.
// Rewrite "in const" from "nr" to "rn"
- if (StringRef(S).endswith("nr"))
+ if (StringRef(S).ends_with("nr"))
S.replace(S.end()-2, S.end(), "rn");
}
@@ -13519,7 +13519,7 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
Target->getTargetOpts().FeaturesAsWritten.begin(),
Target->getTargetOpts().FeaturesAsWritten.end());
} else {
- if (VersionStr.startswith("arch="))
+ if (VersionStr.starts_with("arch="))
TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
else if (VersionStr != "default")
Features.push_back((StringRef{"+"} + VersionStr).str());
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 30a26d518386c5..24da6f2ef32b4f 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1728,7 +1728,7 @@ void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
std::string TypeStr = PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
getAsString(Policy);
Out << ' ' << TypeStr;
- if (!StringRef(TypeStr).endswith("*"))
+ if (!StringRef(TypeStr).ends_with("*"))
Out << ' ';
Out << *PDecl;
if (Policy.PolishForDeclaration)
diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 64c971912a91d0..d3a6b61fd2bec9 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -147,7 +147,7 @@ void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
// If the label isn't literal, or if this is an alias for an LLVM intrinsic,
// do not add a "\01" prefix.
- if (!ALA->getIsLiteralLabel() || ALA->getLabel().startswith("llvm.")) {
+ if (!ALA->getIsLiteralLabel() || ALA->getLabel().starts_with("llvm.")) {
Out << ALA->getLabel();
return;
}
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index c59a66e103a6e3..8346ad87b409b6 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -63,7 +63,7 @@ struct msvc_hashing_ostream : public llvm::raw_svector_ostream {
: llvm::raw_svector_ostream(Buffer), OS(OS) {}
~msvc_hashing_ostream() override {
StringRef MangledName = str();
- bool StartsWithEscape = MangledName.startswith("\01");
+ bool StartsWithEscape = MangledName.starts_with("\01");
if (StartsWithEscape)
MangledName = MangledName.drop_front(1);
if (MangledName.size() < 4096) {
diff --git a/clang/lib/AST/PrintfFormatString.cpp b/clang/lib/AST/PrintfFormatString.cpp
index f0b9d0ecaf2346..3b09ca40bd2a53 100644
--- a/clang/lib/AST/PrintfFormatString.cpp
+++ b/clang/lib/AST/PrintfFormatString.cpp
@@ -140,7 +140,7 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H,
// Set the privacy flag if the privacy annotation in the
// comma-delimited segment is at least as strict as the privacy
// annotations in previous comma-delimited segments.
- if (MatchedStr.startswith("mask")) {
+ if (MatchedStr.starts_with("mask")) {
StringRef MaskType = MatchedStr.substr(sizeof("mask.") - 1);
unsigned Size = MaskType.size();
if (Warn && (Size == 0 || Size > 8))
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index c3beb23228887a..dffa007b6588bc 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -141,8 +141,8 @@ RawComment::RawComment(const SourceManager &SourceMgr, SourceRange SR,
Kind = K.first;
IsTrailingComment |= K.second;
- IsAlmostTrailingComment = RawText.startswith("//<") ||
- RawText.startswith("/*<");
+ IsAlmostTrailingComment =
+ RawText.starts_with("//<") || RawText.starts_with("/*<");
} else {
Kind = RCK_Merged;
IsTrailingComment =
diff --git a/clang/lib/AST/Stmt.cpp b/clang/lib/AST/Stmt.cpp
index c31fb48a2addfa..afd05881cb1621 100644
--- a/clang/lib/AST/Stmt.cpp
+++ b/clang/lib/AST/Stmt.cpp
@@ -811,11 +811,12 @@ std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
StringRef Instruction = Pieces[I];
// For vex/vex2/vex3/evex masm style prefix, convert it to att style
// since we don't support masm style prefix in backend.
- if (Instruction.startswith("vex "))
+ if (Instruction.starts_with("vex "))
MSAsmString += '{' + Instruction.substr(0, 3).str() + '}' +
Instruction.substr(3).str();
- else if (Instruction.startswith("vex2 ") ||
- Instruction.startswith("vex3 ") || Instruction.startswith("evex "))
+ else if (Instruction.starts_with("vex2 ") ||
+ Instruction.starts_with("vex3 ") ||
+ Instruction.starts_with("evex "))
MSAsmString += '{' + Instruction.substr(0, 4).str() + '}' +
Instruction.substr(4).str();
else
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 435bbdeda22066..8ed213ca2ce096 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -480,11 +480,11 @@ HasNameMatcher::HasNameMatcher(std::vector<std::string> N)
static bool consumeNameSuffix(StringRef &FullName, StringRef Suffix) {
StringRef Name = FullName;
- if (!Name.endswith(Suffix))
+ if (!Name.ends_with(Suffix))
return false;
Name = Name.drop_back(Suffix.size());
if (!Name.empty()) {
- if (!Name.endswith("::"))
+ if (!Name.ends_with("::"))
return false;
Name = Name.drop_back(2);
}
@@ -530,7 +530,7 @@ class PatternSet {
PatternSet(ArrayRef<std::string> Names) {
Patterns.reserve(Names.size());
for (StringRef Name : Names)
- Patterns.push_back({Name, Name.startswith("::")});
+ Patterns.push_back({Name, Name.starts_with("::")});
}
/// Consumes the name suffix from each pattern in the set and removes the ones
@@ -652,11 +652,11 @@ bool HasNameMatcher::matchesNodeFullSlow(const NamedDecl &Node) const {
const StringRef FullName = OS.str();
for (const StringRef Pattern : Names) {
- if (Pattern.startswith("::")) {
+ if (Pattern.starts_with("::")) {
if (FullName == Pattern)
return true;
- } else if (FullName.endswith(Pattern) &&
- FullName.drop_back(Pattern.size()).endswith("::")) {
+ } else if (FullName.ends_with(Pattern) &&
+ FullName.drop_back(Pattern.size()).ends_with("::")) {
return true;
}
}
diff --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 33a10fe838a6aa..27096a83b8dd60 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -187,10 +187,10 @@ class Parser::CodeTokenizer {
break;
++TokenLength;
}
- if (TokenLength == 4 && Code.startswith("true")) {
+ if (TokenLength == 4 && Code.starts_with("true")) {
Result.Kind = TokenInfo::TK_Literal;
Result.Value = true;
- } else if (TokenLength == 5 && Code.startswith("false")) {
+ } else if (TokenLength == 5 && Code.starts_with("false")) {
Result.Kind = TokenInfo::TK_Literal;
Result.Value = false;
} else {
@@ -737,7 +737,7 @@ bool Parser::parseMatcherExpressionImpl(const TokenInfo &NameToken,
// Completions minus the prefix.
void Parser::addCompletion(const TokenInfo &CompToken,
const MatcherCompletion& Completion) {
- if (StringRef(Completion.TypedText).startswith(CompToken.Text) &&
+ if (StringRef(Completion.TypedText).starts_with(CompToken.Text) &&
Completion.Specificity > 0) {
Completions.emplace_back(Completion.TypedText.substr(CompToken.Text.size()),
Completion.MatcherDecl, Completion.Specificity);
diff --git a/clang/lib/Analysis/BodyFarm.cpp b/clang/lib/Analysis/BodyFarm.cpp
index 13ec9b65c9f0b2..127e843d4ead21 100644
--- a/clang/lib/Analysis/BodyFarm.cpp
+++ b/clang/lib/Analysis/BodyFarm.cpp
@@ -726,8 +726,8 @@ Stmt *BodyFarm::getBody(const FunctionDecl *D) {
FF = nullptr;
break;
}
- } else if (Name.startswith("OSAtomicCompareAndSwap") ||
- Name.startswith("objc_atomicCompareAndSwap")) {
+ } else if (Name.starts_with("OSAtomicCompareAndSwap") ||
+ Name.starts_with("objc_atomicCompareAndSwap")) {
FF = create_OSAtomicCompareAndSwap;
} else if (Name == "call_once" && D->getDeclContext()->isStdNamespace()) {
FF = create_call_once;
diff --git a/clang/lib/Analysis/CallGraph.cpp b/clang/lib/Analysis/CallGraph.cpp
index 59cc939b6fd15e..f892980ed31386 100644
--- a/clang/lib/Analysis/CallGraph.cpp
+++ b/clang/lib/Analysis/CallGraph.cpp
@@ -168,7 +168,7 @@ bool CallGraph::includeCalleeInGraph(const Decl *D) {
return false;
IdentifierInfo *II = FD->getIdentifier();
- if (II && II->getName().startswith("__inline"))
+ if (II && II->getName().starts_with("__inline"))
return false;
}
diff --git a/clang/lib/Analysis/CalledOnceCheck.cpp b/clang/lib/Analysis/CalledOnceCheck.cpp
index 5b4fc24b6f0e2a..04c5f6aa9c7450 100644
--- a/clang/lib/Analysis/CalledOnceCheck.cpp
+++ b/clang/lib/Analysis/CalledOnceCheck.cpp
@@ -973,7 +973,7 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
/// Return true if the given name has conventional suffixes.
static bool hasConventionalSuffix(llvm::StringRef Name) {
return llvm::any_of(CONVENTIONAL_SUFFIXES, [Name](llvm::StringRef Suffix) {
- return Name.endswith(Suffix);
+ return Name.ends_with(Suffix);
});
}
diff --git a/clang/lib/Analysis/CocoaConventions.cpp b/clang/lib/Analysis/CocoaConventions.cpp
index 571d72e1a84165..836859c2234585 100644
--- a/clang/lib/Analysis/CocoaConventions.cpp
+++ b/clang/lib/Analysis/CocoaConventions.cpp
@@ -26,10 +26,10 @@ bool cocoa::isRefType(QualType RetTy, StringRef Prefix,
// Recursively walk the typedef stack, allowing typedefs of reference types.
while (const TypedefType *TD = RetTy->getAs<TypedefType>()) {
StringRef TDName = TD->getDecl()->getIdentifier()->getName();
- if (TDName.startswith(Prefix) && TDName.endswith("Ref"))
+ if (TDName.starts_with(Prefix) && TDName.ends_with("Ref"))
return true;
// XPC unfortunately uses CF-style function names, but aren't CF types.
- if (TDName.startswith("xpc_"))
+ if (TDName.starts_with("xpc_"))
return false;
RetTy = TD->getDecl()->getUnderlyingType();
}
@@ -43,7 +43,7 @@ bool cocoa::isRefType(QualType RetTy, StringRef Prefix,
return false;
// Does the name start with the prefix?
- return Name.startswith(Prefix);
+ return Name.starts_with(Prefix);
}
/// Returns true when the passed-in type is a CF-style reference-counted
@@ -127,10 +127,9 @@ bool coreFoundation::followsCreateRule(const FunctionDecl *fn) {
// Scan for *lowercase* 'reate' or 'opy', followed by no lowercase
// character...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/75149
More information about the cfe-commits
mailing list