Skip to content

Commit 11efcce

Browse files
[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.
1 parent ad8fd5b commit 11efcce

File tree

12 files changed

+31
-31
lines changed

12 files changed

+31
-31
lines changed

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ inline bool isa_derived(mlir::Type t) { return t.isa<fir::RecordType>(); }
118118
/// Is `t` type(c_ptr) or type(c_funptr)?
119119
inline bool isa_builtin_cptr_type(mlir::Type t) {
120120
if (auto recTy = t.dyn_cast_or_null<fir::RecordType>())
121-
return recTy.getName().endswith("T__builtin_c_ptr") ||
122-
recTy.getName().endswith("T__builtin_c_funptr");
121+
return recTy.getName().ends_with("T__builtin_c_ptr") ||
122+
recTy.getName().ends_with("T__builtin_c_funptr");
123123
return false;
124124
}
125125

flang/lib/Frontend/CompilerInstance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ getExplicitAndImplicitNVPTXTargetFeatures(clang::DiagnosticsEngine &diags,
257257
llvm::StringRef userKeyString(llvm::StringRef(userFeature).drop_front(1));
258258
implicitFeaturesMap[userKeyString.str()] = (userFeature[0] == '+');
259259
// Check if the user provided a PTX version
260-
if (userKeyString.startswith("ptx"))
260+
if (userKeyString.starts_with("ptx"))
261261
ptxVer = true;
262262
}
263263

flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ updateDiagEngineForOptRemarks(clang::DiagnosticsEngine &diagsEng,
131131

132132
// Check to see if this opt starts with "no-", if so, this is a
133133
// negative form of the option.
134-
bool isPositive = !remarkOpt.startswith("no-");
134+
bool isPositive = !remarkOpt.starts_with("no-");
135135
if (!isPositive)
136136
remarkOpt = remarkOpt.substr(3);
137137

flang/lib/Lower/PFTBuilder.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,22 +149,22 @@ class PFTBuilder {
149149
// Modules IEEE_FEATURES, IEEE_EXCEPTIONS, and IEEE_ARITHMETIC get common
150150
// declarations from several __fortran_... support module files.
151151
llvm::StringRef modName = toStringRef(modSym.name());
152-
if (!modName.startswith("ieee_") && !modName.startswith("__fortran_"))
152+
if (!modName.starts_with("ieee_") && !modName.starts_with("__fortran_"))
153153
return;
154154
llvm::StringRef procName = toStringRef(procSym.name());
155-
if (!procName.startswith("ieee_"))
155+
if (!procName.starts_with("ieee_"))
156156
return;
157157
lower::pft::FunctionLikeUnit *proc =
158158
evaluationListStack.back()->back().getOwningProcedure();
159159
proc->hasIeeeAccess = true;
160-
if (!procName.startswith("ieee_set_"))
160+
if (!procName.starts_with("ieee_set_"))
161161
return;
162-
if (procName.startswith("ieee_set_modes_") ||
163-
procName.startswith("ieee_set_status_"))
162+
if (procName.starts_with("ieee_set_modes_") ||
163+
procName.starts_with("ieee_set_status_"))
164164
proc->mayModifyHaltingMode = proc->mayModifyRoundingMode = true;
165-
else if (procName.startswith("ieee_set_halting_mode_"))
165+
else if (procName.starts_with("ieee_set_halting_mode_"))
166166
proc->mayModifyHaltingMode = true;
167-
else if (procName.startswith("ieee_set_rounding_mode_"))
167+
else if (procName.starts_with("ieee_set_rounding_mode_"))
168168
proc->mayModifyRoundingMode = true;
169169
}
170170

flang/lib/Optimizer/Builder/IntrinsicCall.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,13 +1418,13 @@ mlir::Value toValue(const fir::ExtendedValue &val, fir::FirOpBuilder &builder,
14181418
//===----------------------------------------------------------------------===//
14191419

14201420
static bool isIntrinsicModuleProcedure(llvm::StringRef name) {
1421-
return name.startswith("c_") || name.startswith("compiler_") ||
1422-
name.startswith("ieee_") || name.startswith("__ppc_");
1421+
return name.starts_with("c_") || name.starts_with("compiler_") ||
1422+
name.starts_with("ieee_") || name.starts_with("__ppc_");
14231423
}
14241424

14251425
static bool isCoarrayIntrinsic(llvm::StringRef name) {
1426-
return name.startswith("atomic_") || name.startswith("co_") ||
1427-
name.contains("image") || name.endswith("cobound") ||
1426+
return name.starts_with("atomic_") || name.starts_with("co_") ||
1427+
name.contains("image") || name.ends_with("cobound") ||
14281428
name.equals("team_number");
14291429
}
14301430

@@ -1433,7 +1433,7 @@ static bool isCoarrayIntrinsic(llvm::StringRef name) {
14331433
/// {_[ail]?[0-9]+}*, such as _1 or _a4.
14341434
llvm::StringRef genericName(llvm::StringRef specificName) {
14351435
const std::string builtin = "__builtin_";
1436-
llvm::StringRef name = specificName.startswith(builtin)
1436+
llvm::StringRef name = specificName.starts_with(builtin)
14371437
? specificName.drop_front(builtin.size())
14381438
: specificName;
14391439
size_t size = name.size();

flang/lib/Optimizer/Dialect/Support/KindMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static MatchResult parseInt(unsigned &result, const char *&ptr,
180180
static mlir::LogicalResult matchString(const char *&ptr, const char *endPtr,
181181
llvm::StringRef literal) {
182182
llvm::StringRef s(ptr, endPtr - ptr);
183-
if (s.startswith(literal)) {
183+
if (s.starts_with(literal)) {
184184
ptr += literal.size();
185185
return mlir::success();
186186
}

flang/lib/Optimizer/Support/InternalNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ llvm::StringRef fir::NameUniquer::doProgramEntry() {
240240

241241
std::pair<fir::NameUniquer::NameKind, fir::NameUniquer::DeconstructedName>
242242
fir::NameUniquer::deconstruct(llvm::StringRef uniq) {
243-
if (uniq.startswith("_Q")) {
243+
if (uniq.starts_with("_Q")) {
244244
llvm::SmallVector<std::string> modules;
245245
llvm::SmallVector<std::string> procs;
246246
std::int64_t blockId = 0;

flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,11 @@ void SimplifyIntrinsicsPass::runOnOperation() {
12791279
// RTNAME(Sum<T>)(const Descriptor &x, const char *source, int line,
12801280
// int dim, const Descriptor *mask)
12811281
//
1282-
if (funcName.startswith(RTNAME_STRING(Sum))) {
1282+
if (funcName.starts_with(RTNAME_STRING(Sum))) {
12831283
simplifyIntOrFloatReduction(call, kindMap, genRuntimeSumBody);
12841284
return;
12851285
}
1286-
if (funcName.startswith(RTNAME_STRING(DotProduct))) {
1286+
if (funcName.starts_with(RTNAME_STRING(DotProduct))) {
12871287
LLVM_DEBUG(llvm::dbgs() << "Handling " << funcName << "\n");
12881288
LLVM_DEBUG(llvm::dbgs() << "Call operation:\n"; op->dump();
12891289
llvm::dbgs() << "\n");
@@ -1350,23 +1350,23 @@ void SimplifyIntrinsicsPass::runOnOperation() {
13501350
llvm::dbgs() << "\n");
13511351
return;
13521352
}
1353-
if (funcName.startswith(RTNAME_STRING(Maxval))) {
1353+
if (funcName.starts_with(RTNAME_STRING(Maxval))) {
13541354
simplifyIntOrFloatReduction(call, kindMap, genRuntimeMaxvalBody);
13551355
return;
13561356
}
1357-
if (funcName.startswith(RTNAME_STRING(Count))) {
1357+
if (funcName.starts_with(RTNAME_STRING(Count))) {
13581358
simplifyLogicalDim0Reduction(call, kindMap, genRuntimeCountBody);
13591359
return;
13601360
}
1361-
if (funcName.startswith(RTNAME_STRING(Any))) {
1361+
if (funcName.starts_with(RTNAME_STRING(Any))) {
13621362
simplifyLogicalDim1Reduction(call, kindMap, genRuntimeAnyBody);
13631363
return;
13641364
}
1365-
if (funcName.endswith(RTNAME_STRING(All))) {
1365+
if (funcName.ends_with(RTNAME_STRING(All))) {
13661366
simplifyLogicalDim1Reduction(call, kindMap, genRuntimeAllBody);
13671367
return;
13681368
}
1369-
if (funcName.startswith(RTNAME_STRING(Minloc))) {
1369+
if (funcName.starts_with(RTNAME_STRING(Minloc))) {
13701370
simplifyMinlocReduction(call, kindMap);
13711371
return;
13721372
}

flang/lib/Parser/source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void SourceFile::RecordLineStarts() {
4646
void SourceFile::IdentifyPayload() {
4747
llvm::StringRef content{buf_->getBufferStart(), buf_->getBufferSize()};
4848
constexpr llvm::StringLiteral UTF8_BOM{"\xef\xbb\xbf"};
49-
if (content.startswith(UTF8_BOM)) {
49+
if (content.starts_with(UTF8_BOM)) {
5050
bom_end_ = UTF8_BOM.size();
5151
encoding_ = Encoding::UTF_8;
5252
}

flang/tools/flang-driver/driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ int main(int argc, const char **argv) {
9999
auto firstArg = std::find_if(args.begin() + 1, args.end(),
100100
[](const char *a) { return a != nullptr; });
101101
if (firstArg != args.end()) {
102-
if (llvm::StringRef(args[1]).startswith("-cc1")) {
102+
if (llvm::StringRef(args[1]).starts_with("-cc1")) {
103103
llvm::errs() << "error: unknown integrated tool '" << args[1] << "'. "
104104
<< "Valid tools include '-fc1'.\n";
105105
return 1;
106106
}
107107
// Call flang-new frontend
108-
if (llvm::StringRef(args[1]).startswith("-fc1")) {
108+
if (llvm::StringRef(args[1]).starts_with("-fc1")) {
109109
return executeFC1Tool(args);
110110
}
111111
}

0 commit comments

Comments
 (0)