diff options
author | Kazu Hirata <kazu@google.com> | 2023-12-13 22:46:02 -0800 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2023-12-13 22:46:02 -0800 |
commit | 5c9d82de6b72cc0c037daecce452c450870f0034 (patch) | |
tree | 6df2bfa36033214406a096235985cdde220765b4 /llvm | |
parent | 2255795f281862b11e22920b982d57787808ecbb (diff) | |
download | llvm-5c9d82de6b72cc0c037daecce452c450870f0034.zip llvm-5c9d82de6b72cc0c037daecce452c450870f0034.tar.gz llvm-5c9d82de6b72cc0c037daecce452c450870f0034.tar.bz2 |
[llvm] 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.
Diffstat (limited to 'llvm')
20 files changed, 50 insertions, 47 deletions
diff --git a/llvm/lib/AsmParser/LLLexer.cpp b/llvm/lib/AsmParser/LLLexer.cpp index fcb25f5..c8da3ef 100644 --- a/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm/lib/AsmParser/LLLexer.cpp @@ -906,7 +906,7 @@ lltok::Kind LLLexer::LexIdentifier() { #define DWKEYWORD(TYPE, TOKEN) \ do { \ - if (Keyword.startswith("DW_" #TYPE "_")) { \ + if (Keyword.starts_with("DW_" #TYPE "_")) { \ StrVal.assign(Keyword.begin(), Keyword.end()); \ return lltok::TOKEN; \ } \ diff --git a/llvm/unittests/Analysis/CFGTest.cpp b/llvm/unittests/Analysis/CFGTest.cpp index 3ffad1c..4616426 100644 --- a/llvm/unittests/Analysis/CFGTest.cpp +++ b/llvm/unittests/Analysis/CFGTest.cpp @@ -61,7 +61,7 @@ protected: assert(ExclusionSet.empty()); for (auto I = F->begin(), E = F->end(); I != E; ++I) { - if (I->hasName() && I->getName().startswith("excluded")) + if (I->hasName() && I->getName().starts_with("excluded")) ExclusionSet.insert(&*I); } } diff --git a/llvm/unittests/Analysis/TBAATest.cpp b/llvm/unittests/Analysis/TBAATest.cpp index 3367aef..3e81968 100644 --- a/llvm/unittests/Analysis/TBAATest.cpp +++ b/llvm/unittests/Analysis/TBAATest.cpp @@ -59,7 +59,7 @@ TEST_F(TBAATest, checkVerifierBehaviorForOldTBAA) { EXPECT_TRUE(verifyFunction(*F, &Outs)); EXPECT_TRUE(StringRef(ErrorMsg.begin(), ErrorMsg.size()) - .startswith(ExpectedFailureMsg)); + .starts_with(ExpectedFailureMsg)); } TEST_F(TBAATest, checkTBAAMerging) { diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index 0841cd3..7c45d97 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -222,9 +222,8 @@ TEST(MachineInstrPrintingTest, DebugLocPrinting) { MI->print(OS, /*IsStandalone*/true, /*SkipOpers*/false, /*SkipDebugLoc*/false, /*AddNewLine*/false); ASSERT_TRUE( - StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location ")); - ASSERT_TRUE( - StringRef(OS.str()).endswith("filename:1:5")); + StringRef(OS.str()).starts_with("$noreg = UNKNOWN debug-location ")); + ASSERT_TRUE(StringRef(OS.str()).ends_with("filename:1:5")); } TEST(MachineInstrSpan, DistanceBegin) { diff --git a/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp b/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp index eb9477e..125bc17 100644 --- a/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp +++ b/llvm/unittests/DebugInfo/LogicalView/CodeViewReaderTest.cpp @@ -73,7 +73,7 @@ void checkElementPropertiesClangCodeview(LVReader *Reader) { EXPECT_EQ(Root->getName(), CodeViewClang); EXPECT_EQ(CompileUnit->getBaseAddress(), 0u); - EXPECT_TRUE(CompileUnit->getProducer().startswith("clang")); + EXPECT_TRUE(CompileUnit->getProducer().starts_with("clang")); EXPECT_EQ(CompileUnit->getName(), "test.cpp"); EXPECT_EQ(Function->lineCount(), 16u); @@ -139,7 +139,7 @@ void checkElementPropertiesMsvcCodeview(LVReader *Reader) { EXPECT_EQ(Root->getName(), CodeViewMsvc); EXPECT_EQ(CompileUnit->getBaseAddress(), 0u); - EXPECT_TRUE(CompileUnit->getProducer().startswith("Microsoft")); + EXPECT_TRUE(CompileUnit->getProducer().starts_with("Microsoft")); EXPECT_EQ(CompileUnit->getName(), "test.cpp"); EXPECT_EQ(Function->lineCount(), 14u); @@ -205,7 +205,7 @@ void checkElementPropertiesMsvcCodeviewPdb(LVReader *Reader) { EXPECT_EQ(Root->getName(), CodeViewPdbMsvc); EXPECT_EQ(CompileUnit->getBaseAddress(), 0u); - EXPECT_TRUE(CompileUnit->getProducer().startswith("Microsoft")); + EXPECT_TRUE(CompileUnit->getProducer().starts_with("Microsoft")); EXPECT_EQ(CompileUnit->getName(), "test.cpp"); EXPECT_EQ(Function->lineCount(), 14u); diff --git a/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp b/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp index f6db28a..bd278be 100644 --- a/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp +++ b/llvm/unittests/DebugInfo/LogicalView/ELFReaderTest.cpp @@ -70,7 +70,7 @@ void checkElementProperties(LVReader *Reader) { EXPECT_EQ(Root->getName(), DwarfClang); EXPECT_EQ(CompileUnit->getBaseAddress(), 0u); - EXPECT_TRUE(CompileUnit->getProducer().startswith("clang")); + EXPECT_TRUE(CompileUnit->getProducer().starts_with("clang")); EXPECT_EQ(CompileUnit->getName(), "test.cpp"); EXPECT_EQ(CompileUnit->lineCount(), 0u); diff --git a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h index 7071681..13484e1b 100644 --- a/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h +++ b/llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h @@ -73,7 +73,7 @@ protected: // If ARCH has sub-arch support, find it SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin(); for(; I != SupportedSubArchs.end(); ++I) - if (Host.getArchName().startswith(*I)) + if (Host.getArchName().starts_with(*I)) return true; return false; diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp index d62973f..12f4263 100644 --- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp @@ -124,7 +124,7 @@ protected: // TODO: Print error messages in failure logs, use them to audit this list. // Some architectures may be unsupportable or missing key components, but // some may just be failing due to bugs in this testcase. - if (Triple.startswith("armv7") || Triple.startswith("armv8l")) + if (Triple.starts_with("armv7") || Triple.starts_with("armv8l")) return false; return true; } diff --git a/llvm/unittests/FileCheck/FileCheckTest.cpp b/llvm/unittests/FileCheck/FileCheckTest.cpp index 317fc449..91fce69 100644 --- a/llvm/unittests/FileCheck/FileCheckTest.cpp +++ b/llvm/unittests/FileCheck/FileCheckTest.cpp @@ -172,7 +172,7 @@ struct ExpressionFormatParameterisedFixture } std::string padWithLeadingZeros(StringRef NumStr) const { - bool Negative = NumStr.startswith("-"); + bool Negative = NumStr.starts_with("-"); if (NumStr.size() - unsigned(Negative) >= Precision) return NumStr.str(); diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 193ada3..e79d0bb 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -5821,7 +5821,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) { Function *KernelLaunchFunc = Call->getCalledFunction(); EXPECT_NE(KernelLaunchFunc, nullptr); StringRef FunctionName = KernelLaunchFunc->getName(); - EXPECT_TRUE(FunctionName.startswith("__tgt_target_kernel")); + EXPECT_TRUE(FunctionName.starts_with("__tgt_target_kernel")); // Check the fallback call BasicBlock *FallbackBlock = Branch->getSuccessor(0); @@ -5838,7 +5838,7 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) { Function *OutlinedFunc = FCall->getCalledFunction(); EXPECT_NE(OutlinedFunc, nullptr); StringRef FunctionName2 = OutlinedFunc->getName(); - EXPECT_TRUE(FunctionName2.startswith("__omp_offloading")); + EXPECT_TRUE(FunctionName2.starts_with("__omp_offloading")); EXPECT_FALSE(verifyModule(*M, &errs())); } diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp index 2e14bfc..31e3b9d 100644 --- a/llvm/unittests/IR/VerifierTest.cpp +++ b/llvm/unittests/IR/VerifierTest.cpp @@ -105,8 +105,10 @@ TEST(VerifierTest, InvalidRetAttribute) { std::string Error; raw_string_ostream ErrorOS(Error); EXPECT_TRUE(verifyModule(M, &ErrorOS)); - EXPECT_TRUE(StringRef(ErrorOS.str()).startswith( - "Attribute 'uwtable' does not apply to function return values")); + EXPECT_TRUE( + StringRef(ErrorOS.str()) + .starts_with( + "Attribute 'uwtable' does not apply to function return values")); } /// Test the verifier rejects invalid nofpclass values that the assembler may @@ -134,11 +136,11 @@ TEST(VerifierTest, InvalidNoFPClassAttribute) { StringRef ErrMsg(ErrorOS.str()); if (InvalidMask == 0) { - EXPECT_TRUE(ErrMsg.startswith( + EXPECT_TRUE(ErrMsg.starts_with( "Attribute 'nofpclass' must have at least one test bit set")) << ErrMsg; } else { - EXPECT_TRUE(ErrMsg.startswith("Invalid value for 'nofpclass' test mask")) + EXPECT_TRUE(ErrMsg.starts_with("Invalid value for 'nofpclass' test mask")) << ErrMsg; } } @@ -195,8 +197,9 @@ TEST(VerifierTest, CrossModuleRef) { Error.clear(); EXPECT_TRUE(verifyModule(M3, &ErrorOS)); - EXPECT_TRUE(StringRef(ErrorOS.str()).startswith( - "Referencing personality function in another module!")); + EXPECT_TRUE( + StringRef(ErrorOS.str()) + .starts_with("Referencing personality function in another module!")); // Erase bad methods to avoid triggering an assertion failure on destruction F1->eraseFromParent(); @@ -211,9 +214,9 @@ TEST(VerifierTest, InvalidVariableLinkage) { std::string Error; raw_string_ostream ErrorOS(Error); EXPECT_TRUE(verifyModule(M, &ErrorOS)); - EXPECT_TRUE( - StringRef(ErrorOS.str()).startswith("Global is external, but doesn't " - "have external or weak linkage!")); + EXPECT_TRUE(StringRef(ErrorOS.str()) + .starts_with("Global is external, but doesn't " + "have external or weak linkage!")); } TEST(VerifierTest, InvalidFunctionLinkage) { @@ -225,9 +228,9 @@ TEST(VerifierTest, InvalidFunctionLinkage) { std::string Error; raw_string_ostream ErrorOS(Error); EXPECT_TRUE(verifyModule(M, &ErrorOS)); - EXPECT_TRUE( - StringRef(ErrorOS.str()).startswith("Global is external, but doesn't " - "have external or weak linkage!")); + EXPECT_TRUE(StringRef(ErrorOS.str()) + .starts_with("Global is external, but doesn't " + "have external or weak linkage!")); } TEST(VerifierTest, DetectInvalidDebugInfo) { @@ -284,8 +287,9 @@ TEST(VerifierTest, MDNodeWrongContext) { std::string Error; raw_string_ostream ErrorOS(Error); EXPECT_TRUE(verifyModule(M, &ErrorOS)); - EXPECT_TRUE(StringRef(ErrorOS.str()) - .startswith("MDNode context does not match Module context!")); + EXPECT_TRUE( + StringRef(ErrorOS.str()) + .starts_with("MDNode context does not match Module context!")); } TEST(VerifierTest, AttributesWrongContext) { diff --git a/llvm/unittests/Support/MemoryBufferTest.cpp b/llvm/unittests/Support/MemoryBufferTest.cpp index bfabd73..cfee3e4 100644 --- a/llvm/unittests/Support/MemoryBufferTest.cpp +++ b/llvm/unittests/Support/MemoryBufferTest.cpp @@ -432,7 +432,7 @@ TEST_F(MemoryBufferTest, mmapVolatileNoNull) { OwningBuffer MB = std::move(*MBOrError); EXPECT_EQ(MB->getBufferKind(), MemoryBuffer::MemoryBuffer_MMap); EXPECT_EQ(MB->getBufferSize(), std::size_t(FileWrites * 8)); - EXPECT_TRUE(MB->getBuffer().startswith("01234567")); + EXPECT_TRUE(MB->getBuffer().starts_with("01234567")); } // Test that SmallVector without a null terminator gets one. diff --git a/llvm/unittests/Support/ProgramTest.cpp b/llvm/unittests/Support/ProgramTest.cpp index ca301dc3..91dbb57 100644 --- a/llvm/unittests/Support/ProgramTest.cpp +++ b/llvm/unittests/Support/ProgramTest.cpp @@ -96,7 +96,7 @@ protected: while (*EnvP != nullptr) { auto S = prepareEnvVar(*EnvP); - if (!StringRef(S).startswith("GTEST_")) + if (!StringRef(S).starts_with("GTEST_")) EnvTable.emplace_back(S); ++EnvP; } diff --git a/llvm/unittests/Support/TarWriterTest.cpp b/llvm/unittests/Support/TarWriterTest.cpp index b5f0724..d640470 100644 --- a/llvm/unittests/Support/TarWriterTest.cpp +++ b/llvm/unittests/Support/TarWriterTest.cpp @@ -119,7 +119,7 @@ TEST_F(TarWriterTest, Pax) { EXPECT_EQ("", StringRef(Hdr->Name)); StringRef Pax = StringRef((char *)(Buf.data() + 512), 512); - EXPECT_TRUE(Pax.startswith("211 path=/" + std::string(200, 'x'))); + EXPECT_TRUE(Pax.starts_with("211 path=/" + std::string(200, 'x'))); } TEST_F(TarWriterTest, SingleFile) { diff --git a/llvm/unittests/Support/TypeNameTest.cpp b/llvm/unittests/Support/TypeNameTest.cpp index c896293..e0d9ac5 100644 --- a/llvm/unittests/Support/TypeNameTest.cpp +++ b/llvm/unittests/Support/TypeNameTest.cpp @@ -29,11 +29,11 @@ TEST(TypeNameTest, Names) { #if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) || \ defined(_MSC_VER) - EXPECT_TRUE(S1Name.endswith("::N1::S1")) << S1Name.str(); - EXPECT_TRUE(C1Name.endswith("::N1::C1")) << C1Name.str(); - EXPECT_TRUE(U1Name.endswith("::N1::U1")) << U1Name.str(); + EXPECT_TRUE(S1Name.ends_with("::N1::S1")) << S1Name.str(); + EXPECT_TRUE(C1Name.ends_with("::N1::C1")) << C1Name.str(); + EXPECT_TRUE(U1Name.ends_with("::N1::U1")) << U1Name.str(); #ifdef __clang__ - EXPECT_TRUE(S2Name.endswith("S2")) << S2Name.str(); + EXPECT_TRUE(S2Name.ends_with("S2")) << S2Name.str(); #else EXPECT_TRUE(S2Name.endswith("::S2")) << S2Name.str(); #endif diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index bd4048f..15f5204 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -452,11 +452,11 @@ TEST(VirtualFileSystemTest, BasicRealFSIteration) { ASSERT_FALSE(EC); ASSERT_NE(vfs::directory_iterator(), I); // Check either a or c, since we can't rely on the iteration order. - EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c")); + EXPECT_TRUE(I->path().ends_with("a") || I->path().ends_with("c")); I.increment(EC); ASSERT_FALSE(EC); ASSERT_NE(vfs::directory_iterator(), I); - EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c")); + EXPECT_TRUE(I->path().ends_with("a") || I->path().ends_with("c")); I.increment(EC); EXPECT_EQ(vfs::directory_iterator(), I); } diff --git a/llvm/unittests/TargetParser/CSKYTargetParserTest.cpp b/llvm/unittests/TargetParser/CSKYTargetParserTest.cpp index 4f0b526..f28a2a3 100644 --- a/llvm/unittests/TargetParser/CSKYTargetParserTest.cpp +++ b/llvm/unittests/TargetParser/CSKYTargetParserTest.cpp @@ -28,7 +28,7 @@ std::string FormatExtensionFlags(uint64_t Flags) { Features.erase(std::remove_if(Features.begin(), Features.end(), [](StringRef extension) { - return extension.startswith("-"); + return extension.starts_with("-"); }), Features.end()); diff --git a/llvm/unittests/TargetParser/TargetParserTest.cpp b/llvm/unittests/TargetParser/TargetParserTest.cpp index 687b56c..e2b9712 100644 --- a/llvm/unittests/TargetParser/TargetParserTest.cpp +++ b/llvm/unittests/TargetParser/TargetParserTest.cpp @@ -55,7 +55,7 @@ std::string FormatExtensionFlags(int64_t Flags) { // E.g. if AEK_CRC is not set then it adds "-crc". Not useful here. Features.erase(std::remove_if(Features.begin(), Features.end(), [](StringRef extension) { - return extension.startswith("-"); + return extension.starts_with("-"); }), Features.end()); @@ -75,7 +75,7 @@ std::string FormatExtensionFlags(AArch64::ExtensionBitset Flags) { // E.g. if AEK_CRC is not set then it adds "-crc". Not useful here. Features.erase(std::remove_if(Features.begin(), Features.end(), [](StringRef extension) { - return extension.startswith("-"); + return extension.starts_with("-"); }), Features.end()); diff --git a/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp b/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp index df4d6c3..da78c15 100644 --- a/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp +++ b/llvm/unittests/Transforms/Coroutines/ExtraRematTest.cpp @@ -126,7 +126,7 @@ bool ExtraMaterializable(Instruction &I) { if (auto *CI = dyn_cast<CallInst>(&I)) { auto *CalledFunc = CI->getCalledFunction(); - if (CalledFunc && CalledFunc->getName().startswith("should.remat")) + if (CalledFunc && CalledFunc->getName().starts_with("should.remat")) return true; } diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp index e083c75b..025771f 100644 --- a/llvm/unittests/Transforms/Utils/CloningTest.cpp +++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp @@ -440,11 +440,11 @@ for.end: EXPECT_NE(NewLoop, nullptr); EXPECT_EQ(NewLoop->getSubLoops().size(), 1u); Loop::block_iterator BI = NewLoop->block_begin(); - EXPECT_TRUE((*BI)->getName().startswith("for.outer")); - EXPECT_TRUE((*(++BI))->getName().startswith("for.inner.preheader")); - EXPECT_TRUE((*(++BI))->getName().startswith("for.inner")); - EXPECT_TRUE((*(++BI))->getName().startswith("for.inner.exit")); - EXPECT_TRUE((*(++BI))->getName().startswith("for.outer.latch")); + EXPECT_TRUE((*BI)->getName().starts_with("for.outer")); + EXPECT_TRUE((*(++BI))->getName().starts_with("for.inner.preheader")); + EXPECT_TRUE((*(++BI))->getName().starts_with("for.inner")); + EXPECT_TRUE((*(++BI))->getName().starts_with("for.inner.exit")); + EXPECT_TRUE((*(++BI))->getName().starts_with("for.outer.latch")); }); } |