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

Upgrade clang-tidy to LLVM 16 #64699

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
exclude = .git,__pycache__,lang/json
exclude = .git,__pycache__,lang/json,tools/clang-tidy-plugin/test/check_clang_tidy.py
ignore =
# E265 forces comments to have a space after the '#'. We have a bunch of
# optional debugging code commented out this way, and not having a space is
Expand Down
139 changes: 96 additions & 43 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Clang-tidy (clang-12, tiles)
name: Clang-tidy 16

on:
push:
Expand Down Expand Up @@ -27,56 +27,109 @@ jobs:
with:
cancel_others: 'true'
paths: '[ "**.cpp", "**.h", "**.c", "**/CMakeLists.txt", "**/Makefile", "**.hpp", "**.cmake", ".github/workflows/clang-tidy.yml" ]'
build:
build-plugin:
needs: skip-duplicates
if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' }}

runs-on: ubuntu-20.04
name: "Build clang-tidy plugin"
runs-on: ubuntu-22.04
env:
CMAKE: 1
CLANG: clang++-12
COMPILER: clang++-12
CATA_CLANG_TIDY: plugin
TILES: 1
SOUND: 1
RELEASE: 1
CC: clang-16
CXX: clang++-16
CLANG_DIR: '/usr/lib/llvm-16/lib/cmake/clang'
LLVM_DIR: '/usr/lib/llvm-16/lib/cmake/llvm'
steps:
- name: install LLVM 16
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
sudo apt update
sudo apt install llvm-16 llvm-16-dev llvm-16-tools clang-16 clang-tidy-16 clang-tools-16 libclang-16-dev
- name: install dependencies
run: |
sudo apt install python3-pip libncursesw5-dev ninja-build cmake gettext
pip3 install --user lit
- name: ensure clang-tidy and FileCheck commands point to LLVM 16
run: |
mkdir ~/llvm-command-override
ln -s /usr/bin/clang-tidy-16 ~/llvm-command-override/clang-tidy
ln -s /usr/bin/FileCheck-16 ~/llvm-command-override/FileCheck
echo "$HOME/llvm-command-override" >> $GITHUB_PATH
- name: checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: build clang-tidy plugin
run: |
cmake -B build -D CMAKE_BUILD_TYPE=Release \
-D CATA_CLANG_TIDY_PLUGIN=ON \
-D LLVM_DIR="${LLVM_DIR}" \
-D Clang_DIR="${CLANG_DIR}" \
-G Ninja
ninja -C build libCataAnalyzerPlugin.so
- name: test clang-tidy plugin
run: |
lit -v build/tools/clang-tidy-plugin/test
- name: cache clang-tidy plugin
uses: actions/cache@v3
with:
fetch-depth: 1
- name: install dependencies
path: ~/cata-clang-tidy-plugin
key: cata-clang-tidy-plugin
- name: copy clang-tidy plugin
run: |
cp build/tools/clang-tidy-plugin/libCataAnalyzerPlugin.so ~/cata-clang-tidy-plugin

