-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add clang-tidy
support for static code analysis
#2648
Conversation
d4d6732
to
b16ddf5
Compare
b16ddf5
to
2bd33be
Compare
clang-tidy
support for static code analysis
e0b6772
to
4b9fc84
Compare
This PR proposes some changes to the Hosted classes **Update simpleRPC to master** With clang-tidy #2648 some failures occur in the `simpleRPC` library. Updating this to current master solves the issues. I've also put all the code into the `simpleRPC` namespace which sorts out the conflict with `Vector` but makes it available for use if required. **Tidy HostTests module** Also decode the anonymous 'packet' blob so we can see what's in it and compare with spec. should we wish to update it. **Use abstract base class for callbacks** Simplifies implementation since usually all callbacks are required. Compiler ensures all methods have implementations. `clang-tidy` gave potential memory leak indication because of Delegates. Not sure if that's real but this fixes it.
Code doesn't get compiled so skip linking stage. Remove `ENABLE_CLANG_TIDY`, use `CLANG_TIDY`, allows specific versions of clang-tidy to be used.
e.g. cannot use `static_cast` so FlashString needs some fudging to get it to compile. Also clang doesn't support constexpr math (yet) so workaround that.
Compiler can optimise ones in headers, but a few others worth doing
Because CSocket virtual destructor calls virtual `close` method which doesn't behave as expected. This one's simple to fix but there are some other cases in the framework (Networking) which will need to be looked at separately.
4b9fc84
to
1ed7de3
Compare
I'm starting to get a feel for the power of this tool! For example:
Will apply a single class of fix across the entire codebase. And the results are consistent and work very well. Same is not true for all checks but I think this is probably the way to go when we decide to apply these sorts of changes. What I'm currently not seeing is an easy way to track changes made into submodules... We should consider globally applying these fixes across the codebase (either in this PR or a separate one): |
1ed7de3
to
96aeb44
Compare
clang-tidy
support for static code analysisclang-tidy
support for static code analysis
96aeb44
to
ca72592
Compare
This PR adds the `CLANG_BUILD` for host builds. The toolchain detection logic is in the main build.mk file as there might be future support for clang toolchains for actual devices. It's also a revision to the existing logic which checks GCC compiler version. Try it out using `make SMING_SOC=host CLANG_BUILD=1`. To build with a specific (installed) version of clang, for example clang-15, use `CLANG_BUILD=15` . Further customisation can be made by editing `Sming/Arch/Host/build.mk`. Clang-tidy support (#2648) is also improved as there are some compiler flag differences between GCC and clang which are now shared between CLANG_TIDY and CLANG_BUILD operation. An extra CI build has been added using clang. Further to #2773, the default toolchain for macos is a version of clang (Apple Clang). This PR doesn't quite support that because there are other issues to address, but it's a step in the right direction.
This PR allows static code analysis using clang-tidy, suggested by #2616.
Clang has more limited
constexpr
support than GCC so cannot parse some of the FlashString and NanoTime code without modification. However, these changes are only made when__clang__
is defined and do not affect regular builds with GCC.This PR also includes some basic code fixes which clang identifies. There are a lot more to look at.
To try it out, build a project with:
Add additional parameters like this:
Notes:
-j
option as clang-tidy output and fixes don't get serialised correctly..clang-tidy
file. A custom version can be used and passed on the command line.