[flang-commits] [flang] 11efcce - [flang] Use StringRef::{starts, ends}_with (NFC)
Kazu Hirata via flang-commits
flang-commits at lists.llvm.org
Wed Dec 13 23:48:59 PST 2023
Author: Kazu Hirata
Date: 2023-12-13T23:48:53-08:00
New Revision: 11efccea8f96c64b893d527523b2bfe8b0734ebd
URL: https://github.com/llvm/llvm-project/commit/11efccea8f96c64b893d527523b2bfe8b0734ebd
DIFF: https://github.com/llvm/llvm-project/commit/11efccea8f96c64b893d527523b2bfe8b0734ebd.diff
LOG: [flang] Use StringRef::{starts,ends}_with (NFC)
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.
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIRType.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/lib/Lower/PFTBuilder.cpp
flang/lib/Optimizer/Builder/IntrinsicCall.cpp
flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
flang/lib/Optimizer/Support/InternalNames.cpp
flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
flang/lib/Parser/source.cpp
flang/tools/flang-driver/driver.cpp
flang/unittests/Frontend/CompilerInstanceTest.cpp
flang/unittests/Frontend/FrontendActionTest.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index 2abcc6547bbabf..a79c67dfe6de86 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -118,8 +118,8 @@ inline bool isa_derived(mlir::Type t) { return t.isa<fir::RecordType>(); }
/// Is `t` type(c_ptr) or type(c_funptr)?
inline bool isa_builtin_cptr_type(mlir::Type t) {
if (auto recTy = t.dyn_cast_or_null<fir::RecordType>())
- return recTy.getName().endswith("T__builtin_c_ptr") ||
- recTy.getName().endswith("T__builtin_c_funptr");
+ return recTy.getName().ends_with("T__builtin_c_ptr") ||
+ recTy.getName().ends_with("T__builtin_c_funptr");
return false;
}
diff --git a/flang/lib/Frontend/CompilerInstance.cpp b/flang/lib/Frontend/CompilerInstance.cpp
index a6b8f1a9d29ee4..555ac91f6dc7c0 100644
--- a/flang/lib/Frontend/CompilerInstance.cpp
+++ b/flang/lib/Frontend/CompilerInstance.cpp
@@ -257,7 +257,7 @@ getExplicitAndImplicitNVPTXTargetFeatures(clang::DiagnosticsEngine &diags,
llvm::StringRef userKeyString(llvm::StringRef(userFeature).drop_front(1));
implicitFeaturesMap[userKeyString.str()] = (userFeature[0] == '+');
// Check if the user provided a PTX version
- if (userKeyString.startswith("ptx"))
+ if (userKeyString.starts_with("ptx"))
ptxVer = true;
}
diff --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index bc09dec17b7ae3..4cad640562c619 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -131,7 +131,7 @@ updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng,
// Check to see if this opt starts with "no-", if so, this is a
// negative form of the option.
- bool isPositive = !remarkOpt.startswith("no-");
+ bool isPositive = !remarkOpt.starts_with("no-");
if (!isPositive)
remarkOpt = remarkOpt.substr(3);
diff --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index 32ed539c775b82..8e224c17edad19 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -149,22 +149,22 @@ class PFTBuilder {
// Modules IEEE_FEATURES, IEEE_EXCEPTIONS, and IEEE_ARITHMETIC get common
// declarations from several __fortran_... support module files.
llvm::StringRef modName = toStringRef(modSym.name());
- if (!modName.startswith("ieee_") && !modName.startswith("__fortran_"))
+ if (!modName.starts_with("ieee_") && !modName.starts_with("__fortran_"))
return;
llvm::StringRef procName = toStringRef(procSym.name());
- if (!procName.startswith("ieee_"))
+ if (!procName.starts_with("ieee_"))
return;
lower::pft::FunctionLikeUnit *proc =
evaluationListStack.back()->back().getOwningProcedure();
proc->hasIeeeAccess = true;
- if (!procName.startswith("ieee_set_"))
+ if (!procName.starts_with("ieee_set_"))
return;
- if (procName.startswith("ieee_set_modes_") ||
- procName.startswith("ieee_set_status_"))
+ if (procName.starts_with("ieee_set_modes_") ||
+ procName.starts_with("ieee_set_status_"))
proc->mayModifyHaltingMode = proc->mayModifyRoundingMode = true;
- else if (procName.startswith("ieee_set_halting_mode_"))
+ else if (procName.starts_with("ieee_set_halting_mode_"))
proc->mayModifyHaltingMode = true;
- else if (procName.startswith("ieee_set_rounding_mode_"))
+ else if (procName.starts_with("ieee_set_rounding_mode_"))
proc->mayModifyRoundingMode = true;
}
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 45c75fc5dd28bc..ff5dbff04360a0 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -1418,13 +1418,13 @@ mlir::Value toValue(const fir::ExtendedValue &val, fir::FirOpBuilder &builder,
//===----------------------------------------------------------------------===//
static bool isIntrinsicModuleProcedure(llvm::StringRef name) {
- return name.startswith("c_") || name.startswith("compiler_") ||
- name.startswith("ieee_") || name.startswith("__ppc_");
+ return name.starts_with("c_") || name.starts_with("compiler_") ||
+ name.starts_with("ieee_") || name.starts_with("__ppc_");
}
static bool isCoarrayIntrinsic(llvm::StringRef name) {
- return name.startswith("atomic_") || name.startswith("co_") ||
- name.contains("image") || name.endswith("cobound") ||
+ return name.starts_with("atomic_") || name.starts_with("co_") ||
+ name.contains("image") || name.ends_with("cobound") ||
name.equals("team_number");
}
@@ -1433,7 +1433,7 @@ static bool isCoarrayIntrinsic(llvm::StringRef name) {
/// {_[ail]?[0-9]+}*, such as _1 or _a4.
llvm::StringRef genericName(llvm::StringRef specificName) {
const std::string builtin = "__builtin_";
- llvm::StringRef name = specificName.startswith(builtin)
+ llvm::StringRef name = specificName.starts_with(builtin)
? specificName.drop_front(builtin.size())
: specificName;
size_t size = name.size();
diff --git a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
index c71e3939dc31d2..bcb112186aeefa 100644
--- a/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
+++ b/flang/lib/Optimizer/Dialect/Support/KindMapping.cpp
@@ -180,7 +180,7 @@ static MatchResult parseInt(unsigned &result, const char *&ptr,
static mlir::LogicalResult matchString(const char *&ptr, const char *endPtr,
llvm::StringRef literal) {
llvm::StringRef s(ptr, endPtr - ptr);
- if (s.startswith(literal)) {
+ if (s.starts_with(literal)) {
ptr += literal.size();
return mlir::success();
}
diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp
index 6138c1f425d62c..d99245f0a012e6 100644
--- a/flang/lib/Optimizer/Support/InternalNames.cpp
+++ b/flang/lib/Optimizer/Support/InternalNames.cpp
@@ -240,7 +240,7 @@ llvm::StringRef fir::NameUniquer::doProgramEntry() {
std::pair<fir::NameUniquer::NameKind, fir::NameUniquer::DeconstructedName>
fir::NameUniquer::deconstruct(llvm::StringRef uniq) {
- if (uniq.startswith("_Q")) {
+ if (uniq.starts_with("_Q")) {
llvm::SmallVector<std::string> modules;
llvm::SmallVector<std::string> procs;
std::int64_t blockId = 0;
diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index 3eddb9e61ae3b3..8ecf7fb44f15d0 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -1279,11 +1279,11 @@ void SimplifyIntrinsicsPass::runOnOperation() {
// RTNAME(Sum<T>)(const Descriptor &x, const char *source, int line,
// int dim, const Descriptor *mask)
//
- if (funcName.startswith(RTNAME_STRING(Sum))) {
+ if (funcName.starts_with(RTNAME_STRING(Sum))) {
simplifyIntOrFloatReduction(call, kindMap, genRuntimeSumBody);
return;
}
- if (funcName.startswith(RTNAME_STRING(DotProduct))) {
+ if (funcName.starts_with(RTNAME_STRING(DotProduct))) {
LLVM_DEBUG(llvm::dbgs() << "Handling " << funcName << "\n");
LLVM_DEBUG(llvm::dbgs() << "Call operation:\n"; op->dump();
llvm::dbgs() << "\n");
@@ -1350,23 +1350,23 @@ void SimplifyIntrinsicsPass::runOnOperation() {
llvm::dbgs() << "\n");
return;
}
- if (funcName.startswith(RTNAME_STRING(Maxval))) {
+ if (funcName.starts_with(RTNAME_STRING(Maxval))) {
simplifyIntOrFloatReduction(call, kindMap, genRuntimeMaxvalBody);
return;
}
- if (funcName.startswith(RTNAME_STRING(Count))) {
+ if (funcName.starts_with(RTNAME_STRING(Count))) {
simplifyLogicalDim0Reduction(call, kindMap, genRuntimeCountBody);
return;
}
- if (funcName.startswith(RTNAME_STRING(Any))) {
+ if (funcName.starts_with(RTNAME_STRING(Any))) {
simplifyLogicalDim1Reduction(call, kindMap, genRuntimeAnyBody);
return;
}
- if (funcName.endswith(RTNAME_STRING(All))) {
+ if (funcName.ends_with(RTNAME_STRING(All))) {
simplifyLogicalDim1Reduction(call, kindMap, genRuntimeAllBody);
return;
}
- if (funcName.startswith(RTNAME_STRING(Minloc))) {
+ if (funcName.starts_with(RTNAME_STRING(Minloc))) {
simplifyMinlocReduction(call, kindMap);
return;
}
diff --git a/flang/lib/Parser/source.cpp b/flang/lib/Parser/source.cpp
index d0fe399424e139..4b4fed64a1a40a 100644
--- a/flang/lib/Parser/source.cpp
+++ b/flang/lib/Parser/source.cpp
@@ -46,7 +46,7 @@ void SourceFile::RecordLineStarts() {
void SourceFile::IdentifyPayload() {
llvm::StringRef content{buf_->getBufferStart(), buf_->getBufferSize()};
constexpr llvm::StringLiteral UTF8_BOM{"\xef\xbb\xbf"};
- if (content.startswith(UTF8_BOM)) {
+ if (content.starts_with(UTF8_BOM)) {
bom_end_ = UTF8_BOM.size();
encoding_ = Encoding::UTF_8;
}
diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 99fa66b0dc8e26..c4e56a862c8613 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -99,13 +99,13 @@ int main(int argc, const char **argv) {
auto firstArg = std::find_if(args.begin() + 1, args.end(),
[](const char *a) { return a != nullptr; });
if (firstArg != args.end()) {
- if (llvm::StringRef(args[1]).startswith("-cc1")) {
+ if (llvm::StringRef(args[1]).starts_with("-cc1")) {
llvm::errs() << "error: unknown integrated tool '" << args[1] << "'. "
<< "Valid tools include '-fc1'.\n";
return 1;
}
// Call flang-new frontend
- if (llvm::StringRef(args[1]).startswith("-fc1")) {
+ if (llvm::StringRef(args[1]).starts_with("-fc1")) {
return executeFC1Tool(args);
}
}
diff --git a/flang/unittests/Frontend/CompilerInstanceTest.cpp b/flang/unittests/Frontend/CompilerInstanceTest.cpp
index 6dbbf9b4e1bbd3..35f1ec1748a3f6 100644
--- a/flang/unittests/Frontend/CompilerInstanceTest.cpp
+++ b/flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -55,7 +55,7 @@ TEST(CompilerInstance, SanityCheckForFileManager) {
llvm::ArrayRef<char> fileContent = sf->content();
EXPECT_FALSE(fileContent.size() == 0);
EXPECT_TRUE(
- llvm::StringRef(fileContent.data()).startswith("InputSourceFile"));
+ llvm::StringRef(fileContent.data()).starts_with("InputSourceFile"));
// 4. Delete the test file
ec = llvm::sys::fs::remove(inputFile);
diff --git a/flang/unittests/Frontend/FrontendActionTest.cpp b/flang/unittests/Frontend/FrontendActionTest.cpp
index d57154cb1001c7..6ec15832d96d3c 100644
--- a/flang/unittests/Frontend/FrontendActionTest.cpp
+++ b/flang/unittests/Frontend/FrontendActionTest.cpp
@@ -112,7 +112,7 @@ TEST_F(FrontendActionTest, TestInputOutput) {
EXPECT_TRUE(success);
EXPECT_TRUE(!outputFileBuffer.empty());
EXPECT_TRUE(llvm::StringRef(outputFileBuffer.data())
- .startswith("End Program arithmetic"));
+ .starts_with("End Program arithmetic"));
}
TEST_F(FrontendActionTest, PrintPreprocessedInput) {
@@ -143,7 +143,7 @@ TEST_F(FrontendActionTest, PrintPreprocessedInput) {
EXPECT_TRUE(success);
EXPECT_TRUE(!outputFileBuffer.empty());
EXPECT_TRUE(
- llvm::StringRef(outputFileBuffer.data()).startswith("program b\n"));
+ llvm::StringRef(outputFileBuffer.data()).starts_with("program b\n"));
}
TEST_F(FrontendActionTest, ParseSyntaxOnly) {
More information about the flang-commits
mailing list