Skip to content

Configure ci clang tidy report#338

Open
filipe-cuim wants to merge 32 commits intoeclipse-openbsw:mainfrom
filipe-cuim:ConfigureCIClangTidyReport
Open

Configure ci clang tidy report#338
filipe-cuim wants to merge 32 commits intoeclipse-openbsw:mainfrom
filipe-cuim:ConfigureCIClangTidyReport

Conversation

@filipe-cuim
Copy link
Contributor

@filipe-cuim filipe-cuim commented Dec 30, 2025

Description

The goal of this PR is to configure a .clang-tidy that respects openbsw coding conventions, and a ci job that runs clang-tidy checks on all compilation units that are generated in compile_commands.json.

In this first step we start with fewer clang-tidy checks enabled, because currently with all checks enabled the repository has around 3924 findings (excluding all files in test, 3rdparty and mock) and around 23386 findings (when excluding only 3rdparty folder).

Each clang-tidy CI workflow will print a report of all findings for each checker in stdout. After that it will also upload an artifact with a yaml file generated by clang-tidy, which will contain the location (both file name and file offset) of all findings.

There may also exist some checkers that we do not want to activate, and as such it's better to do small PRs after this one, where only few checkers are considered, in order to limit the amount of changes in the repository.

@filipe-cuim filipe-cuim marked this pull request as draft December 30, 2025 14:51
@filipe-cuim filipe-cuim force-pushed the ConfigureCIClangTidyReport branch 5 times, most recently from d256dec to 18cf424 Compare January 5, 2026 11:18
@filipe-cuim
Copy link
Contributor Author

Hello @rolandreichweinbmw @christian-schilling @hbragge-acn @johannes-esr let's maybe move the discussion here. In this PR I followed the suggestion of doing a full report of clang-tidy findings, instead of just checking a diff.

I tried to fix some of the warnings, but I didn't do it for all of them. There is a commit that addresses only one of the checkers.

I also focused on the posix build, and as such you will find in the s32k1xx build some warnings that supposedly were cleaned up in some of the commits.

There is also some clang-diagnostic-error which I'm not yet sure how to solve. These happen because clang-tidy looks to each compilation unit that is written in the compile_commands.json, and apparently some of these have invalid targets for unit test builds, and because of this CMake ignores those targets, and as such the compile commands becomes incomplete.
Usually these are libraries that depend on something from platforms which is not included in the unit test build, while their unit tests have the correct dependencies (which are different than the dependencies present in the library). An example is the CMake of bspOutputManager which depends on bspIo, while its unit tests depend on utbspIo.
Not sure if I should change the name of the targets to be the same for all (both target and unit test), or if I should change the CMakes somehow so that the compile_commands.json doesn't generate an entry for each library (and instead just for each executable for example).

Let me know what you think. Also, the checkers that I introduced came from a previous project, so I'm not really enforcing them. We may remove the ones you don't want to have.

Copy link
Contributor

@rolandreichweinbmw rolandreichweinbmw left a comment

Choose a reason for hiding this comment

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

Only put a few remarks.

Also: Are the included "Fix" commits directly related to clang-tidy findings? E.g. directly enabling a clean acceptable baseline? Otherwise, "unrelated" changes could be separated out to a cleanup PR.

@filipe-cuim
Copy link
Contributor Author

Only put a few remarks.

Also: Are the included "Fix" commits directly related to clang-tidy findings? E.g. directly enabling a clean acceptable baseline? Otherwise, "unrelated" changes could be separated out to a cleanup PR.

Theoretically yes, each commit is respective to one clang-tidy finding. So, in principle, if I remove one commit the PR should remain clean, or at least not needed many rebase changes

@filipe-cuim filipe-cuim force-pushed the ConfigureCIClangTidyReport branch 2 times, most recently from d829127 to 7d9d4f7 Compare January 20, 2026 11:10
@filipe-cuim filipe-cuim marked this pull request as ready for review January 20, 2026 11:10
@filipe-cuim filipe-cuim force-pushed the ConfigureCIClangTidyReport branch 4 times, most recently from b816b37 to 385b457 Compare January 26, 2026 17:02
@filipe-cuim filipe-cuim force-pushed the ConfigureCIClangTidyReport branch 4 times, most recently from 27cb498 to 3d404e2 Compare January 27, 2026 19:49
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
filipe-cuim and others added 19 commits January 28, 2026 17:38
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Signed-off-by: Filipe Cuim <filipe.cuim@ctw.bmwgroup.com>
Copy link

