Skip to content

Commit 7583df8

Browse files
authored
added scheduled Clang Static Analyzer run (#6835)
- added CMake target `run-clang-tidy-csa` to run Clang Static Analyzer - added CMake option `ENABLE_CSA_ALPHA` to enable the alpha checkers
1 parent 06f6f1c commit 7583df8

File tree

8 files changed

+41
-3
lines changed

8 files changed

+41
-3
lines changed

.github/workflows/clang-tidy.yml

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
tags:
1212
- '2.*'
1313
pull_request:
14+
schedule:
15+
- cron: '0 0 * * 0'
1416

1517
permissions:
1618
contents: read
@@ -73,5 +75,11 @@ jobs:
7375
make -C cmake.output/test cmake_pch.hxx.pch
7476
7577
- name: Clang-Tidy
78+
if: github.event.schedule == ''
7679
run: |
7780
cmake --build cmake.output --target run-clang-tidy 2> /dev/null
81+
82+
- name: Clang Static Analyzer
83+
if: github.event.schedule != ''
84+
run: |
85+
cmake --build cmake.output --target run-clang-tidy-csa 2> /dev/null

cmake/clang_tidy.cmake

+24-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
88
set(RUN_CLANG_TIDY_NAMES "run-clang-tidy-${_clang_major}")
99
message(STATUS "Clang and clang-tidy version need to match when precompiled headers are enabled - limiting search to '${RUN_CLANG_TIDY_NAMES}'")
1010
else()
11-
message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy' target generation")
11+
message(STATUS "Cannot use non-Clang compiler with clang-tidy when precompiled headers are enabled - skipping 'run-clang-tidy'/'run-clang-tidy-csa' target generation")
1212
endif()
1313
else()
1414
set(RUN_CLANG_TIDY_NAMES run-clang-tidy run-clang-tidy-20 run-clang-tidy-19 run-clang-tidy-18 run-clang-tidy-17 run-clang-tidy-16 run-clang-tidy-15 run-clang-tidy-14 run-clang-tidy-13 run-clang-tidy-12 run-clang-tidy-11 run-clang-tidy-10 run-clang-tidy-9 run-clang-tidy-8)
@@ -25,16 +25,38 @@ if(RUN_CLANG_TIDY_NAMES)
2525
endif()
2626
message(STATUS "NPROC=${NPROC}")
2727

28+
# most of these are disabled because they are too noisy in our code
29+
# clang-analyzer-core.CallAndMessage
30+
# clang-analyzer-core.NonNullParamChecker
31+
# clang-analyzer-cplusplus.NewDeleteLeaks
32+
# clang-analyzer-cplusplus.NewDelete
33+
# clang-analyzer-core.NullDereference
34+
# clang-analyzer-unix.Stream
35+
# clang-analyzer-optin.cplusplus.UninitializedObject - false positives with unnamed fields - see https://github.com/llvm/llvm-project/issues/132001
36+
# clang-analyzer-alpha.clone.CloneChecker
37+
# clang-analyzer-alpha.webkit.* - we are not interested in these
38+
set(CLANG_TIDY_CSA_CONFIG "-config={InheritParentConfig: true, Checks: '-*,clang-analyzer-*,-clang-analyzer-core.CallAndMessage,-clang-analyzer-core.NonNullParamChecker,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-cplusplus.NewDelete,-clang-analyzer-core.NullDereference,-clang-analyzer-unix.Stream,-clang-analyzer-optin.cplusplus.UninitializedObject,-clang-analyzer-alpha.clone.CloneChecker,-clang-analyzer-alpha.webkit.*'}")
39+
if (ENABLE_CSA_ALPHA)
40+
set(CLANG_TIDY_CSA_ALPHA_OPTS "-allow-enabling-alpha-checkers" "-extra-arg=-Xclang" "-extra-arg=-analyzer-config" "-extra-arg=-Xclang" "-extra-arg=aggressive-binary-operation-simplification=true")
41+
endif()
42+
2843
# TODO: exclude moc_*.cpp
2944
# TODO: exclude mocs_compilation.cpp
3045
# disable all compiler warnings since we are just interested in the tidy ones
3146
add_custom_target(run-clang-tidy
3247
${Python_EXECUTABLE} ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -quiet
33-
USES_TERMINAL)
48+
USES_TERMINAL
49+
VERBATIM)
50+
add_custom_target(run-clang-tidy-csa
51+
${Python_EXECUTABLE} ${RUN_CLANG_TIDY} -p=${CMAKE_BINARY_DIR} -j ${NPROC} -quiet ${CLANG_TIDY_CSA_ALPHA_OPTS} ${CLANG_TIDY_CSA_CONFIG}
52+
USES_TERMINAL
53+
VERBATIM)
3454
if(BUILD_GUI)
3555
add_dependencies(run-clang-tidy gui-build-deps)
56+
add_dependencies(run-clang-tidy-csa gui-build-deps)
3657
if(BUILD_TRIAGE)
3758
add_dependencies(run-clang-tidy triage-build-ui-deps)
59+
add_dependencies(run-clang-tidy-csa triage-build-ui-deps)
3860
endif()
3961
endif()
4062
endif()

