Add clang tidy CI test & tools to use it locally#1303
Add clang tidy CI test & tools to use it locally#1303AlexanderSinn merged 38 commits intoHi-PACE:developmentfrom
Conversation
|
Hei @AlexanderSinn, do you think that this could be a useful tool? |
|
The way I currently think about it, it is only useful if it runs as part of CI and has some more powerful checks enabled that can detect and prevent actual potential bugs. If it is just a script, then I think it will rarely be used in practice and constantly break over time from PRs not using the script. However, as a CI test, it should finish in less than 15 minutes (for the case of many checks enabled but no errors found) to not be slower compared to the other CI tests that we have. |
Oh, yes, sorry, I failed to explain it properly. My intention is to finally (either in this PR or in another one) make a CI test that runs this script. The advantage of also having the script in We can progressively add more checks to |
|
@AlexanderSinn , what do you think about this ? I've added a new CI test that uses |
|
Ping, @AlexanderSinn ;-) |
src/utils/MultiBuffer.cpp
Outdated
| num_particles * sizeof(std::uint64_t)); | ||
| } | ||
| else{ | ||
| amrex::Abort("bo.m_beam_idcpu[" + std::to_string(b) + "] has no value!"); |
There was a problem hiding this comment.
This seems much worse than the original code. The .value() function was used deliberately to get the value if it exists and give an error if it doesn't. The way the code is now, an error should never be triggered; it is there only to catch mistakes if changes are made to it. The same is done below with std::map by using .at() instead of operator[]. The .has_value() and amrex::Abort combination does the same thing in a much more verbose way. Can you use the original version with .value() and add a NOLINT comment, here and below? It would be good to give an example of how to do that.
There was a problem hiding this comment.
I see the intent, now. Then the best solution is probably to add the option IgnoreValueCalls for this check. What do you think ?
There was a problem hiding this comment.
(instead of a NOLINT)
There was a problem hiding this comment.
bugprone-unchecked-optional-access
There was a problem hiding this comment.
btw, do you prefer writing explicitly all the enabled & disabled checks ?
As it is now, it is like "all the checks of the bugprone family except..."
There was a problem hiding this comment.
Since there are quite a lot of bugprone- checks enabled now, I think it is best how it is now.
There was a problem hiding this comment.
weird... it does not work. Maybe the version of clan-tidy is too old ?
There was a problem hiding this comment.
Is it possible to add "all the checks of the bugprone family except..." as a comment in the clang-tidy file?
There was a problem hiding this comment.
Ah, yes, that option was introduced after clang-tidy v 20
Co-authored-by: Alexander Sinn <[email protected]>
|
The output if it fails is actually quite nice: |
1849513 to
3d70f1f
Compare
Sorry, it was not clear in what I wrote before. The option to silence this check for |
|
@AlexanderSinn , since I can't disable the warning about the |
|
Ok! It seems to work now., @AlexanderSinn . |
This PR adds a
.clang-tidyconfiguration file and a script to runclang-tidylocally, as well as a CI test that runsclang-tidywith the rules specified in the configuration file. Some issues found with the tool are also fixed.The
clang-tidyconfiguration file at the moment enables most of the checks of thebugprone-family, as well ascppcoreguidelines-avoid-goto. More checks will be added in future PRs.The script
tools/runClangTidy.shwrites a smallclang-tidywrapper in order to avoid using it on AMReX and OpenPMD source files. This script can be run by doing:The compilation is done in the folder
build_clang_tidyand the output of the tool is written tobuild_clang_tidy/clang-tidy.logThe new
clang-tidyCI test is define ingithub/workflows/clangtidy.yml(note that since we're compiling withclangin this test I have removed the comments at the end ofgithub/workflows/linux.ymland I have updated thesetup/ubuntu_clang.shscript to install the new required dependencies).The PR also fixes these issues found with the new CI test:
src/mg_solver/HpMultiGrid.H: a default case is added to two switch statements to respect the rule bugprone-switch-missing-default-casesrc/mg_solver/HpMultiGrid.Handsrc/mg_solver/HpMultiGrid.cpptwo variables are declared only ifAMREX_USE_GPUis defined (otherwise they are flagged as unused byclang)src/utils/MultiBuffer.cpp:checks are added to respect the rule bugprone-unchecked-optional-accessaNOLINTis used to silence an inappropriate[bugprone-unchecked-optional-access]warning.already done in Remove unused PhysConst #1317src/particles/beam/BeamParticleContainer.cppandsrc/particles/plasma/PlasmaParticleContainer.cpp: remove two unused variablesThis PR is a follow-up of #1302
constisconst)