[WIP]Memory Ownership Annotations
Description
This pull request focuses on improving code clarity and consistency. The changes include:
- Adding memory ownership annotations to improve code documentation and enable better static analysis.
- Standardizing function declarations by explicitly including
voidin parameter lists for consistency. - Introducing the
CELIX_HAS_ATTRIBUTEmacro to check for attribute support. - Improved Formatting and Grammar: Fixed typos, improved clarity in comments, and ensured consistency in phrasing following CLion's suggestions.
Usage
Enable the following clang-tidy checks to see its effects:
- clang-analyzer-unix.DynamicMemoryModeling
- clang-analyzer-unix.Malloc
- clang-analyzer-unix.MallocSizeof
- clang-analyzer-unix.MismatchedDeallocator
Both vscode and Clion IDE have good integrations with clang-tidy.
Limitations
- Clang Static Analyzer does not model cleanup attribute properly, see https://github.com/llvm/llvm-project/issues/160527
ownership_returnscan only be used to mark functions returning their allocations through return values, i.e., output parameter is not supported, see https://github.com/llvm/llvm-project/issues/166122
The first issue leads to lots of false-positives, which can fortunately be suppressed using NOLINT macros. I will try to fix both issues in the Clang upstream.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 91.47%. Comparing base (6418698) to head (245a3a2).
Additional details and impacted files
@@ Coverage Diff @@
## master #806 +/- ##
==========================================
- Coverage 91.52% 91.47% -0.06%
==========================================
Files 236 236
Lines 29561 28818 -743
==========================================
- Hits 27057 26361 -696
+ Misses 2504 2457 -47
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Should we also add clang-tidy to our CI?
Yes.
For the usage of '(void)' for an explicit empty argument list, maybe this should also be added to our coding conventions documentation.
And ideally when to use 'CELIX_OWNERSHIP_RETURNS', '_TAKES' and ' _HOLDS' should also be documented.
I am currently working on fixing the cleanup attributes modeling issue, and will follow the above suggestions once it's done.