Skip to content

[RISCV] Use StringRef in a range-based for loop (NFC) #144243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

When we iterate over std::vectorstd::string, we can directly assign
each element to StringRef. We do not need to go through a separate
statement.

When we iterate over std::vector<std::string>, we can directly assign
each element to StringRef.  We do not need to go through a separate
statement.
@llvmbot
Copy link
Member

llvmbot commented Jun 15, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Kazu Hirata (kazutakahirata)

Changes

When we iterate over std::vector<std::string>, we can directly assign
each element to StringRef. We do not need to go through a separate
statement.


Full diff: https://github.com/llvm/llvm-project/pull/144243.diff

1 Files Affected:

  • (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+1-2)
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index e76ddd4b648dc..17c98332ab0af 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -449,8 +449,7 @@ RISCVISAInfo::parseFeatures(unsigned XLen,
   assert(XLen == 32 || XLen == 64);
   std::unique_ptr<RISCVISAInfo> ISAInfo(new RISCVISAInfo(XLen));
 
-  for (auto &Feature : Features) {
-    StringRef ExtName = Feature;
+  for (StringRef ExtName : Features) {
     assert(ExtName.size() > 1 && (ExtName[0] == '+' || ExtName[0] == '-'));
     bool Add = ExtName[0] == '+';
     ExtName = ExtName.drop_front(1); // Drop '+' or '-'

Copy link
Member

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit 84ff1bd into llvm:main Jun 15, 2025
9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250614_range_for_StringRef_llvm_RISCV branch June 15, 2025 06:24
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 15, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building llvm at step 5 "compile-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/7361

Here is the relevant piece of the build log for the reference
Step 5 (compile-openmp) failure: build (failure)
...
0.140 [390/130/167] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/ctype.h
0.141 [389/130/168] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/stdlib.h
0.141 [388/130/169] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/locale.h
0.141 [387/130/170] Generating header locale.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/locale.yaml
0.141 [386/130/171] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/uchar.h
0.142 [385/130/172] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/time.h
0.142 [384/130/173] Generating header time.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/time.yaml
0.142 [383/130/174] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/signal.h
0.143 [382/130/175] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.getenv.dir/getenv.cpp.o
0.144 [381/130/176] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcasestr.dir/strcasestr.cpp.o
FAILED: libc/src/string/CMakeFiles/libc.src.string.strcasestr.dir/strcasestr.cpp.o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang++ --target=amdgcn-amd-amdhsa -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -D__LIBC_USE_FLOAT16_CONVERSION -I/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc -isystem /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa -O3 -DNDEBUG --target=amdgcn-amd-amdhsa -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)" -fpie -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -nogpulib -fvisibility=hidden -fconvergent-functions -flto -Wno-multi-gpu -Xclang -mcode-object-version=none -DLIBC_COPT_PUBLIC_PACKAGING -UNDEBUG -MD -MT libc/src/string/CMakeFiles/libc.src.string.strcasestr.dir/strcasestr.cpp.o -MF libc/src/string/CMakeFiles/libc.src.string.strcasestr.dir/strcasestr.cpp.o.d -o libc/src/string/CMakeFiles/libc.src.string.strcasestr.dir/strcasestr.cpp.o -c /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/strcasestr.cpp
In file included from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/strcasestr.cpp:15:
In file included from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/memory_utils/inline_strstr.h:15:
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/string_utils.h:66:27: error: unknown type name 'uintptr_t'
   66 |   for (; reinterpret_cast<uintptr_t>(char_ptr) % sizeof(Word) != 0;
      |                           ^
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/string_utils.h:66:48: error: invalid operands to binary expression ('const char *' and 'unsigned long')
   66 |   for (; reinterpret_cast<uintptr_t>(char_ptr) % sizeof(Word) != 0;
      |                                      ~~~~~~~~  ^ ~~~~~~~~~~~~
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/string_utils.h:107:27: error: unknown type name 'uintptr_t'
  107 |   for (; reinterpret_cast<uintptr_t>(char_ptr) % sizeof(Word) != 0 && cur < n;
      |                           ^
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/src/string/string_utils.h:107:48: error: invalid operands to binary expression ('const unsigned char *' and 'unsigned long')
  107 |   for (; reinterpret_cast<uintptr_t>(char_ptr) % sizeof(Word) != 0 && cur < n;
      |                                      ~~~~~~~~  ^ ~~~~~~~~~~~~
4 errors generated.
0.144 [381/129/177] Generating header string.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/string.yaml
0.144 [381/128/178] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.memalignment.dir/memalignment.cpp.o
0.144 [381/127/179] Generating header stdlib.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/stdlib.yaml
0.144 [381/126/180] Generating header uchar.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/uchar.yaml
0.145 [381/125/181] Generating header stdio.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/stdio.yaml
0.145 [381/124/182] Generating header signal.h from /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/runtimes/../libc/include/signal.yaml
0.154 [381/123/183] Building CXX object libc/src/strings/CMakeFiles/libc.src.strings.bcopy.dir/bcopy.cpp.o
0.155 [381/122/184] Generating /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/include/amdgcn-amd-amdhsa/llvm-libc-decls/stdio.h
0.199 [381/121/185] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlcat.dir/strlcat.cpp.o
0.201 [381/120/186] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.common_constants.dir/common_constants.cpp.o
0.201 [381/119/187] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strnlen.dir/strnlen.cpp.o
0.205 [381/118/188] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_leading_ones_ull.dir/stdc_leading_ones_ull.cpp.o
0.208 [381/117/189] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strsep.dir/strsep.cpp.o
0.211 [381/116/190] Building CXX object libc/src/errno/CMakeFiles/libc.src.errno.errno.dir/libc_errno.cpp.o
0.212 [381/115/191] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strrchr.dir/strrchr.cpp.o
0.213 [381/114/192] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlen.dir/strlen.cpp.o
0.213 [381/113/193] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strtok_r.dir/strtok_r.cpp.o
0.213 [381/112/194] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_leading_zeros_uc.dir/stdc_leading_zeros_uc.cpp.o
0.214 [381/111/195] Building CXX object libc/src/ctype/CMakeFiles/libc.src.ctype.isblank_l.dir/isblank_l.cpp.o
0.214 [381/110/196] Building CXX object libc/src/ctype/CMakeFiles/libc.src.ctype.isalnum.dir/isalnum.cpp.o
0.214 [381/109/197] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_count_zeros_us.dir/stdc_count_zeros_us.cpp.o
0.214 [381/108/198] Building CXX object libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_leading_zeros_ui.dir/stdc_leading_zeros_ui.cpp.o

akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
When we iterate over std::vector<std::string>, we can directly assign
each element to StringRef.  We do not need to go through a separate
statement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants