Skip to content

[Clang-tidy] Fix warning for uninitialized vars in fallbackReduction.hpp#1423

Merged
tdavidcl merged 3 commits into
Shamrock-code:mainfrom
Akos299:features/clang-tidy-fix-2
Dec 14, 2025
Merged

[Clang-tidy] Fix warning for uninitialized vars in fallbackReduction.hpp#1423
tdavidcl merged 3 commits into
Shamrock-code:mainfrom
Akos299:features/clang-tidy-fix-2

Conversation

@Akos299

@Akos299 Akos299 commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

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;

@Akos299 Akos299 requested a review from tdavidcl December 12, 2025 08:38
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 FallbackReduction implementation. By explicitly initializing accumulator variables in the _int_sum, _int_min, and _int_max functions, the changes prevent potential undefined behavior and enhance the robustness of the reduction algorithms.

Highlights

  • Clang-tidy Warning Fix: Addressed Clang-tidy warnings regarding uninitialized variables in FallbackReduction functions by providing explicit initial values for accumulator variables.
  • Accumulator Initialization: Ensured accum variables in _int_sum, _int_min, and _int_max functions are correctly initialized to prevent undefined behavior.
  • Header Dependencies: Included necessary headers (shambase/numeric_limits.hpp, <cassert>, <limits>) to support the new initialization logic for min/max operations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp Outdated
[Clang-tidy] Fix warning for Calling 'FallbackReduction::sum'

updates
@tdavidcl tdavidcl changed the title [Clang-tidy] Fix warning for Calling 'FallbackReduction::sum' [Clang-tidy] Fix warning for uninitialized vars in fallbackReduction.hpp Dec 13, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 8fe2f06
Commiter email is timothee.davidcleris@proton.me
GitHub page artifact URL GitHub page artifact link (can expire)

Pre-commit check report

Pre-commit check: ✅

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check for merge conflicts................................................Passed
check that executables have shebangs.....................................Passed
check that scripts with shebangs are executable..........................Passed
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check for broken symlinks................................................Passed
check yaml...............................................................Passed
detect private key.......................................................Passed
No-tabs checker..........................................................Passed
Tabs remover.............................................................Passed
Validate GitHub Workflows................................................Passed
clang-format.............................................................Passed
black....................................................................Passed
ruff check...............................................................Passed
Check doxygen headers....................................................Passed
Check license headers....................................................Passed
Check #pragma once.......................................................Passed
Check SYCL #include......................................................Passed
No ssh in git submodules remote..........................................Passed

Test pipeline can run.

Clang-tidy diff report

No relevant changes found.
Well done!

You should now go back to your normal life and enjoy a hopefully sunny day while waiting for the review.

Doxygen diff with main

Removed warnings : 7
New warnings : 7
Warnings count : 7417 → 7417 (0.0%)

Detailed changes :
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:25: warning: Compound shamalgs::reduction::details::FallbackReduction is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:27: warning: Compound shamalgs::reduction::details::FallbackReduction is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:27: warning: Member sum(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:29: warning: Member min(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:29: warning: Member sum(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:31: warning: Member max(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:31: warning: Member min(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:33: warning: Member max(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of struct shamalgs::reduction::details::FallbackReduction is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:35: warning: Member _int_sum(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:37: warning: Member _int_sum(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:54: warning: Member _int_min(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:56: warning: Member _int_min(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.
- src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:73: warning: Member _int_max(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.
+ src/shamalgs/include/shamalgs/details/reduction/fallbackReduction.hpp:75: warning: Member _int_max(sycl::queue &q, sycl::buffer< T > &buf1, u32 start_id, u32 end_id) (function) of namespace shamalgs::reduction::details is not documented.

@tdavidcl tdavidcl merged commit 9f14dda into Shamrock-code:main Dec 14, 2025
58 checks passed
DavidFang03 pushed a commit to DavidFang03/Shamrock that referenced this pull request Dec 16, 2025
…hpp (Shamrock-code#1423)

Co-authored-by: David--Cléris Timothée <timothee.davidcleris@proton.me>
@Akos299 Akos299 deleted the features/clang-tidy-fix-2 branch February 16, 2026 14:42
aserhani pushed a commit to aserhani/Shamrock that referenced this pull request Feb 23, 2026
…hpp (Shamrock-code#1423)

Co-authored-by: David--Cléris Timothée <timothee.davidcleris@proton.me>
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.

2 participants