From cf68e1b2fb4f6172b08f3430b2530dc2d193ab60 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Tue, 19 Oct 2021 08:54:02 -0700 Subject: [PATCH] [Driver, Frontend] Use StringRef::contains (NFC) --- clang/lib/Driver/Distro.cpp | 6 +++--- clang/lib/Driver/Driver.cpp | 3 +-- clang/lib/Driver/ToolChain.cpp | 2 +- clang/lib/Driver/ToolChains/Clang.cpp | 6 +++--- clang/lib/Driver/ToolChains/FreeBSD.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/lib/Frontend/CompilerInvocation.cpp | 12 ++++++------ clang/lib/Frontend/LayoutOverrideSource.cpp | 2 +- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 4 +--- 10 files changed, 19 insertions(+), 22 deletions(-) diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp index cdb5a1725750..6a11bacb41e5 100644 --- a/clang/lib/Driver/Distro.cpp +++ b/clang/lib/Driver/Distro.cpp @@ -118,11 +118,11 @@ static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) { return Distro::Fedora; if (Data.startswith("Red Hat Enterprise Linux") || Data.startswith("CentOS") || Data.startswith("Scientific Linux")) { - if (Data.find("release 7") != StringRef::npos) + if (Data.contains("release 7")) return Distro::RHEL7; - else if (Data.find("release 6") != StringRef::npos) + else if (Data.contains("release 6")) return Distro::RHEL6; - else if (Data.find("release 5") != StringRef::npos) + else if (Data.contains("release 5")) return Distro::RHEL5; } return Distro::UnknownDistro; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 6558116bbaeb..bdec63e35f62 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -436,8 +436,7 @@ static llvm::Triple computeTargetTriple(const Driver &D, // GNU/Hurd's triples should have been -hurd-gnu*, but were historically made // -gnu* only, and we can not change this, so we have to detect that case as // being the Hurd OS. - if (TargetTriple.find("-unknown-gnu") != StringRef::npos || - TargetTriple.find("-pc-gnu") != StringRef::npos) + if (TargetTriple.contains("-unknown-gnu") || TargetTriple.contains("-pc-gnu")) Target.setOSName("hurd"); // Handle Apple-specific options available here. diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index f40adeb063fc..df205c37f063 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -583,7 +583,7 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD, // for the linker flavor is brittle. In addition, prepending "ld." or "ld64." // to a relative path is surprising. This is more complex due to priorities // among -B, COMPILER_PATH and PATH. --ld-path= should be used instead. - if (UseLinker.find('/') != StringRef::npos) + if (UseLinker.contains('/')) getDriver().Diag(diag::warn_drv_fuse_ld_path); if (llvm::sys::path::is_absolute(UseLinker)) { diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 68b695036458..e56cd4829759 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -644,7 +644,7 @@ static void addDebugPrefixMapArg(const Driver &D, const ArgList &Args, ArgString for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fdebug_prefix_map_EQ)) { StringRef Map = A->getValue(); - if (Map.find('=') == StringRef::npos) + if (!Map.contains('=')) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else @@ -659,7 +659,7 @@ static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args, for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fmacro_prefix_map_EQ)) { StringRef Map = A->getValue(); - if (Map.find('=') == StringRef::npos) + if (!Map.contains('=')) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else @@ -674,7 +674,7 @@ static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args, for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fcoverage_prefix_map_EQ)) { StringRef Map = A->getValue(); - if (Map.find('=') == StringRef::npos) + if (!Map.contains('=')) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp b/clang/lib/Driver/ToolChains/FreeBSD.cpp index 2753876d28d4..7ace08f6e619 100644 --- a/clang/lib/Driver/ToolChains/FreeBSD.cpp +++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -110,7 +110,7 @@ void freebsd::Assembler::ConstructJob(Compilation &C, const JobAction &JA, for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fdebug_prefix_map_EQ)) { StringRef Map = A->getValue(); - if (Map.find('=') == StringRef::npos) + if (!Map.contains('=')) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else { diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 80e379cb6471..2b5c34b9a63d 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -930,7 +930,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C, for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ, options::OPT_fdebug_prefix_map_EQ)) { StringRef Map = A->getValue(); - if (Map.find('=') == StringRef::npos) + if (!Map.contains('=')) D.Diag(diag::err_drv_invalid_argument_to_option) << Map << A->getOption().getName(); else { diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index a80b8ad4e7ed..20ed697fecbc 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -206,7 +206,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) ExtraOpts.push_back("max-page-size=4096"); } - if (GCCInstallation.getParentLibPath().find("opt/rh/") != StringRef::npos) + if (GCCInstallation.getParentLibPath().contains("opt/rh/")) // With devtoolset on RHEL, we want to add a bin directory that is relative // to the detected gcc install, because if we are using devtoolset gcc then // we want to use other tools from devtoolset (e.g. ld) instead of the diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 410702d51ed2..8d33a59cb983 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -999,7 +999,7 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, diag::err_analyzer_config_no_value) << configVal; break; } - if (val.find('=') != StringRef::npos) { + if (val.contains('=')) { Diags.Report(SourceLocation(), diag::err_analyzer_config_multiple_values) << configVal; @@ -2061,13 +2061,13 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, if (!Args.hasArg(OPT_fno_sanitize_ignorelist)) { for (const auto *A : Args.filtered(OPT_fsanitize_ignorelist_EQ)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist); } if (Opts.IncludeSystemHeaders) { for (const auto *A : Args.filtered(OPT_fsanitize_system_ignorelist_EQ)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_SanitizeIgnorelist); } } @@ -2084,7 +2084,7 @@ static bool ParseDependencyOutputArgs(DependencyOutputOptions &Opts, // Only the -fmodule-file= form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ExtraDeps.emplace_back(std::string(Val), EDK_ModuleFile); } @@ -2728,7 +2728,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, // Only the -fmodule-file= form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') == StringRef::npos) + if (!Val.contains('=')) Opts.ModuleFiles.push_back(std::string(Val)); } @@ -3003,7 +3003,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args, // Only the -fmodule-file== form. for (const auto *A : Args.filtered(OPT_fmodule_file)) { StringRef Val = A->getValue(); - if (Val.find('=') != StringRef::npos){ + if (Val.contains('=')) { auto Split = Val.split('='); Opts.PrebuiltModuleFiles.insert( {std::string(Split.first), std::string(Split.second)}); diff --git a/clang/lib/Frontend/LayoutOverrideSource.cpp b/clang/lib/Frontend/LayoutOverrideSource.cpp index c735c6c42cb3..0d288db0632f 100644 --- a/clang/lib/Frontend/LayoutOverrideSource.cpp +++ b/clang/lib/Frontend/LayoutOverrideSource.cpp @@ -43,7 +43,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef Filename) { StringRef LineStr(Line); // Determine whether the following line will start a - if (LineStr.find("*** Dumping AST Record Layout") != StringRef::npos) { + if (LineStr.contains("*** Dumping AST Record Layout")) { // Flush the last type/layout, if there is one. if (!CurrentType.empty()) Layouts[CurrentType] = CurrentLayout; diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index 0503ae46a15f..2759625ae254 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -99,9 +99,7 @@ public: return true; } - bool match(StringRef S) override { - return S.find(Text) != StringRef::npos; - } + bool match(StringRef S) override { return S.contains(Text); } }; /// RegexDirective - Directive with regular-expression matching.