@simon-d-bmw simon-d-bmw left a comment

Choose a reason for hiding this comment

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

@filipe-cuim there are still 7 clang-diagnostic-errors remaining.


Additionally, most of these practices are enforced by clang-tidy which is run as part of our CI pipeline.
The clang-tidy configuration can be found in the file ``.clang-tidy`` in the root directory of openbsw repository.
The ci script for running clang-tidy is located in ``.ci/clang-tidy.py``, which runs an llvm helper tool called
Copy link

@simon-d-bmw simon-d-bmw Jan 29, 2026

Choose a reason for hiding this comment

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

nit:

Suggested change
The ci script for running clang-tidy is located in ``.ci/clang-tidy.py``, which runs an llvm helper tool called
The CI script for running clang-tidy is located in ``.ci/clang-tidy.py``, which runs an llvm helper tool called

Comment on lines +40 to +44
parser.add_argument(
"--build_directory",
type=Path,
help="Path to the build directory containing compile_commands.json generated by CMake",
)
Copy link

@simon-d-bmw simon-d-bmw Feb 2, 2026

Choose a reason for hiding this comment

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

nit:

Suggested change
parser.add_argument(
"--build_directory",
type=Path,
help="Path to the build directory containing compile_commands.json generated by CMake",
)
parser.add_argument(
"--build_directory",
type=Path,
help="Path to the build directory containing compile_commands.json generated by CMake",
required=True
)

parser.add_argument(
"--output_file",
type=str,
help="Path to the output YAML file where clang-tidy findings will be stored",
Copy link

@simon-d-bmw simon-d-bmw Feb 2, 2026

Choose a reason for hiding this comment

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

nit:

Suggested change
help="Path to the output YAML file where clang-tidy findings will be stored",
help="Path to the output YAML file where clang-tidy findings will be stored",
required=True

python3 .ci/clang-tidy.py --build_directory=build/tests/${{ matrix.platform }}/${{ matrix.config }} --output_file=ct-findings.yaml --exclude="3rdparty" --ignore-checks="clang-diagnostic-error"

- name: Upload clang-tidy findings
if: always()
Copy link

@simon-d-bmw simon-d-bmw Feb 2, 2026

Choose a reason for hiding this comment

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

nit: can't we skip this upload if the output file doesn't exist?

{
// 64 = 8 byte payload
// 53 = CAN overhead
// NOLINTNEXTLINE(clang-analyzer-core.DivideZero): CAN Baudrate can never be zero here.
Copy link
Contributor

Choose a reason for hiding this comment

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

@filipe-cuim , just a quick question: Have you ever experimented with __builtin_assume()? I know this might introduce portability issues, but I was generally curious if the could work in such cases.

@matthiaskessler
Copy link
Contributor

Interesting...I was actually trying to review and approve commit by commit but that doesn't seem to work...

using namespace ::runtime;
using namespace ::estd::test;

// NOLINTBEGIN(cert-oop54-cpp): This is intentional for testing purposes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, if it's an alias, we should only check for one rule.

using namespace ::runtime;
using namespace ::estd::test;

// NOLINTBEGIN(cert-oop54-cpp): This is intentional for testing purposes.
Copy link
Contributor

Choose a reason for hiding this comment

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

According to here the two rules are aliased. If that's the case, we should only have suppressions for one.

// NOLINTBEGIN(bugprone-reserved-identifier): Explanation for this suppression is below
/**
* \par Linking this module
* The diab compiler is providing these methods for char in-/output. They will
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, we need to review this since we are using gcc and clang.

{
#endif

// NOLINTBEGIN(cert-dcl51-cpp): Explanation for this suppression is below
Copy link
Contributor

Choose a reason for hiding this comment

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

According to here
these rules are aliases. I don't think we should suppress each of them but decide to use only one rule.

}

#ifdef UNIT_TEST
static void unsetDiagSession() { sfpSessionManager = nullptr; }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd call it unsetDiagSessionManager() to have a clear distiction between session manager and the actual session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants