dist/tools/coccinelle: add patch to fix asserts with side-effects#22200
Draft
maribu wants to merge 2 commits intoRIOT-OS:masterfrom
Draft
dist/tools/coccinelle: add patch to fix asserts with side-effects#22200maribu wants to merge 2 commits intoRIOT-OS:masterfrom
maribu wants to merge 2 commits intoRIOT-OS:masterfrom
Conversation
This adds a semantic patch to replace ```C assert(do_something() == 0); ``` with ```C typeof(do_something()) tmp = do_something(); (void)tmp; assert(tmp == 0); ``` The reasoning that `do_something()` likely has side-effects and compilation with `-DNDEBUG` results in incorrect behavior. A list of some 50 pure functions that safely can be used in `assert()` and are used in `assert()` has been added to disable all current false positives.
Member
Author
|
Not sure if we really want to merge this. It will force people adding some new On the other hand, it would prevent a certain flavor footguns from being merged. |
kfessel
requested changes
Apr 20, 2026
Contributor
kfessel
left a comment
There was a problem hiding this comment.
assume should not be covert as its side effects are are effective regardless of NDEBUG
…ects Co-authored-by: Karl Fessel <karl.fessel@ml-pa.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
This adds a semantic patch to replace
with
The reasoning that
do_something()likely has side-effects and compilation with-DNDEBUGresults in incorrect behavior.A list of some 50 pure functions that safely can be used in
assert()and are used inassert()has been added to disable all current false positives.Testing procedure
Adding some
assert(do_something())should now result in the CI detecting the issue.Issues/PRs references
None
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: