-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Create clang-tidy CI #12653
Create clang-tidy CI #12653
Conversation
.clang-tidy
Outdated
@@ -1,6 +1,6 @@ | |||
--- | |||
# turn off readability-braces-around-statements to allow single line statement like 'if (x == y) doSomething();' | |||
Checks: '-*,cppcoreguidelines-*,google-*,readability-*,modernize-*,-readability-braces-around-statements,-google-runtime-references,-cppcoreguidelines-pro-type-reinterpret-cast' | |||
Checks: '-*,cppcoreguidelines-*,google-*,readability-*,modernize-*,bugprone-*,-readability-braces-around-statements,-google-runtime-references,-cppcoreguidelines-pro-type-reinterpret-cast' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.clang-tidy
file is a yaml
file literally, if desired, you can actually make it mulit-line by using a yaml multiple line string, and clang-tidy
itself happens to tolerate the \n
tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I've passed this question along to the core team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justinchuby I don't have suggestion to enable more checks, instead, I'd suggest to disable more.
modernize-concat-nested-namespaces
, becaure we don't use it.cppcoreguidelines-macro-usage
, there are a lot of false-positives likeFunction-like macro 'Foo' used; consider a 'constexpr' template function
readability-identifier-length
, clang-tidy is bullshitting here, there are a lot of numerical code rely on short names to imporve readability.google-readability-todo
, Missing username/bug in TODO, which I am not sure we are practicing.cppcoreguidelines-pro-bounds-array-to-pointer-decay
Do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead. But our macros likeORT_RETURN_IF
andLOGS
are relying on it. We shall fix it, either way.
hint, onnxruntime/core/session/inference_session.cc
is full of warning in current setting xDDD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloudhan I added all except for cppcoreguidelines-pro-bounds-array-to-pointer-decay
, because it does seem desired from my understanding of your explanation, even though some of our macros have this behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed -google-readability-braces-around-statements
because google-readability-braces-around-statements.ShortStatementLines
is set to 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is OK to keep cppcoreguidelines-pro-bounds-array-to-pointer-decay
, it has its purpose. But I think someone should fix it from source code level. And if we add the magic comment to disable it at the macro definition side, I am not sure if it has effect on macro application site.
https://github.com/microsoft/onnxruntime/actions/runs/3092428102/jobs/5003682677 looking at the build output, it appears that there are no files checked. perhaps the filter should be adjusted?
|
@edgchen1 I think that's because the lint is only checking diffs! |
ah ok, that makes sense. as a side note, we'll probably need to generate a compile_commands.json file to configure clang-tidy properly. |
Absolutely. I haven't figured out how to do that though. @snnn any suggestions? |
may be able to refer to this as a starting point: onnxruntime/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml Lines 20 to 29 in 4074912
a few notes:
also, not sure which EPs we should enable for this. I suppose we can try with only the CPU EP first. |
Use clangd as C++ language server gives you a uniform editing experience span C/C++ and CUDA and HIP code. clang-tidy and clang-format is also integrated. All you need is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will greatly improve my code editing experience. Thanks!
Current command
|
Strange: https://github.com/microsoft/onnxruntime/actions/runs/3099926945/jobs/5019640574#step:8:39 clang-tidy failed with return code 134 and error: |
.github/workflows/lint.yml
Outdated
uses: ZedThree/clang-tidy-review@526cbfb043719639f1ebdeedae0cc1eacd219d8f | ||
with: | ||
token: ${{ secrets.github_token }} | ||
build_dir: "build/Debug/compile_commands.json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be the compile_commands.json directory, "build/Debug"?
https://github.com/ZedThree/clang-tidy-review#inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no wonder 😅 . thanks!
wonder if setting base_dir is needed since compile_commands.json is generated outside of the action: |
I can see the merits of using [[nodiscard]] more. However, we don't use it much in our existing code. @pranavsharma what do you think? |
I think it'll be good to enable this. I've seen before that we ignored Status returns from some functions. |
nondiscard is great. Better to keep it on and fix them from the code side. |
@edgchen1 PTAL |
thanks for setting this up! |
--build_dir build \ | ||
--update \ | ||
--cmake_extra_defines CMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
- name: Generate ONNX protobuf files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, I just found out about the build.py --target
option. so this could possibly be done in the build.py command above, e.g., build.py ... --build --parallel --target onnx_proto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! For the sake of avoiding running another day of CI tests I merged as is.
@justinchuby Just found a new common annoying case:
I think this should also be disabled. |
Co-authored-by: Edward Chen <[email protected]>
4c8a482
to
b2ab665
Compare
@cloudhan PTAL |
Update clang-tidy config to prepare for creating a CI workflow to run clang-tidy. Added clangtidy check in CI Co-authored-by: Edward Chen <[email protected]>
Update clang-tidy config to prepare for creating a CI workflow to run clang-tidy.
Added clangtidy check in CI