Skip to content

ci: add clang-tidy and clang-tidy-fix targets#242

Merged
andreiltd merged 28 commits intobytecodealliance:mainfrom
andreiltd:clang-tidy
Aug 29, 2025
Merged

ci: add clang-tidy and clang-tidy-fix targets#242
andreiltd merged 28 commits intobytecodealliance:mainfrom
andreiltd:clang-tidy

Conversation

@andreiltd
Copy link
Copy Markdown
Member

This enables clang based linting over c++ codebase. There are two new targets:

  • just lint - runs clang-tidy on the codebase
  • just lint-fix - runs clang-tidy with -fix option to automatically fix issues

The .clang-tidy file contains minimal configuration to get us started. See enabled Checks.

I was hoping to start the discussion on linting StarlingMonkey in general:

  • do we want linting at all,
  • should we try to apply the offered fixes,
  • should we run the checks on CI,
  • should we enforce the checks on PRs?

I hope we can review the errors from the linter and decide which are just the noise and which we want to fix.

cc: @tschneidereit

@tschneidereit
Copy link
Copy Markdown
Member

tschneidereit commented Apr 25, 2025

Some quick responses:

  • do we want linting at all,

Yes, I absolutely think we do

  • should we try to apply the offered fixes,

I haven't looked at them, but as long as none stick out as very annoying, I'm all for sticking with formatting defaults.

  • should we run the checks on CI,

Yes :)

  • should we enforce the checks on PRs?

Yes :)

The reason for the last two "yes"s is that that'll help avoid the situation where patches mix functional and formatting changes, making it much harder to identify the former.

@andreiltd
Copy link
Copy Markdown
Member Author

Thanks! OK, I will move this PR to draft then and try to come up with sensible lint defaults and fixes.

@andreiltd andreiltd marked this pull request as draft April 25, 2025 15:47
@tschneidereit
Copy link
Copy Markdown
Member

This looks good to me, fwiw. Feel free to un-draft and land this once you feel comfortable with it

andreiltd and others added 3 commits August 18, 2025 09:22
This is needed to build compile_command.json file that clang-tidy uses.
These are various fixes reported by clang-analyzer regarding memory
leaks, unsafe functions and inconsistent use use of new and free.
This changes script loader paths to use owned string instead of raw
pointers to fix potential memory leaks reported by clang. The tradeof is
that now we call c_str in few places, but the impact on performance
should be negligible since we call this only once.
This patch enables cppcoreguidelines but disables all the lints that
don't offer auto fixes.
This patch enables modernize lints and disable all lints from this group
that are not offering auto fix.
This fixes linter error, where clang complains about using new/free
instead of new/delete.
@andreiltd andreiltd marked this pull request as ready for review August 18, 2025 22:56
@andreiltd
Copy link
Copy Markdown
Member Author

Hey @tschneidereit, while this PR is rather large, I've tried my best to keep individual commits logically separated. Each commit includes:

  • Enabling a specific linter group
  • Fixes for the associated lint errors

I've also added a CI step to run the clang-tidy checks automatically but I wonder if I should maybe move this to separate workflow to parallelize the job. The tests are already taking a long time.

Copy link
Copy Markdown
Member

@tschneidereit tschneidereit left a comment

Choose a reason for hiding this comment

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

Thank you for this! I skimmed most of the files, and looked more closely at the first few (up to blob.cpp).

Mostly, the changes look very good to me. There are a few weird formatting issues though, where however you inserted or removed curly braces seems to have removed line breaks. It'd be great if you could look for those with a regex and fix them in one go.

Additionally, I left a comment on the first occurrence of a bool check that has been expanded to a comparison, in that case with nullptr. I'm not convinced we want those changes, myself. Ironically enough, in many cases I don't even think they're somehow "more correct": I don't think comparing a RootedObject or HandleObject with nullptr is particularly closer to some ground truth than comparing it to true (and then shortening the latter).

As I said in the inline comment, I'm not necessarily asking you to revert all those changes—but I also wouldn't be opposed to it 😬 I guess for now I'm more interested in hearing the reasoning, because I might simply be wrong.

@andreiltd
Copy link
Copy Markdown
Member Author

It'd be great if you could look for those with a regex and fix them in one go.

Maybe it's worth, to just run clang format on the codebase as a very last commit in this PR?

@andreiltd
Copy link
Copy Markdown
Member Author

andreiltd commented Aug 19, 2025

I kept my janitor hat on for a little bit longer and cleaned up clang diagnostics for invalid offsetof and disabled the warning globally with the last commit.

While disabling this warning is not ideal, starting from version 20.0, clang introduces the suppression maps option so we can selectively disable the warning only in problematic header files:

https://clang.llvm.org/docs/WarningSuppressionMappings.html

If it's OK, I will add an issue to remove the -Wno-invalid-offsetof compile flag and replace it with suppression mapping when we switch to the next wasi-sdk. WDYT?

@andreiltd andreiltd changed the title Add clang-tidy and clang-tidy-fix targets ci: add clang-tidy and clang-tidy-fix targets Aug 19, 2025
@andreiltd
Copy link
Copy Markdown
Member Author

Hey @tschneidereit, let me know if you wanted to have another pass on this or else maybe we can get this landed?

@tschneidereit
Copy link
Copy Markdown
Member

I wasn't sure whether you were done iterating on it. Will take a look now.

@andreiltd
Copy link
Copy Markdown
Member Author

andreiltd commented Aug 21, 2025

I will make a follow up PR where we parallelize the checks.

This change is a bit controversial: #242 (comment) so I wanted to double check if you're on board to proceed 🙂

Copy link
Copy Markdown
Member

@tschneidereit tschneidereit left a comment

Choose a reason for hiding this comment

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

I got through the files up to and including headers.cpp. That one contained some changes in behavior that make me nervous in this kind of PR.

Can you point out commits that might contain these kinds of changes, instead of being pure formatting changes or otherwise trivial? Otherwise this will take a long time to fully get through, I'm afraid :/

@tschneidereit
Copy link
Copy Markdown
Member

If it's OK, I will add an issue to remove the -Wno-invalid-offsetof compile flag and replace it with suppression mapping when we switch to the next wasi-sdk. WDYT?

Ah, I had been wondering why it was okay to disable these checks. That all makes sense to me, and as long as you/we don't forget to apply that change once we can update SDKs, I'm okay with this plan. Getting rid of all the pragmas sure is nice!

andreiltd and others added 2 commits August 21, 2025 13:02
Co-authored-by: Till Schneidereit <till@tillschneidereit.net>
@andreiltd andreiltd merged commit cafdee7 into bytecodealliance:main Aug 29, 2025
6 checks passed
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.

2 participants