Skip to content
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

Misc redundant const refs #1

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

jstrzebonski
Copy link

@jstrzebonski jstrzebonski commented Nov 16, 2022

WORK IN PROGRESS

Related to DARMA-tasking/vt#874


How to build this check

See Dockerfile for general reference on how to build the LLVM. Minimal cmake configuration I used for development:

/usr/bin/cmake --no-warn-unused-cli -DCMAKE_COLOR_MAKEFILE:STRING=0 -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_VERBOSE_MAKEFILE:STRING=0 -DCLANG_TIDY_ENABLE_STATIC_ANALYZER:STRING=ON -DCMAKE_CXX_COMPILER_LAUNCHER:STRING=ccache -DCMAKE_C_COMPILER_LAUNCHER:STRING=ccache "-DLLVM_ENABLE_PROJECTS:STRING=clang;clang-tools-extra" -DLLVM_TARGETS_TO_BUILD:STRING=X86 -DLLVM_USE_LINKER:STRING=lld -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING=<installation-path> -DCMAKE_C_COMPILER:FILEPATH=/bin/clang-14 -DCMAKE_CXX_COMPILER:FILEPATH=/bin/clang++-14 -S/<path-to-llvm-root-dir>/llvm -B<build-path> -G Ninja

Bonus, if you're using vscode:

{
  "cmake.buildDirectory": "<build-path>-${buildType}",
  "cmake.configureSettings": {
    "CLANG_TIDY_ENABLE_STATIC_ANALYZER": "ON",
    "CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
    "CMAKE_C_COMPILER_LAUNCHER": "ccache",
    "CMAKE_VERBOSE_MAKEFILE": 0,
    "LLVM_ENABLE_PROJECTS": ["clang", "clang-tools-extra"],
    "LLVM_TARGETS_TO_BUILD": "X86",
    "LLVM_USE_LINKER": "lld"
  },
  "cmake.installPrefix": "<installation-path>-${buildType}",
  "cmake.sourceDirectory": "${workspaceFolder}/llvm"
}

Testing

Code snippets used for misc-redundant-const-refs testing can be found in:
clang-tools-extra/test/clang-tidy/checkers/misc/redundant-const-refs.cpp

To run misc-redundant-const-refs test:

cd clang-tools-extra/test/clang-tidy
export PATH=<llvm-installation-path>/bin/:$PATH
python3 check_clang_tidy.py checkers/misc/redundant-const-refs.cpp misc-redundant-const-refs tmp

export PATH makes sure that compiled clang-tidy 1) is in the path, 2) will be found before system clang-tidy (if exists).

In case of an error No such file or directory: 'FileCheck', copy FileCheck from <llvm-build-path>/bin to <llvm-installation-path>/bin

Docker image publishing

Originally every change done within this PR would trigger building and publishing images to my docker hub containing compiled clang-tidy, later used by DARMA-tasking/vt#1875, but because back then this PR occupied my own fork, it should be changed after moving it to DARMA-tasking, and the docker image should be published on DARMA docker hub.

Links that (IMHO) matter

Contributing to LLVM

https://llvm.org/docs/Contributing.html

Clang doxygen

https://clang.llvm.org/doxygen/

AST Matcher Reference

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

How to get started with the implementation of clang-tidy check

https://blog.audio-tk.com/2018/03/20/writing-custom-checks-for-clang-tidy/
https://www.kdab.com/clang-tidy-part-1-modernize-source-code-using-c11c14/
https://bbannier.github.io/blog/2015/05/02/Writing-a-basic-clang-static-analysis-check.html
https://docs.redpoint.games/clang-tidy-for-unreal-engine/docs/writing_custom_checks/
https://devblogs.microsoft.com/cppblog/exploring-clang-tooling-part-1-extending-clang-tidy/
https://devblogs.microsoft.com/cppblog/exploring-clang-tooling-part-2-examining-the-clang-ast-with-clang-query/
https://devblogs.microsoft.com/cppblog/exploring-clang-tooling-part-3-rewriting-code-with-clang-tidy/
https://firefox-source-docs.mozilla.org/code-quality/static-analysis/writing-new/clang-query.html
https://eli.thegreenplace.net/2014/07/29/ast-matchers-and-clang-refactoring-tools

https://www.youtube.com/watch?v=VqCkCDFLSsc
https://www.youtube.com/watch?v=K-WhaEUEZWc
https://www.youtube.com/watch?v=UfLH7dORav8

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.

1 participant