onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

Create clang-tidy lint

Open justinchuby opened this issue 3 years ago • 9 comments
trafficstars

Creates a CI workflow to run clang-tidy.

Tested #12655

justinchuby avatar Aug 19 '22 16:08 justinchuby

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?

Run ZedThree/[email protected]

...

Diff from GitHub PR:
[<PatchedFile: .clang-tidy>, <PatchedFile: .github/workflows/lint.yml>]

include: *.[ch], file list now: []
include: *.[ch]xx, file list now: []
include: *.[ch]pp, file list now: []
include: *.[ch]++, file list now: []
include: *.cc, file list now: []
include: *.hh, file list now: []
exclude: , file list now: []
No files to check!

edgchen1 avatar Sep 20 '22 21:09 edgchen1

@edgchen1 I think that's because the lint is only checking diffs!

justinchuby avatar Sep 20 '22 21:09 justinchuby

@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.

edgchen1 avatar Sep 20 '22 21:09 edgchen1

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?

justinchuby avatar Sep 20 '22 21:09 justinchuby

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: https://github.com/microsoft/onnxruntime/blob/40749124b132a8a114a639548eec76abe6152e57/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml#L20-L29

a few notes:

  • --build_objc is probably unnecessary. and --use_coreml enabling the CoreML EP may be as well. that pipeline is specifically analyzing the Objective-C code.
  • it is not ideal as it does a full build of ORT. I think that was done to generate the ONNX protobuf source files. it certainly could be done more efficiently, perhaps by building the corresponding cmake target directly.

also, not sure which EPs we should enable for this. I suppose we can try with only the CPU EP first.

edgchen1 avatar Sep 21 '22 00:09 edgchen1

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 compile_commands.json.

cloudhan avatar Sep 21 '22 00:09 cloudhan

Current command

python tools/ci_build/build.py --build_dir build --update --cmake_extra_defines CMAKE_EXPORT_COMPILE_COMMANDS=ON

justinchuby avatar Sep 21 '22 17:09 justinchuby

Strange: https://github.com/microsoft/onnxruntime/actions/runs/3099926945/jobs/5019640574#step:8:39

clang-tidy failed with return code 134 and error: LLVM ERROR: Cannot chdir into "/home/runner/work/onnxruntime/onnxruntime/build/Debug"!

justinchuby avatar Sep 21 '22 18:09 justinchuby

Strange: https://github.com/microsoft/onnxruntime/actions/runs/3099926945/jobs/5019640574#step:8:39

clang-tidy failed with return code 134 and error: LLVM ERROR: Cannot chdir into "/home/runner/work/onnxruntime/onnxruntime/build/Debug"!

wonder if setting base_dir is needed since compile_commands.json is generated outside of the action: https://github.com/ZedThree/clang-tidy-review#use-in-a-non-default-location

edgchen1 avatar Sep 21 '22 19:09 edgchen1

@edgchen1 @cloudhan should

modernize-use-nodiscard be disabled? Otherwise this is ready to merge.

image

justinchuby avatar Sep 26 '22 19:09 justinchuby

@edgchen1 @cloudhan should

modernize-use-nodiscard be disabled? Otherwise this is ready to merge.

image

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?

edgchen1 avatar Sep 26 '22 23:09 edgchen1

@edgchen1 @cloudhan should modernize-use-nodiscard be disabled? Otherwise this is ready to merge. image

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.

pranavsharma avatar Sep 27 '22 00:09 pranavsharma

nondiscard is great. Better to keep it on and fix them from the code side.

cloudhan avatar Sep 27 '22 01:09 cloudhan

@edgchen1 PTAL

justinchuby avatar Sep 28 '22 17:09 justinchuby

thanks for setting this up!

edgchen1 avatar Sep 28 '22 17:09 edgchen1

@justinchuby Just found a new common annoying case:

Floating point literal has suffix 'f', which is not uppercase (fix available)clang-tidy(readability-uppercase-literal-suffix)

I think this should also be disabled.

cloudhan avatar Sep 29 '22 07:09 cloudhan

@cloudhan PTAL

justinchuby avatar Sep 29 '22 14:09 justinchuby