Skip to content
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

dist/tools/cppcheck: improve warnings #17300

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

maribu
Copy link
Member

@maribu maribu commented Nov 30, 2021

Contribution description

  • provide include paths and defines of samr21-xpro
  • provide platform configuration for Cortex-M MCUs
  • detect include paths of all modules by searching for include folders in core, drivers, and sys
  • filter out files in cpu/* and boards/* before checking, as those depend on board/architecture specific include paths and defines
  • re-enable cppcheck in the CI
  • drop some suppressions of false positives in sys/net/grnc that should no longer pop up with the proper type definitions now around

Testing procedure

At least some of the dropped suppressions should no longer be needed. (Note: None of these is needed with the latest cppcheck, but other warnings are generated instead.)

Issues/PRs references

#17282

- provide include paths and defines of samr21-xpro
- provide platform configuration for Cortex-M MCUs
- detect include paths of all modules by searching for include folders
  in core, drivers, and sys
- filter out files in cpu/* and boards/* before checking, as those
  depend on board/architecture specific include paths and defines
@maribu maribu added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: CI Area: Continuous Integration of RIOT components CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs labels Nov 30, 2021
@github-actions github-actions bot added Area: doc Area: Documentation Area: LoRa Area: LoRa radio support Area: network Area: Networking Area: sys Area: System Area: tools Area: Supplementary tools and removed Area: CI Area: Continuous Integration of RIOT components labels Nov 30, 2021
@maribu maribu added Area: CI Area: Continuous Integration of RIOT components and removed Area: doc Area: Documentation Area: LoRa Area: LoRa radio support Area: network Area: Networking Area: sys Area: System labels Nov 30, 2021
@@ -248,9 +248,6 @@ static int _receive(gnrc_pktsnip_t *pkt)
mutex_unlock(&list->lock);

/* Call FSM with event RCVD_PKT if a fitting TCB was found */
/* cppcheck-suppress knownConditionTrueFalse
* (reason: tcb can be NULL at runtime)
*/
if (tcb != NULL) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Here the warning of cppcheck is correct: tcb must be NULL, since the while (tcb) has no break in it except when MODULE_GNRC_IPV6 is defined (which cppcheck assumes to not be the case).

@maribu
Copy link
Member Author

maribu commented Nov 30, 2021

@brummer-simon @miri64: What was the reasoning behind this:

#else
/* Suppress compiler warnings if TCP is built without network layer */
TCP_DEBUG_ERROR("Missing network layer. Add module to makefile.");
(void) syn;
(void) src;
(void) dst;
#endif

Isn't this one of the "we know your configuration is broken at build time, but we still emit a firmware that you can spent on hours debugging" cases that @benpicco is such a huge fan of?

Why not add

#ifndef MODULE_GNRC_IPV6
#error "module gnrc_ipv6 required but not used"
#endif

for ease of mind and model the dependency so that this cannot happen?

@brummer-simon
Copy link
Member

brummer-simon commented Nov 30, 2021

@brummer-simon @miri64: What was the reasoning behind this:

#else
/* Suppress compiler warnings if TCP is built without network layer */
TCP_DEBUG_ERROR("Missing network layer. Add module to makefile.");
(void) syn;
(void) src;
(void) dst;
#endif

Isn't this one of the "we know your configuration is broken at build time, but we still emit a firmware that you can spent on hours debugging" cases that @benpicco is such a huge fan of?

Why not add

#ifndef MODULE_GNRC_IPV6
#error "module gnrc_ipv6 required but not used"
#endif

for ease of mind and model the dependency so that this cannot happen?

Good question regarding the reasoning. In general I am favor of breaking things at build time.
Feel free to remove these and similar macros. There should be a few like this within GNRC_TCP.

@benpicco
Copy link
Contributor

benpicco commented Feb 4, 2022

Is this waiting for anything?
The changes look good!

@github-actions github-actions bot added Area: doc Area: Documentation and removed Area: CI Area: Continuous Integration of RIOT components labels Feb 4, 2022
@maribu
Copy link
Member Author

maribu commented Feb 4, 2022

I dropped the last commit disabling some of the cppcheck suppression, which were mostly still needed. I don't have locally the old version of cppcheck used in the CI installed, so it is some effort for me to remove only unneeded suppressions. That should be easier once the CI is updated.

@benpicco
Copy link
Contributor

benpicco commented Feb 4, 2022

Ugh if this brings back the need to litter the code with cppcheck suppression comments just to get it though CI, we should wait with merging it until CI has been updated.

@maribu
Copy link
Member Author

maribu commented Feb 5, 2022

+1

@benpicco
Copy link
Contributor

benpicco commented Jun 1, 2022

Is CI sufficiently up to date now that we can give this another try?

@maribu
Copy link
Member Author

maribu commented Jun 2, 2022

good question. Maybe @kaspar030 knows?

@maribu
Copy link
Member Author

maribu commented Jun 2, 2022

Maybe it would also make sense to just build it from source. Having top notch static analysis is helpful. Speaking of that, both LLVM and GCC have static analysis tools that at least from the outside look more promising than cppcheck. That isn't supposed to be an argument against also using cppcheck in addition. Once the false positive rate gets acceptable, any additional tool that increase coverage will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: tools Area: Supplementary tools CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants