[clang] Use StringRef in range-based for loops (NFC) (#144242)

When we iterate over std::vector<std::string>, we can directly assign
each element to StringRef.  We do not need to go through separate
statements.
This commit is contained in:
Kazu Hirata 2025-06-15 21:00:22 -07:00 committed by GitHub
parent 9adde28df7
commit f71fb2dc01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 8 deletions

View File

@ -555,8 +555,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
bool TargetInfo::initFeatureMap(
llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU,
const std::vector<std::string> &FeatureVec) const {
for (const auto &F : FeatureVec) {
StringRef Name = F;
for (StringRef Name : FeatureVec) {
if (Name.empty())
continue;
// Apply the feature via the target.

View File

@ -3232,8 +3232,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
if (ParsedAttrs.Duplicate != "")
return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
<< Duplicate << None << ParsedAttrs.Duplicate << Target;
for (const auto &Feature : ParsedAttrs.Features) {
StringRef CurFeature = Feature;
for (StringRef CurFeature : ParsedAttrs.Features) {
if (!CurFeature.starts_with('+') && !CurFeature.starts_with('-'))
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
<< Unsupported << None << AttrStr << Target;
@ -3241,8 +3240,7 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
}
if (Context.getTargetInfo().getTriple().isLoongArch()) {
for (const auto &Feature : ParsedAttrs.Features) {
StringRef CurFeature = Feature;
for (StringRef CurFeature : ParsedAttrs.Features) {
if (CurFeature.starts_with("!arch=")) {
StringRef ArchValue = CurFeature.split("=").second.trim();
return Diag(LiteralLoc, diag::err_attribute_unsupported)

View File

@ -22,8 +22,7 @@ namespace clang {
namespace tooling {
static StringRef getDriverMode(const CommandLineArguments &Args) {
for (const auto &Arg : Args) {
StringRef ArgRef = Arg;
for (StringRef ArgRef : Args) {
if (ArgRef.consume_front("--driver-mode=")) {
return ArgRef;
}