Skip to content

Commit 9f7a725

Browse files
authored
added environment variable UNUSEDFUNCTION_ONLY to make sure only the unusedFunction check is being executed (#4362)
1 parent 12afb9b commit 9f7a725

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

.github/workflows/selfcheck.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
7979
env:
8080
DISABLE_VALUEFLOW: 1
81+
UNUSEDFUNCTION_ONLY: 1
8182

8283
# the following steps are duplicated from above since setting up the build node in a parallel step takes longer than the actual steps
8384
- name: CMake (no test)
@@ -98,6 +99,7 @@ jobs:
9899
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
99100
env:
100101
DISABLE_VALUEFLOW: 1
102+
UNUSEDFUNCTION_ONLY: 1
101103

102104
- name: Fetch corpus
103105
run: |
@@ -126,6 +128,7 @@ jobs:
126128
head -50 callgrind.annotated.log
127129
env:
128130
DISABLE_VALUEFLOW: 1
131+
UNUSEDFUNCTION_ONLY: 1
129132

130133
- uses: actions/upload-artifact@v2
131134
with:

lib/cppcheck.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,10 @@ void CppCheck::checkRawTokens(const Tokenizer &tokenizer)
10251025

10261026
void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
10271027
{
1028+
// TODO: this should actually be the behavior if only "--enable=unusedFunction" is specified - see #10648
1029+
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
1030+
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
1031+
10281032
// call all "runChecks" in all registered Check classes
10291033
for (Check *check : Check::instances()) {
10301034
if (Settings::terminated())
@@ -1033,6 +1037,9 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
10331037
if (Tokenizer::isMaxTime())
10341038
return;
10351039

1040+
if (doUnusedFunctionOnly && dynamic_cast<CheckUnusedFunctions*>(check) == nullptr)
1041+
continue;
1042+
10361043
Timer timerRunChecks(check->name() + "::runChecks", mSettings.showtime, &s_timerResults);
10371044
check->runChecks(&tokenizer, &mSettings, this);
10381045
}
@@ -1053,7 +1060,10 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
10531060
mAnalyzerInformation.setFileInfo("ctu", fi1->toString());
10541061
}
10551062

1056-
for (const Check *check: Check::instances()) {
1063+
for (const Check *check : Check::instances()) {
1064+
if (doUnusedFunctionOnly && dynamic_cast<const CheckUnusedFunctions*>(check) == nullptr)
1065+
continue;
1066+
10571067
Check::FileInfo *fi = check->getFileInfo(&tokenizer, &mSettings);
10581068
if (fi != nullptr) {
10591069
if (mSettings.jobs == 1)

0 commit comments

Comments
 (0)