Skip to content

[Clang-tidy] fix warning for Tscal used as loop counter#1424

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

[Clang-tidy] fix warning for Tscal used as loop counter#1424
tdavidcl merged 4 commits into
Shamrock-code:mainfrom
Akos299:features/clang-tidy-fix-3

Conversation

@Akos299

@Akos299 Akos299 commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

warning: Variable 'x' with floating point type 'Tscal' should not be used as a loop counter [clang-analyzer-security.FloatLoopCounter]
85 | for (Tscal x = 0; x < Ker::Rkern; x += step) {...};

Replaced the foor loop by a while loop.

@Akos299 Akos299 requested a review from tdavidcl December 12, 2025 09:58
@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 a clang-tidy warning related to the use of floating-point types as loop counters. The change improves code quality and adheres to best practices for numerical stability by replacing a for loop with a while loop in a test file, ensuring the test logic remains sound while eliminating the potential for precision issues.

Highlights

  • Clang-tidy Warning Fix: Addressed a clang-analyzer-security.FloatLoopCounter warning by refactoring a for loop that used a floating-point Tscal variable as its counter into an equivalent while loop.
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 addresses the clang-tidy warning about using a floating-point type as a loop counter by replacing the for loop with a while loop. The change is functionally correct.

I've added one comment suggesting the removal of the old, commented-out code to improve maintainability.

Additionally, I noticed a few other places in the codebase that also use floating-point loop counters (e.g., in src/shammath/include/shammath/integrator.hpp:27 and src/tests/shammath/sphkernelsTests.cpp:226). It would be beneficial to address these in a follow-up pull request to ensure consistency and robustness across the project.

Comment thread src/tests/shammath/sphkernelsTests.cpp Outdated
Comment thread src/tests/shammath/sphkernelsTests.cpp Outdated
@tdavidcl

Copy link
Copy Markdown
Member

/gemini review

@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 addresses a clang-tidy warning about using a floating-point variable as a loop counter by converting a for loop to a while loop. While this silences the warning, it doesn't fix the underlying potential for floating-point precision issues. I've suggested a more robust approach using an integer-based loop, which avoids the accumulation of floating-point errors and makes the code more reliable.

Comment thread src/tests/shammath/sphkernelsTests.cpp Outdated
[Clang-tidy] fix warning for Tscal used as loop counter

Replace for loop by a while loop.

updates
@Akos299 Akos299 force-pushed the features/clang-tidy-fix-3 branch from 8fb791d to 0033f6d Compare December 12, 2025 10:36
@tdavidcl

Copy link
Copy Markdown
Member

/gemini review

@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 resolves a clang-tidy warning about using a floating-point type as a loop counter. The change from a float-based for loop to an integer-based one is a standard and safe practice to avoid issues with floating-point precision. The implementation, which calculates the number of iterations beforehand using std::ceil, is robust and correctly maintains the original loop's logic. The addition of the <cmath> header is also appropriate. Overall, this is a good, focused fix that improves code quality.

@github-actions

Copy link
Copy Markdown
Contributor

Workflow report

workflow report corresponding to commit 9a78a9b
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 : 0
New warnings : 0
Warnings count : 7417 → 7417 (0.0%)

Detailed changes :

@tdavidcl tdavidcl merged commit 0cd5879 into Shamrock-code:main Dec 13, 2025
55 checks passed
@Akos299 Akos299 deleted the features/clang-tidy-fix-3 branch February 16, 2026 14:42
aserhani pushed a commit to aserhani/Shamrock that referenced this pull request Feb 23, 2026
…e#1424)

warning: Variable 'x' with floating point type 'Tscal' should not be
used as a loop counter [clang-analyzer-security.FloatLoopCounter]
   85 |     for (Tscal x = 0; x < Ker::Rkern; x += step) {...};

Replaced the foor loop by a while loop.

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