check:
needs: build-plugin
if: ${{ needs.skip-duplicates.outputs.should_skip != 'true' }}
strategy:
fail-fast: true
matrix:
include:
- title: Check main
filter: "/src/"
- title: Check tests
filter: "/tests/"
name: "Run clang-tidy checks"
runs-on: ubuntu-22.04
env:
CC: clang-16
CXX: clang++-16
steps:
- name: install LLVM 16
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main"
sudo apt-get update
sudo apt-get install libncursesw5-dev clang-12 libclang-12-dev llvm-12-dev llvm-12-tools \
libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev ccache \
gettext jq
- name: prepare
run: bash ./build-scripts/requirements.sh
- name: determine changed files
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v5
sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main"
sudo apt update
sudo apt install llvm-16 llvm-16-dev llvm-16-tools clang-16 clang-tidy-16 clang-tools-16 libclang-16-dev
- name: install dependencies
run: |
sudo apt update
sudo apt install libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev libsdl2-mixer-dev libpulse-dev gettext \
cmake ninja-build parallel jq
- name: checkout
uses: actions/checkout@v3
- name: configure cmake
run: |
cmake -B build -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
-D TILES=ON \
-D SOUND=ON \
-G Ninja
- name: determine scope of files to be checked
run: |
jq --arg pwd $(pwd) --arg filter "/src/" \
'[.[].file] | map(sub($pwd; ".")) | map(select(. | contains($filter))) | join(" ")' \
build/compile_commands.json > files
- name: cache clang-tidy plugin
uses: actions/cache@v3
with:
script: |
var fs = require('fs');
const response = await github.paginate(github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
}
);
const files = response.map(x => x.filename);
for (const path of files) {
console.log(path);
}
fs.writeFileSync("files_changed", files.join('\n'));
- uses: ammaraskar/gcc-problem-matcher@master
- name: run clang-tidy
run: bash ./build-scripts/clang-tidy.sh
- name: show most time consuming checks
if: always()
path: ~/cata-clang-tidy-plugin
key: cata-clang-tidy-plugin
- name: ensure clang-tidy plugin exists
run: |
file ~/cata-clang-tidy-plugin/libCataAnalyzerPlugin.so
- name: run clang-tidy in src
run: |
jq -n 'reduce(inputs.profile | to_entries[]) as {$key,$value} ({}; .[$key] += $value) | with_entries(select(.key|contains(".wall"))) | to_entries | sort_by(.value) | reverse | .[0:10] | from_entries' clang-tidy-trace/*.json
parallel --linebuffer --keep-order \
clang-tidy -p build --checks="-*,cata-*" --use-color --quiet \
--load=~/cata-clang-tidy-plugin/libCataAnalyzerPlugin.so \
::: $(cat files)
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ astyle-fast: $(ASTYLE_SOURCES)
echo $(ASTYLE_SOURCES) | xargs -P 0 -L 1 $(ASTYLE_BINARY) --quiet --options=.astylerc -n

astyle-diff: $(ASTYLE_SOURCES)
$(ASTYLE_BINARY) --options=.astylerc -n $$(git diff --name-only src/*.h src/*.cpp tests/*.h tests/*.cpp)
$(ASTYLE_BINARY) --options=.astylerc -n $$(git diff --name-only src/*.h src/*.cpp tests/*.h tests/*.cpp tools/*.h tools/*.cpp)

astyle-all: $(ASTYLE_SOURCES)
$(ASTYLE_BINARY) --options=.astylerc -n $(ASTYLE_SOURCES)
Expand Down
8 changes: 7 additions & 1 deletion tools/clang-tidy-plugin/AlmostNeverAutoCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void CheckDecl( AlmostNeverAutoCheck &Check,
}

QualType AutoTp = Initializer->getType();
QualType DesugaredAutoTp = AutoTp.getDesugaredType( *Result.Context );
bool WasRRef = VarDeclType.getTypePtr()->isRValueReferenceType();
bool WasLRef = VarDeclType.getTypePtr()->isLValueReferenceType();
VarDeclType = VarDeclType.getNonReferenceType();
Expand All @@ -107,6 +108,7 @@ static void CheckDecl( AlmostNeverAutoCheck &Check,
PrintingPolicy Policy( LangOptions{} );
Policy.adjustForCPlusPlus();
std::string TypeStr = AutoTp.getAsString( Policy );
const std::string DesugaredTypeStr = DesugaredAutoTp.getAsString( Policy );

// In the case of 'const auto' we need to bring the beginning forwards
// to the start of the 'const'.
Expand Down Expand Up @@ -139,12 +141,16 @@ static void CheckDecl( AlmostNeverAutoCheck &Check,
// details) based on their names. Skipping the first character of each
// word to avoid worrying about capitalization.
for( std::string Fragment : {
"terator", "nternal", "__"
"terator", "element_type", "mapped_type", "value_type", "nternal", "__"
} ) {
if( std::search( TypeStr.begin(), TypeStr.end(), Fragment.begin(), Fragment.end() ) !=
TypeStr.end() ) {
return;
}
if( std::search( DesugaredTypeStr.begin(), DesugaredTypeStr.end(), Fragment.begin(),
Fragment.end() ) != DesugaredTypeStr.end() ) {
return;
}
}

if( WasLRef ) {
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/AlmostNeverAutoCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/AssertCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/AvoidAlternativeTokensCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
18 changes: 1 addition & 17 deletions tools/clang-tidy-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,7 @@ endif ()
target_include_directories(${CataAnalyzerName} SYSTEM PRIVATE
${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (NOT "${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "")
target_include_directories(${CataAnalyzerName} SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR})
endif ()

This is still needed for compiling the custom executable on Windows.

if ("${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "")
set(CTPS_RELEASES https://github.com/jbytheway/clang-tidy-plugin-support/releases/download)
set(CTPS_VERSION llvm-12.0.0-r3)
set(CTPS_SRC ${CMAKE_CURRENT_BINARY_DIR}/clang-tidy-plugin-support)

ExternalProject_Add(clang-tidy-plugin-support
URL ${CTPS_RELEASES}/${CTPS_VERSION}/clang-tidy-plugin-support-${CTPS_VERSION}.tar.xz
URL_HASH SHA256=c84aaf35b4d5bb9130b1cc309a92146ae5c62fd69db30a6254725beac9d60990
SOURCE_DIR ${CTPS_SRC}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND "")

add_dependencies(${CataAnalyzerName} clang-tidy-plugin-support)
target_include_directories(${CataAnalyzerName} SYSTEM PRIVATE ${CTPS_SRC}/include)
else ()
if (NOT "${CATA_CLANG_TIDY_INCLUDE_DIR}" STREQUAL "")
target_include_directories(${CataAnalyzerName} SYSTEM PRIVATE ${CATA_CLANG_TIDY_INCLUDE_DIR})
endif ()

Expand Down
6 changes: 3 additions & 3 deletions tools/clang-tidy-plugin/CataTidyModule.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <clang/Basic/Version.h>
#include <clang-tidy/ClangTidyModule.h>
#include <clang-tidy/ClangTidyModuleRegistry.h>
#include <llvm/ADT/StringRef.h>

#include "AlmostNeverAutoCheck.h"
#include "AssertCheck.h"
#include "AvoidAlternativeTokensCheck.h"
#include "ClangTidyModule.h"
#include "ClangTidyModuleRegistry.h"
#include "CombineLocalsIntoPointCheck.h"
#include "DeterminismCheck.h"
#include "HeaderGuardCheck.h"
Expand Down Expand Up @@ -40,7 +40,7 @@
#include "XYCheck.h"

#if defined( CATA_CLANG_TIDY_EXECUTABLE )
#include "tool/ClangTidyMain.h"
#include <clang-tidy/tool/ClangTidyMain.h>
#endif

namespace clang::tidy
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/CombineLocalsIntoPointCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <unordered_map>
#include <unordered_set>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/DeterminismCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/HeaderGuardCheck.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef CATA_TOOLS_CLANG_TIDY_PLUGIN_HEADERGUARDCHECK_H
#define CATA_TOOLS_CLANG_TIDY_PLUGIN_HEADERGUARDCHECK_H

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/JsonTranslationInputCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/LargeInlineFunctionCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/LargeStackObjectCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/NoLongCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/NoStaticTranslationCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/OtMatchCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
4 changes: 2 additions & 2 deletions tools/clang-tidy-plugin/PointInitializationCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <clang/ASTMatchers/ASTMatchFinder.h>
#include <llvm/ADT/StringRef.h>

#include "ClangTidy.h"
#include "ClangTidyCheck.h"
#include <clang-tidy/ClangTidy.h>
#include <clang-tidy/ClangTidyCheck.h>

namespace clang
{
Expand Down
Loading