Skip to content

Commit 8522105

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

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

.github/workflows/selfcheck.yml

Lines changed: 6 additions & 7 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
@@ -81,7 +80,7 @@ jobs:
8180
- name: Self check (unusedFunction)
8281
if: false # TODO: fails with preprocessorErrorDirective - see #10667
8382
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
83+
./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
8584
env:
8685
DISABLE_VALUEFLOW: 1
8786
UNUSEDFUNCTION_ONLY: 1
@@ -106,7 +105,7 @@ jobs:
106105
# TODO: find a way to report unmatched suppressions without need to add information checks
107106
- name: Self check (unusedFunction / no test)
108107
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
108+
./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
110109
env:
111110
DISABLE_VALUEFLOW: 1
112111
UNUSEDFUNCTION_ONLY: 1
@@ -125,7 +124,7 @@ jobs:
125124
# TODO: find a way to report unmatched suppressions without need to add information checks
126125
- name: Self check (unusedFunction / no test / no gui)
127126
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
127+
./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
129128
env:
130129
DISABLE_VALUEFLOW: 1
131130
UNUSEDFUNCTION_ONLY: 1
@@ -149,7 +148,7 @@ jobs:
149148
- name: Self check (unusedFunction / no test / no cli)
150149
if: false # TODO: the findings are currently too intrusive
151150
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
151+
./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
153152
env:
154153
DISABLE_VALUEFLOW: 1
155154
UNUSEDFUNCTION_ONLY: 1
@@ -169,7 +168,7 @@ jobs:
169168
- name: Self check (unusedFunction / no test / no cli / no gui)
170169
if: false # TODO: the findings are currently too intrusive
171170
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
171+
./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
173172
env:
174173
DISABLE_VALUEFLOW: 1
175174
UNUSEDFUNCTION_ONLY: 1
@@ -197,7 +196,7 @@ jobs:
197196
- name: Self check (unusedFunction / corpus / no test / callgrind)
198197
run: |
199198
# 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)
199+
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)
201200
cat callgrind.log
202201
callgrind_annotate --auto=no > callgrind.annotated.log
203202
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)