cmake/options.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling"
101101
option(NO_UNIX_BACKTRACE_SUPPORT "Disable usage of Unix Backtrace support" OFF)
102102
option(NO_WINDOWS_SEH "Disable usage of Windows SEH" OFF)
103103

104+
option(ENABLE_CSA_ALPHA "Enable Clang Static Analyzer alpha checkers for run-clang-tidy-csa target" OFF)
105+
104106
# TODO: disable by default like make build?
105107
option(FILESDIR "Hard-coded directory for files to load from" OFF)
106108

cmake/printInfo.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ message(STATUS "NO_UNIX_SIGNAL_HANDLING = ${NO_UNIX_SIGNAL_HANDLING}")
4343
message(STATUS "NO_UNIX_BACKTRACE_SUPPORT = ${NO_UNIX_BACKTRACE_SUPPORT}")
4444
message(STATUS "NO_WINDOWS_SEH = ${NO_WINDOWS_SEH}")
4545
message(STATUS)
46+
message(STATUS "ENABLE_CSA_ALPHA = ${ENABLE_CSA_ALPHA}")
47+
message(STATUS)
4648
if(NOT DEFINED BUILD_SHARED_LIBS)
4749
message(STATUS "BUILD_SHARED_LIBS = OFF")
4850
else()

lib/ctu.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ bool CTU::FileInfo::FunctionCall::loadFromXml(const tinyxml2::XMLElement *xmlEle
205205
callValueType = (ValueFlow::Value::ValueType)readAttrInt(xmlElement, ATTR_CALL_ARGVALUETYPE, &error);
206206
callArgValue.value = readAttrInt(xmlElement, ATTR_CALL_ARGVALUE, &error);
207207
const auto ufr = readAttrInt(xmlElement, ATTR_CALL_UNKNOWN_FUNCTION_RETURN, &error);
208+
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) - TODO: fix this - #13726
208209
callArgValue.unknownFunctionReturn = (ValueFlow::Value::UnknownFunctionReturn)(ufr>=0 && ufr <=0xff ? ufr : 0xff);
209210
const char *w = xmlElement->Attribute(ATTR_WARNING);
210211
warning = w && std::strcmp(w, "true") == 0;

lib/settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class SimpleEnableGroup {
9797
* to pass individual values to functions or constructors now or in the
9898
* future when we might have even more detailed settings.
9999
*/
100+
// NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding)
100101
class CPPCHECKLIB WARN_UNUSED Settings {
101102
private:
102103

releasenotes.txt

+2
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ Deprecations:
1818

1919
Other:
2020
- Updated Qt to 6.8.2 (official Windows release only).
21+
- added CMake target `run-clang-tidy-csa` to run Clang Static Analyzer
22+
- added CMake option `ENABLE_CSA_ALPHA` to enable the Clang Static Analyzer alpha checkers
2123
-

test/signal/test-signalhandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
/*static*/ void my_segv() // NOLINT(misc-use-internal-linkage)
5050
{
5151
// cppcheck-suppress nullPointer
52-
++*(int*)nullptr;
52+
++*(int*)nullptr; // NOLINT(clang-analyzer-core.NullDereference)
5353
}
5454

5555
#if !defined(__APPLE__)

0 commit comments

Comments
 (0)