Skip to content

Commit c848d1b

Browse files
committed
ignore all other suppressions when UNUSEDFUNCTION_ONLY hack is active / selfcheck.yml: enabled information messages
1 parent f3d9a37 commit c848d1b

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

.github/workflows/selfcheck.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ permissions:
1616
contents: read
1717

1818
jobs:
19-
# TODO: enable information
2019
build:
2120

2221
runs-on: ubuntu-22.04
@@ -77,11 +76,10 @@ jobs:
7776
# make sure the auto-generated GUI dependencies exist
7877
make -C cmake.output gui-build-deps
7978
80-
# TODO: find a way to report unmatched suppressions without need to add information checks
8179
- name: Self check (unusedFunction)
8280
if: false # TODO: fails with preprocessorErrorDirective - see #10667
8381
run: |
84-
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
82+
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
8583
env:
8684
DISABLE_VALUEFLOW: 1
8785
UNUSEDFUNCTION_ONLY: 1
@@ -103,10 +101,9 @@ jobs:
103101
# make sure the auto-generated GUI dependencies exist
104102
make -C cmake.output.notest gui-build-deps
105103
106-
# TODO: find a way to report unmatched suppressions without need to add information checks
107104
- name: Self check (unusedFunction / no test)
108105
run: |
109-
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
106+
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
110107
env:
111108
DISABLE_VALUEFLOW: 1
112109
UNUSEDFUNCTION_ONLY: 1
@@ -122,10 +119,9 @@ jobs:
122119
# make sure the precompiled headers exist
123120
make -C cmake.output.notest_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
124121
125-
# TODO: find a way to report unmatched suppressions without need to add information checks
126122
- name: Self check (unusedFunction / no test / no gui)
127123
run: |
128-
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
124+
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
129125
env:
130126
DISABLE_VALUEFLOW: 1
131127
UNUSEDFUNCTION_ONLY: 1
@@ -145,11 +141,10 @@ jobs:
145141
# make sure the auto-generated GUI dependencies exist
146142
make -C cmake.output.notest_nocli gui-build-deps
147143
148-
# TODO: find a way to report unmatched suppressions without need to add information checks
149144
- name: Self check (unusedFunction / no test / no cli)
150145
if: false # TODO: the findings are currently too intrusive
151146
run: |
152-
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest_nocli/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
147+
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nocli/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
153148
env:
154149
DISABLE_VALUEFLOW: 1
155150
UNUSEDFUNCTION_ONLY: 1
@@ -165,11 +160,10 @@ jobs:
165160
# make sure the precompiled headers exist
166161
make -C cmake.output.notest_nocli_nogui lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
167162
168-
# TODO: find a way to report unmatched suppressions without need to add information checks
169163
- name: Self check (unusedFunction / no test / no cli / no gui)
170164
if: false # TODO: the findings are currently too intrusive
171165
run: |
172-
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.notest_nocli_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
166+
./cppcheck -q --template=selfcheck --error-exitcode=1 --library=cppcheck-lib --library=qt -D__CPPCHECK__ -D__GNUC__ --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.notest_nocli_nogui/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr
173167
env:
174168
DISABLE_VALUEFLOW: 1
175169
UNUSEDFUNCTION_ONLY: 1
@@ -193,11 +187,10 @@ jobs:
193187
# make sure the auto-generated GUI dependencies exist
194188
make -C cmake.output.corpus gui-build-deps
195189
196-
# TODO: find a way to report unmatched suppressions without need to add information checks
197190
- name: Self check (unusedFunction / corpus / no test / callgrind)
198191
run: |
199192
# TODO: fix -rp so the suppressions actually work
200-
valgrind --tool=callgrind ./cppcheck --template=selfcheck --error-exitcode=0 --library=cppcheck-lib --library=qt -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction --exception-handling -rp=. --project=cmake.output.corpus/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr 2>callgrind.log || (cat callgrind.log && false)
193+
valgrind --tool=callgrind ./cppcheck --template=selfcheck --error-exitcode=0 --library=cppcheck-lib --library=qt -D__GNUC__ -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --enable=unusedFunction,information --exception-handling -rp=. --project=cmake.output.corpus/compile_commands.json --suppressions-list=.selfcheck_unused_suppressions --inline-suppr 2>callgrind.log || (cat callgrind.log && false)
201194
cat callgrind.log
202195
callgrind_annotate --auto=no > callgrind.annotated.log
203196
head -50 callgrind.annotated.log

cli/cppcheckexecutor.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,27 +339,39 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
339339
assert(!(!files.empty() && !fileSettings.empty()));
340340

341341
// bail out if there is a suppression of unmatchedSuppression which matches any file
342-
const auto suppr = suppressions.getSuppressions();
342+
auto suppr = suppressions.getSuppressions();
343343
if (std::any_of(suppr.cbegin(), suppr.cend(), [](const SuppressionList::Suppression& s) {
344344
return s.errorId == "unmatchedSuppression" && (s.fileName.empty() || s.fileName == "*") && s.lineNumber == SuppressionList::Suppression::NO_LINE;
345345
}))
346346
return false;
347347

348+
SuppressionList supprlist;
349+
350+
const char* unusedFunctionOnly = std::getenv("UNUSEDFUNCTION_ONLY");
351+
const bool doUnusedFunctionOnly = unusedFunctionOnly && (std::strcmp(unusedFunctionOnly, "1") == 0);
352+
// ignore all other suppressions if we use the unusedFunction hack
353+
for (auto&& s : suppr)
354+
{
355+
if (doUnusedFunctionOnly && s.errorId != "unusedFunction")
356+
continue;
357+
supprlist.addSuppression(std::move(s));
358+
}
359+
348360
bool err = false;
349361

350362
for (auto i = files.cbegin(); i != files.cend(); ++i) {
351-
err |= ::reportUnmatchedSuppressions(suppressions.getUnmatchedLocalSuppressions(*i), errorLogger, settings.unmatchedSuppressionFilters);
363+
err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(*i), errorLogger, settings.unmatchedSuppressionFilters);
352364
}
353365

354366
for (auto i = fileSettings.cbegin(); i != fileSettings.cend(); ++i) {
355-
err |= ::reportUnmatchedSuppressions(suppressions.getUnmatchedLocalSuppressions(i->file), errorLogger, settings.unmatchedSuppressionFilters);
367+
err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedLocalSuppressions(i->file), errorLogger, settings.unmatchedSuppressionFilters);
356368
}
357369

358370
if (settings.inlineSuppressions) {
359-
err |= ::reportUnmatchedSuppressions(suppressions.getUnmatchedInlineSuppressions(), errorLogger, settings.unmatchedSuppressionFilters);
371+
err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedInlineSuppressions(), errorLogger, settings.unmatchedSuppressionFilters);
360372
}
361373

362-
err |= ::reportUnmatchedSuppressions(suppressions.getUnmatchedGlobalSuppressions(), errorLogger, settings.unmatchedSuppressionFilters);
374+
err |= ::reportUnmatchedSuppressions(supprlist.getUnmatchedGlobalSuppressions(), errorLogger, settings.unmatchedSuppressionFilters);
363375
return err;
364376
}
365377

0 commit comments

Comments
 (0)