Skip to content
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

[Driver] Use a range constructor of StringSet (NFC) #133201

Conversation

kazutakahirata
Copy link
Contributor

This patch uses a range constructor to collapse:

llvm::StringSet<> Dest;
for (const auto &S : Src)
Dest.insert(S);

down to:

llvm::StringSet<> Dest(llvm::from_range, Src);

This patch uses a range constructor to collapse:

  llvm::StringSet<> Dest;
  for (const auto &S : Src)
    Dest.insert(S);

down to:

  llvm::StringSet<> Dest(llvm::from_range, Src);
@kazutakahirata kazutakahirata requested review from kuhar and MaskRay March 27, 2025 03:21
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Mar 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 27, 2025

@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)

Changes

This patch uses a range constructor to collapse:

llvm::StringSet<> Dest;
for (const auto &S : Src)
Dest.insert(S);

down to:

llvm::StringSet<> Dest(llvm::from_range, Src);


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

2 Files Affected:

  • (modified) clang/lib/Driver/Job.cpp (+1-3)
  • (modified) clang/lib/Driver/Multilib.cpp (+2-6)
diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index ae2f1cd1f56c9..4619b8c1887be 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -140,9 +140,7 @@ void Command::buildArgvForResponseFile(
     return;
   }
 
-  llvm::StringSet<> Inputs;
-  for (const auto *InputName : InputFileList)
-    Inputs.insert(InputName);
+  llvm::StringSet<> Inputs(llvm::from_range, InputFileList);
   Out.push_back(Executable);
 
   if (PrependArg)
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index a92ad4718fb6e..87fa1af54a8ea 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -60,9 +60,7 @@ void Multilib::print(raw_ostream &OS) const {
 bool Multilib::operator==(const Multilib &Other) const {
   // Check whether the flags sets match
   // allowing for the match to be order invariant
-  llvm::StringSet<> MyFlags;
-  for (const auto &Flag : Flags)
-    MyFlags.insert(Flag);
+  llvm::StringSet<> MyFlags(llvm::from_range, Flags);
 
   for (const auto &Flag : Other.Flags)
     if (!MyFlags.contains(Flag))
@@ -272,9 +270,7 @@ bool MultilibSet::select(
 
 llvm::StringSet<>
 MultilibSet::expandFlags(const Multilib::flags_list &InFlags) const {
-  llvm::StringSet<> Result;
-  for (const auto &F : InFlags)
-    Result.insert(F);
+  llvm::StringSet<> Result(llvm::from_range, InFlags);
   for (const FlagMatcher &M : FlagMatchers) {
     std::string RegexString(M.Match);
 

@llvmbot
Copy link
Member

llvmbot commented Mar 27, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

This patch uses a range constructor to collapse:

llvm::StringSet<> Dest;
for (const auto &S : Src)
Dest.insert(S);

down to:

llvm::StringSet<> Dest(llvm::from_range, Src);


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

2 Files Affected:

  • (modified) clang/lib/Driver/Job.cpp (+1-3)
  • (modified) clang/lib/Driver/Multilib.cpp (+2-6)
diff --git a/clang/lib/Driver/Job.cpp b/clang/lib/Driver/Job.cpp
index ae2f1cd1f56c9..4619b8c1887be 100644
--- a/clang/lib/Driver/Job.cpp
+++ b/clang/lib/Driver/Job.cpp
@@ -140,9 +140,7 @@ void Command::buildArgvForResponseFile(
     return;
   }
 
-  llvm::StringSet<> Inputs;
-  for (const auto *InputName : InputFileList)
-    Inputs.insert(InputName);
+  llvm::StringSet<> Inputs(llvm::from_range, InputFileList);
   Out.push_back(Executable);
 
   if (PrependArg)
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index a92ad4718fb6e..87fa1af54a8ea 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -60,9 +60,7 @@ void Multilib::print(raw_ostream &OS) const {
 bool Multilib::operator==(const Multilib &Other) const {
   // Check whether the flags sets match
   // allowing for the match to be order invariant
-  llvm::StringSet<> MyFlags;
-  for (const auto &Flag : Flags)
-    MyFlags.insert(Flag);
+  llvm::StringSet<> MyFlags(llvm::from_range, Flags);
 
   for (const auto &Flag : Other.Flags)
     if (!MyFlags.contains(Flag))
@@ -272,9 +270,7 @@ bool MultilibSet::select(
 
 llvm::StringSet<>
 MultilibSet::expandFlags(const Multilib::flags_list &InFlags) const {
-  llvm::StringSet<> Result;
-  for (const auto &F : InFlags)
-    Result.insert(F);
+  llvm::StringSet<> Result(llvm::from_range, InFlags);
   for (const FlagMatcher &M : FlagMatchers) {
     std::string RegexString(M.Match);
 

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

The PR title doesn't match the content -- could you update it with the focus on the constructor?

@kazutakahirata kazutakahirata changed the title [Driver] Use *Set::insert_range (NFC) [Driver] Use a range constructor of StringSet (NFC) Mar 27, 2025
@kazutakahirata
Copy link
Contributor Author

The PR title doesn't match the content -- could you update it with the focus on the constructor?

Oops. Thank you for pointing this out!

@kazutakahirata kazutakahirata merged commit 64046e9 into llvm:main Mar 27, 2025
14 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 27, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vls running on linaro-g3-03 while building clang at step 7 "ninja check 1".

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

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
...
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld64.lld
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/wasm-ld
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/discovery.py:276: warning: input '/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/runtimes/runtimes-bins/compiler-rt/test/interception/Unit' contained no tests
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/discovery.py:276: warning: input '/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/Unit' contained no tests
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld.lld
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/lld-link
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld64.lld
llvm-lit: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/wasm-ld
-- Testing: 97383 tests, 64 workers --
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (1 of 97383)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Clang :: Driver/cl-options.c (2 of 97383)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-aarch64-Test/53/71 (3 of 97383)
PASS: Clang :: Driver/x86-target-features.c (4 of 97383)
PASS: MemorySanitizer-AARCH64 :: release_origin.c (5 of 97383)
PASS: LLVM :: CodeGen/ARM/build-attributes.ll (6 of 97383)
PASS: ScudoStandalone-Unit-GwpAsanTorture :: ./ScudoUnitTest-aarch64-Test/53/71 (7 of 97383)
PASS: UBSan-AddressSanitizer-aarch64 :: TestCases/ImplicitConversion/unsigned-integer-truncation-ignorelist.c (8 of 97383)
PASS: libFuzzer-aarch64-default-Linux :: merge-sigusr.test (9 of 97383)
PASS: Clang :: OpenMP/target_teams_distribute_codegen_registration.cpp (10 of 97383)
PASS: Clang :: Driver/clang_f_opts.c (11 of 97383)
PASS: Clang :: OpenMP/target_parallel_for_codegen_registration.cpp (12 of 97383)
PASS: Clang :: Headers/arm-neon-header.c (13 of 97383)
PASS: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp (14 of 97383)
PASS: UBSan-ThreadSanitizer-aarch64 :: TestCases/ImplicitConversion/signed-integer-truncation-ignorelist.c (15 of 97383)
PASS: UBSan-ThreadSanitizer-aarch64 :: TestCases/ImplicitConversion/unsigned-integer-truncation-ignorelist.c (16 of 97383)
PASS: libFuzzer-aarch64-default-Linux :: large.test (17 of 97383)
PASS: Clang :: Driver/linux-ld.c (18 of 97383)
PASS: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp (19 of 97383)
PASS: libFuzzer-aarch64-default-Linux :: value-profile-cmp.test (20 of 97383)
PASS: SanitizerCommon-ubsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (21 of 97383)
PASS: Clang :: CodeGen/X86/sse2-builtins.c (22 of 97383)
PASS: SanitizerCommon-lsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (23 of 97383)
PASS: Clang :: Preprocessor/predefined-arch-macros.c (24 of 97383)
PASS: HWAddressSanitizer-aarch64 :: TestCases/Linux/create-thread-stress.cpp (25 of 97383)
PASS: libFuzzer-aarch64-default-Linux :: fuzzer-timeout.test (26 of 97383)
PASS: Clang :: CodeGen/X86/rot-intrinsics.c (27 of 97383)
PASS: Clang :: CodeGen/X86/avx-builtins.c (28 of 97383)
PASS: SanitizerCommon-hwasan-aarch64-Linux :: Linux/signal_segv_handler.cpp (29 of 97383)
PASS: Clang :: Analysis/runtime-regression.c (30 of 97383)
PASS: SanitizerCommon-tsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (31 of 97383)
PASS: SanitizerCommon-asan-aarch64-Linux :: Linux/signal_segv_handler.cpp (32 of 97383)
PASS: SanitizerCommon-msan-aarch64-Linux :: Linux/signal_segv_handler.cpp (33 of 97383)
PASS: LLVM-Unit :: Support/./SupportTests/83/95 (34 of 97383)
PASS: ThreadSanitizer-aarch64 :: force_background_thread.cpp (35 of 97383)
PASS: Clang :: Analysis/a_flaky_crash.cpp (36 of 97383)
PASS: Clang :: Preprocessor/aarch64-target-features.c (37 of 97383)

@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 27, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vls-2stage running on linaro-g3-02 while building clang at step 12 "ninja check 2".

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

Here is the relevant piece of the build log for the reference
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/macro-def-undef.F90 (25119 of 97383)
PASS: Flang :: Driver/msvc-dependent-lib-flags.f90 (25120 of 97383)
PASS: Flang :: Driver/parse-error.ll (25121 of 97383)
PASS: Flang :: Driver/override-triple.ll (25122 of 97383)
PASS: Clangd Unit Tests :: ./ClangdTests/80/81 (25123 of 97383)
PASS: Flang :: Driver/print-resource-dir.F90 (25124 of 97383)
PASS: Flang :: Driver/print-effective-triple.f90 (25125 of 97383)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (25126 of 97383)
PASS: Flang :: Driver/bbc-openmp-version-macro.f90 (25127 of 97383)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (25128 of 97383)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (25129 of 97383)
PASS: Flang :: Driver/phases.f90 (25130 of 97383)
PASS: Flang :: Driver/implicit-none.f90 (25131 of 97383)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (25132 of 97383)
PASS: DataFlowSanitizer-aarch64 :: origin_ldst.c (25133 of 97383)
PASS: Flang :: Driver/parse-fir-error.ll (25134 of 97383)
PASS: Flang :: Driver/scanning-error.f95 (25135 of 97383)
PASS: Flang :: Driver/include-header.f90 (25136 of 97383)
PASS: Flang :: Driver/print-target-triple.f90 (25137 of 97383)
PASS: Flang :: Driver/print-pipeline-passes.f90 (25138 of 97383)
PASS: Flang :: Driver/fd-lines-as.f90 (25139 of 97383)
PASS: Flang :: Driver/pthread.f90 (25140 of 97383)
PASS: Flang :: Driver/parse-ir-error.f95 (25141 of 97383)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (25142 of 97383)
PASS: Flang :: Driver/std2018-wrong.f90 (25143 of 97383)
PASS: Flang :: Driver/missing-arg.f90 (25144 of 97383)
PASS: Flang :: Driver/pp-fixed-form.f90 (25145 of 97383)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (25146 of 97383)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (25147 of 97383)
PASS: Flang :: Driver/target-gpu-features.f90 (25148 of 97383)
PASS: Flang :: Driver/target.f90 (25149 of 97383)
PASS: Clangd Unit Tests :: ./ClangdTests/68/81 (25150 of 97383)
PASS: Flang :: Driver/linker-flags.f90 (25151 of 97383)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (25152 of 97383)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (25153 of 97383)
PASS: Flang :: Driver/q-unused-arguments.f90 (25154 of 97383)
PASS: Clangd Unit Tests :: ./ClangdTests/34/81 (25155 of 97383)
PASS: Clangd Unit Tests :: ./ClangdTests/71/81 (25156 of 97383)
PASS: Flang :: Driver/multiple-input-files.f90 (25157 of 97383)
PASS: Flang :: Driver/lto-bc.f90 (25158 of 97383)
PASS: Flang :: Driver/mllvm.f90 (25159 of 97383)
PASS: Flang :: Driver/unparse-with-modules.f90 (25160 of 97383)
PASS: Flang :: Driver/target-machine-error.f90 (25161 of 97383)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (25162 of 97383)
PASS: Flang :: Driver/no-duplicate-main.f90 (25163 of 97383)
PASS: Flang :: Driver/lto-flags.f90 (25164 of 97383)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants