Skip to content

Commit 16523cd

Browse files
Merge branch 'main' into chr_11617
2 parents e341033 + 583bc8b commit 16523cd

35 files changed

Lines changed: 333 additions & 92 deletions

.github/workflows/CI-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ jobs:
219219

220220
- name: Run Debug test
221221
if: matrix.config == 'debug'
222-
run: .\bin\debug\testrunner.exe || exit /b !errorlevel!
222+
run: .\bin\debug\testrunner.exe -t || exit /b !errorlevel!
223223

224224
- name: Build CLI release configuration using MSBuild
225225
if: matrix.config == 'release'

.github/workflows/sanitizers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
cmake --build cmake.output --target gui-tests -- -j $(nproc)
115115
116116
- name: Run tests
117-
run: ./cmake.output/bin/testrunner
117+
run: ./cmake.output/bin/testrunner -t
118118

119119
- name: Run cfg tests
120120
run: |

.github/workflows/selfcheck.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,16 @@ jobs:
202202
with:
203203
name: Callgrind Output
204204
path: ./callgrind.*
205+
206+
- name: Self check (unusedFunction / corpus / no test / memcheck)
207+
run: |
208+
# TODO: fix -rp so the suppressions actually work
209+
valgrind --error-limit=yes --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --log-fd=9 --error-exitcode=42 ./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 9>memcheck.log || (cat memcheck.log && false)
210+
cat memcheck.log
211+
env:
212+
DISABLE_VALUEFLOW: 1
213+
214+
- uses: actions/upload-artifact@v4
215+
with:
216+
name: Memcheck Output
217+
path: ./memcheck.*

.github/workflows/valgrind.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
TestProcessExecutorFiles \
5858
TestSuppressions::suppressionsSettingsProcessesFiles \
5959
TestSuppressions::suppressionsSettingsProcessesFS"
60-
valgrind --error-limit=yes --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --suppressions=valgrind/testrunner.supp --gen-suppressions=all -s --log-fd=9 --error-exitcode=42 ./testrunner -x $excluded_tests 9>memcheck.log || ec=1
60+
valgrind --error-limit=yes --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --suppressions=valgrind/testrunner.supp --gen-suppressions=all -s --log-fd=9 --error-exitcode=42 ./testrunner -t -x $excluded_tests 9>memcheck.log || ec=1
6161
cat memcheck.log
6262
exit $ec
6363
# TODO: debuginfod.ubuntu.com is currently not responding to any requests causing it to run into a 40(!) minute timeout

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ $(libcppdir)/standards.o: lib/standards.cpp externals/simplecpp/simplecpp.h lib/
656656
$(libcppdir)/summaries.o: lib/summaries.cpp lib/addoninfo.h lib/analyzerinfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
657657
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/summaries.cpp
658658

659-
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
659+
$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h
660660
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp
661661

662662
$(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/addoninfo.h lib/checkers.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/regex.h lib/settings.h lib/smallvector.h lib/standards.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
@@ -722,7 +722,7 @@ cli/stacktrace.o: cli/stacktrace.cpp cli/stacktrace.h lib/config.h lib/utils.h
722722
cli/threadexecutor.o: cli/threadexecutor.cpp cli/executor.h cli/threadexecutor.h lib/addoninfo.h lib/check.h lib/checkers.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h
723723
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/threadexecutor.cpp
724724

725-
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/fixture.h test/helpers.h test/options.h test/redirect.h
725+
test/fixture.o: test/fixture.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/fixture.h test/helpers.h test/options.h test/redirect.h
726726
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/fixture.cpp
727727

728728
test/helpers.o: test/helpers.cpp cli/filelister.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/preprocessor.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/xml.h test/helpers.h
@@ -731,7 +731,7 @@ test/helpers.o: test/helpers.cpp cli/filelister.h externals/simplecpp/simplecpp.
731731
test/main.o: test/main.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/regex.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h test/options.h
732732
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/main.cpp
733733

734-
test/options.o: test/options.cpp test/options.h
734+
test/options.o: test/options.cpp lib/config.h lib/timer.h test/options.h
735735
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/options.cpp
736736

737737
test/test64bit.o: test/test64bit.cpp lib/addoninfo.h lib/check.h lib/check64bit.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h

cli/cmdlineparser.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,15 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
756756
}
757757
}
758758

759+
else if (std::strncmp(argv[i], "--exitcode-suppress=", 20) == 0) {
760+
const std::string suppression = argv[i]+20;
761+
const std::string errmsg(mSuppressions.nofail.addSuppressionLine(suppression));
762+
if (!errmsg.empty()) {
763+
mLogger.printError(errmsg);
764+
return Result::Fail;
765+
}
766+
}
767+
759768
// Filter errors
760769
else if (std::strncmp(argv[i], "--exitcode-suppressions=", 24) == 0) {
761770
// exitcode-suppressions=filename.txt
@@ -1811,6 +1820,9 @@ void CmdLineParser::printHelp() const
18111820
" provided. Note that your operating system can modify\n"
18121821
" this value, e.g. '256' can become '0'.\n"
18131822
" --errorlist Print a list of all the error messages in XML format.\n"
1823+
" --exitcode-suppress=<spec>\n"
1824+
" Used to specify an error ID which should not result in\n"
1825+
" a non-zero exitcode."
18141826
" --exitcode-suppressions=<file>\n"
18151827
" Used when certain messages should be displayed but\n"
18161828
" should not cause a non-zero exitcode.\n"

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
309309
// check if this unmatched suppression is suppressed
310310
bool suppressed = false;
311311
for (const SuppressionList::Suppression &s2 : unmatched) {
312-
if (s2.errorId == "unmatchedSuppression") {
312+
if (s2.errorId == "unmatchedSuppression") { // TODO: handle unmatchedPolyspaceSuppression?
313313
if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) &&
314314
(s2.lineNumber == SuppressionList::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) {
315315
suppressed = true;
@@ -329,7 +329,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
329329

330330
std::list<ErrorMessage::FileLocation> callStack;
331331
if (!s.fileName.empty()) {
332-
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, 0); // TODO: set column - see #13810 / get rid of s.lineNumber == -1 hack
332+
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, s.column); // TODO: get rid of s.lineNumber == -1 hack
333333
}
334334
const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
335335
errors.emplace_back(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal);
@@ -345,6 +345,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
345345
// bail out if there is a suppression of unmatchedSuppression which matches any file
346346
auto suppr = suppressions.getSuppressions();
347347
if (std::any_of(suppr.cbegin(), suppr.cend(), [](const SuppressionList::Suppression& s) {
348+
// TODO: handle unmatchedPolyspaceSuppression?
348349
return s.errorId == "unmatchedSuppression" && (s.fileName.empty() || s.fileName == "*") && s.lineNumber == SuppressionList::Suppression::NO_LINE;
349350
}))
350351
return false;

cli/processexecutor.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ namespace {
113113
{
114114
std::string suppr_str = suppr.toString();
115115
suppr_str += ";";
116+
suppr_str += std::to_string(suppr.column);
117+
suppr_str += ";";
116118
suppr_str += suppr.checked ? "1" : "0";
117119
suppr_str += ";";
118120
suppr_str += suppr.matched ? "1" : "0";
@@ -241,18 +243,19 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
241243
if (!buf.empty()) {
242244
// TODO: avoid string splitting
243245
auto parts = splitString(buf, ';');
244-
if (parts.size() < 4)
246+
if (parts.size() < 5)
245247
{
246248
// TODO: make this non-fatal
247249
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") adding of inline suppression failed - insufficient data" << std::endl;
248250
std::exit(EXIT_FAILURE);
249251
}
250252
auto suppr = SuppressionList::parseLine(parts[0]);
251253
suppr.isInline = (type == PipeWriter::REPORT_SUPPR_INLINE);
252-
suppr.checked = parts[1] == "1";
253-
suppr.matched = parts[2] == "1";
254-
suppr.extraComment = parts[3];
255-
for (std::size_t i = 4; i < parts.size(); i++) {
254+
suppr.column = strToInt<int>(parts[1]);
255+
suppr.checked = parts[2] == "1";
256+
suppr.matched = parts[3] == "1";
257+
suppr.extraComment = parts[4];
258+
for (std::size_t i = 5; i < parts.size(); i++) {
256259
suppr.extraComment += ";" + parts[i];
257260
}
258261
const std::string err = mSuppressions.nomsg.addSuppression(suppr);

lib/astutils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ bool isTemporary(const Token* tok, const Library* library, bool unknown)
461461
return false;
462462
return !branchTok->astOperand1()->valueType()->isTypeEqual(branchTok->astOperand2()->valueType());
463463
}
464-
if (Token::simpleMatch(tok, "(") && tok->astOperand1() &&
464+
if (Token::Match(tok, "(|{") && tok->astOperand1() &&
465465
(tok->astOperand2() || Token::simpleMatch(tok->next(), ")"))) {
466466
if (Token::simpleMatch(tok->astOperand1(), "typeid"))
467467
return false;
@@ -498,9 +498,6 @@ bool isTemporary(const Token* tok, const Library* library, bool unknown)
498498
// Currying a function is unknown in cppcheck
499499
if (Token::simpleMatch(tok, "(") && Token::simpleMatch(tok->astOperand1(), "("))
500500
return unknown;
501-
if (Token::simpleMatch(tok, "{") && Token::simpleMatch(tok->astParent(), "return") && tok->astOperand1() &&
502-
!tok->astOperand2())
503-
return isTemporary(tok->astOperand1(), library);
504501
return true;
505502
}
506503

lib/checkunusedfunctions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const Setting
261261
while (Token::Match(funcname, "%name% :: %name%"))
262262
funcname = funcname->tokAt(2);
263263

264+
if (funcname && funcname->isName() && !funcname->function() && !tok->astParent() && Token::Match(tok, "[(,]")) // unknown type in parameter list
265+
continue;
266+
264267
if (!Token::Match(funcname, "%name% [(),;]:}<>]"))
265268
continue;
266269
}

0 commit comments

Comments
 (0)