Implemented support for bit-field members as a loop variable
or upper limit. Supporting also non bit-field integer members.
Fixes issues: https://github.com/llvm/llvm-project/issues/58614
Paths
| Differential D142587
[clang-tidy] Improved too-small-loop-variable with bit-field support ClosedPublic Authored by PiotrZSL on Jan 25 2023, 3:05 PM.
Details Summary Implemented support for bit-field members as a loop variable Fixes issues: https://github.com/llvm/llvm-project/issues/58614
Diff Detail
Event TimelineEugene.Zelenko added reviewers: aaron.ballman, hokein, gribozavr2, carlosgalvezp.Jan 25 2023, 3:36 PM Comment Actions Thanks for the fix! I have some suggestions for improved readability.
Comment Actions @carlosgalvezp: Sorry, there are too much Clang specifics in this patch, so I could not be reviewer. Comment Actions
No prob, thanks for letting us know :) This revision is now accepted and ready to land.Feb 26 2023, 3:44 AM Closed by commit rGc7dac52203a0: [clang-tidy] Improved too-small-loop-variable with bit-field support (authored by PiotrZSL). · Explain WhyFeb 26 2023, 6:54 AM This revision was automatically updated to reflect the committed changes. Comment Actions Hi typedef struct S { int x:4; } S; void foo(S s) { for (int i=10; i > s.x; --i) ; } loop_var.c:6:22: warning: loop variable has narrower type 'int:4' than iteration's upper bound 'int' [bugprone-too-small-loop-variable] for (int i=10; i > s.x; --i) ; ^ Looks like the logic i reversed here, so the loop variable gets the bit field type. Comment Actions Thank you for information, I will look into this....
Revision Contents
Diff 500523 clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/too-small-loop-variable.cpp
|
Having an std::pair is a bit hard to read, as it's not clear what each element of the pair represents. Could you replace it with something like this, for improved readability and maintainability? Then you can also skip the utility header.