[Clang-tidy] Fix warning for uninitialized vars in fallbackReduction.hpp#1423
Conversation
Summary of ChangesHello @Akos299, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves Clang-tidy warnings related to uninitialized variables within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a critical bug identified by clang-tidy where accumulator variables in reduction functions could be uninitialized, leading to undefined behavior for empty ranges. By initializing accum in _int_sum, _int_min, and _int_max to the appropriate identity value, the code is now safer and more correct. I've added one comment regarding unnecessary header includes that can be cleaned up. Additionally, it's worth noting that with these initializations in place, the if (idx == start_id) checks within the reduction loops are now redundant. Removing this conditional logic would simplify the code and improve performance by eliminating a branch inside the loop. This could be a good candidate for a follow-up refactoring.
[Clang-tidy] Fix warning for Calling 'FallbackReduction::sum' updates
7ccfd05 to
0168edc
Compare
Workflow reportworkflow report corresponding to commit 8fe2f06 Pre-commit check reportPre-commit check: ✅ Test pipeline can run. Clang-tidy diff reportNo relevant changes found. You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review. Doxygen diff with
|
…hpp (Shamrock-code#1423) Co-authored-by: David--Cléris Timothée <timothee.davidcleris@proton.me>
…hpp (Shamrock-code#1423) Co-authored-by: David--Cléris Timothée <timothee.davidcleris@proton.me>
note: Calling 'FallbackReduction::sum'
672 | T sum = shamalgs::reduction::details::FallbackReduction::sum(
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
673 | shamsys::instance::get_compute_queue(), buf, 0, sz);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/__w/Shamrock/Shamrock/src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:95:16: note: Calling '_int_sum'
95 | return _int_sum(q, buf1, start_id, end_id);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/__w/Shamrock/Shamrock/src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:36:9: note: 'accum' declared without an initial value
36 | T accum;
| ^~~~~~~
/__w/Shamrock/Shamrock/src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:41:38: note: Assuming 'idx' is >= 'end_id'
41 | for (u32 idx = start_id; idx < end_id; idx++) {
| ^~~~~~~~~~~~
/__w/Shamrock/Shamrock/src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:41:13: note: Loop condition is false. Execution continues on line 50
41 | for (u32 idx = start_id; idx < end_id; idx++) {
| ^
/__w/Shamrock/Shamrock/src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:50:9: note: Undefined or garbage value returned to caller
50 | return accum;