Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,6 @@ jobs:
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0

# work around missingInclude not being reported with -j and the --check-config requirement for detailed warnings
./cppcheck $selfcheck_options -DCHECK_INTERNAL cli lib --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
./cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1

# early exit
if [ $ec -eq 1 ]; then
exit $ec
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-22.04

env:
QT_VERSION: 5.15.2
ASAN_OPTIONS: detect_stack_use_after_return=1

steps:
Expand All @@ -35,9 +36,16 @@ jobs:
chmod +x llvm.sh
sudo ./llvm.sh 16

- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
modules: 'qtcharts'
cache: true

- name: CMake
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On
env:
CC: clang-16
CXX: clang++-16
Expand All @@ -53,6 +61,12 @@ jobs:
- name: Run tests
run: ./cmake.output/bin/testrunner

- name: Generate dependencies
run: |
# make sure auto-generated GUI files exist
make -C cmake.output autogen
make -C cmake.output gui-build-deps triage-build-ui-deps

# TODO: this is currently way too slow (~60 minutes) to enable it
# TODO: only fail the step on sanitizer issues
- name: Self check
Expand All @@ -61,7 +75,7 @@ jobs:
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1
exit $ec
20 changes: 17 additions & 3 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-22.04

env:
QT_VERSION: 5.15.2
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1

steps:
Expand All @@ -35,9 +36,16 @@ jobs:
chmod +x llvm.sh
sudo ./llvm.sh 16

- name: Install Qt ${{ env.QT_VERSION }}
uses: jurplel/install-qt-action@v3
with:
version: ${{ env.QT_VERSION }}
modules: 'qtcharts'
cache: true

- name: CMake
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On
env:
CC: clang-16
CXX: clang++-16
Expand All @@ -53,13 +61,19 @@ jobs:
- name: Run tests
run: ./cmake.output/bin/testrunner

- name: Generate dependencies
run: |
# make sure auto-generated GUI files exist
make -C cmake.output autogen
make -C cmake.output gui-build-deps triage-build-ui-deps

# TODO: only fail the step on sanitizer issues
- name: Self check
run: |
selfcheck_options="-q -j$(nproc) --std=c++11 --template=selfcheck --showtime=top5 -D__CPPCHECK__ --error-exitcode=1 --inline-suppr --suppressions-list=.selfcheck_suppressions --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2/ --inconclusive --enable=style,performance,portability,warning,missingInclude,internal --exception-handling --debug-warnings"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Igui/temp -Igui gui/*.cpp gui/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQT_VERSION=0x050000 -DQ_MOC_OUTPUT_REVISION=67 --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Itools/triage/temp -Igui tools/triage/*.cpp tools/triage/temp/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options -DQ_MOC_OUTPUT_REVISION=67 --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1
exit $ec
3 changes: 3 additions & 0 deletions .selfcheck_suppressions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
missingIncludeSystem
shadowFunction
bitwiseOnBoolean

Expand All @@ -11,7 +12,9 @@ simplifyUsing:gui/temp/moc_*.cpp
funcArgNamesDifferent:gui/temp/moc_*.cpp
symbolDatabaseWarning:tools/triage/temp/moc_*.cpp
naming-varname:gui/temp/ui_*.h
naming-varname:cmake.output/gui/ui_*.h
functionStatic:gui/temp/ui_fileview.h
functionStatic:cmake.output/gui/ui_fileview.h

# --debug-warnings suppressions
valueFlowBailout
Expand Down
3 changes: 1 addition & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,7 @@ void CmdLineParser::printHelp()
" to only enable this when the whole program is\n"
" scanned.\n"
" * missingInclude\n"
" Warn if there are missing includes. For\n"
" detailed information, use '--check-config'.\n"
" Warn if there are missing includes.\n"
" Several ids can be given if you separate them with\n"
" commas. See also --std\n"
" --error-exitcode=<n> If errors are found, integer [n] is returned instead of\n"
Expand Down
26 changes: 0 additions & 26 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c

int CppCheckExecutor::check(int argc, const char* const argv[])
{
Preprocessor::missingIncludeFlag = false;
Preprocessor::missingSystemIncludeFlag = false;

CheckUnusedFunctions::clear();

CppCheck cppCheck(*this, true, executeCommand);
Expand Down Expand Up @@ -380,29 +377,6 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)

if (!settings.checkConfiguration) {
cppcheck.tooManyConfigsError(emptyString,0U);

if (settings.checks.isEnabled(Checks::missingInclude) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
const std::list<ErrorMessage::FileLocation> callStack;
ErrorMessage msg(callStack,
emptyString,
Severity::information,
"Cppcheck cannot find all the include files (use --check-config for details)\n"
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
"include files found. But the results will probably be more accurate if all the include "
"files are found. Please check your project's include directories and add all of them "
"as include directories for Cppcheck. To see what files Cppcheck cannot find use "
"--check-config.",
"",
Certainty::normal);
if (Preprocessor::missingIncludeFlag) {
msg.id = "missingInclude";
reportInfo(msg);
}
if (Preprocessor::missingSystemIncludeFlag) {
msg.id = "missingIncludeSystem";
reportInfo(msg);
}
}
}

if (settings.xml) {
Expand Down
26 changes: 7 additions & 19 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ Directive::Directive(std::string _file, const int _linenr, const std::string &_s
str(trim(_str))
{}

std::atomic<bool> Preprocessor::missingIncludeFlag;
std::atomic<bool> Preprocessor::missingSystemIncludeFlag;

char Preprocessor::macroChar = char(1);

Preprocessor::Preprocessor(Settings& settings, ErrorLogger *errorLogger) : mSettings(settings), mErrorLogger(errorLogger)
Expand Down Expand Up @@ -836,49 +833,40 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
// Report that include is missing
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType)
{
if (!mSettings.checks.isEnabled(Checks::missingInclude) && !mSettings.checkConfiguration)
if (!mSettings.checks.isEnabled(Checks::missingInclude))
return;

std::string fname = Path::fromNativeSeparators(filename);
std::string errorId = (headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude";
Suppressions::ErrorMessage errorMessage;
errorMessage.errorId = "missingInclude";
errorMessage.errorId = errorId;
errorMessage.setFileName(std::move(fname));
errorMessage.lineNumber = linenr;
if (mSettings.nomsg.isSuppressed(errorMessage))
return;
errorMessage.errorId = "missingIncludeSystem";
if (headerType == SystemHeader && mSettings.nomsg.isSuppressed(errorMessage))
return;

if (headerType == SystemHeader)
missingSystemIncludeFlag = true;
else
missingIncludeFlag = true;

if (mErrorLogger && mSettings.checkConfiguration) {

if (mErrorLogger) {
std::list<ErrorMessage::FileLocation> locationList;
if (!filename.empty()) {
ErrorMessage::FileLocation loc;
loc.line = linenr;
loc.setfile(Path::toNativeSeparators(filename));
locationList.push_back(std::move(loc));
}
ErrorMessage errmsg(locationList, mFile0, Severity::information,
ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information,
(headerType==SystemHeader) ?
"Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." :
"Include file: \"" + header + "\" not found.",
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
std::move(errorId),
Certainty::normal);
mErrorLogger->reportInfo(errmsg);
mErrorLogger->reportErr(errmsg);
}
}

void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
{
Settings settings2(*settings);
Preprocessor preprocessor(settings2, errorLogger);
settings2.checkConfiguration = true;
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
preprocessor.error(emptyString, 1, "#error message"); // #error ..
Expand Down
4 changes: 0 additions & 4 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "config.h"

#include <atomic>
#include <cstddef>
#include <istream>
#include <list>
Expand Down Expand Up @@ -87,9 +86,6 @@ class CPPCHECKLIB Preprocessor {
explicit Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr);
virtual ~Preprocessor();

static std::atomic<bool> missingIncludeFlag;
static std::atomic<bool> missingSystemIncludeFlag;

void inlineSuppressions(const simplecpp::TokenList &tokens);

void setDirectives(const simplecpp::TokenList &tokens);
Expand Down
2 changes: 1 addition & 1 deletion man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Example: '-UDEBUG'</para>
enables unusedFunction.</para></glossdef></glossentry><glossentry><glossterm>warning</glossterm><glossdef><para>Enable warning messages</para></glossdef></glossentry><glossentry><glossterm>style</glossterm><glossdef><para>Enable all coding style checks. All messages with the
severities 'style', 'performance' and 'portability' are
enabled.</para></glossdef></glossentry><glossentry><glossterm>performance</glossterm><glossdef><para>Enable performance messages</para></glossdef></glossentry><glossentry><glossterm>portability</glossterm><glossdef><para>Enable portability messages</para></glossdef></glossentry><glossentry><glossterm>information</glossterm><glossdef><para>Enable information messages</para></glossdef></glossentry><glossentry><glossterm>unusedFunction</glossterm><glossdef><para>Check for unused functions. It is recommend to only
enable this when the whole program is scanned</para></glossdef></glossentry><glossentry><glossterm>missingInclude</glossterm><glossdef><para>Warn if there are missing includes. For detailed information use --check-config</para></glossdef></glossentry></glosslist>
enable this when the whole program is scanned</para></glossdef></glossentry><glossentry><glossterm>missingInclude</glossterm><glossdef><para>Warn if there are missing includes</para></glossdef></glossentry></glosslist>
By default none of the additional checks are enabled. Several ids can be given if you separate them with commas, e.g. --enable=style,unusedFunction. See also --std
</para>
</listitem>
Expand Down
5 changes: 4 additions & 1 deletion releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
release notes for cppcheck-2.11

- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.
- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.
- It is no longer necessary to run "--check-config" to get detailed "missingInclude" and "missingIncludeSystem" messages. They will always be issued in the regular analysis if "missingInclude" is enabled.
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied
9 changes: 4 additions & 5 deletions test/cli/test-helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,15 @@ def test_build_dir_dump_output():
assert '</dump>' in dump, 'invalid dump data: ...' + dump[-100:]

def __test_missing_include_system(use_j):
args = '--enable=missingInclude --suppress=zerodiv helloworld'
args = ['--enable=missingInclude', '--suppress=zerodiv', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', 'helloworld']
if use_j:
args = '-j2 ' + args
args.insert(0, '-j2')

_, _, stderr = cppcheck(args.split())
assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]\n\n'
_, _, stderr = cppcheck(args)
assert stderr.replace('\\', '/') == 'helloworld/main.c:1:0: information: Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n'

def test_missing_include_system():
__test_missing_include_system(False)

@pytest.mark.xfail
def test_missing_include_system_j(): #11283
__test_missing_include_system(True)
11 changes: 5 additions & 6 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ def __test_missing_include(tmpdir, use_j):
#include "test.h"
""")

args = '--enable=missingInclude {}'.format(test_file)
args = ['--enable=missingInclude', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
if use_j:
args = '-j2 ' + args
args.insert(0, '-j2')

_, _, stderr = cppcheck(args.split())
assert stderr == 'nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude]\n\n'
_, _, stderr = cppcheck(args)
assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file)

def test_missing_include(tmpdir):
__test_missing_include(tmpdir, False)

@pytest.mark.xfail
def test_missing_include_j(tmpdir): #11283
__test_missing_include(tmpdir, True)

Expand All @@ -40,7 +39,7 @@ def __test_missing_include_check_config(tmpdir, use_j):
args = '-j2 ' + args

_, _, stderr = cppcheck(args.split())
assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n\n^\n'.format(test_file)
assert stderr == '' # --check-config no longer reports the missing includes

def test_missing_include_check_config(tmpdir):
__test_missing_include_check_config(tmpdir, False)
Expand Down
16 changes: 16 additions & 0 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,19 @@ void TestFixture::reportErr(const ErrorMessage &msg)
if (errout.str().find(errormessage) == std::string::npos)
errout << errormessage << std::endl;
}

void TestFixture::setTemplateFormat(const std::string &templateFormat)
{
if (templateFormat == "multiline") {
mTemplateFormat = "{file}:{line}:{severity}:{message}";
mTemplateLocation = "{file}:{line}:note:{info}";
}
else if (templateFormat == "simple") {
mTemplateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
mTemplateLocation = "";
}
else {
mTemplateFormat = templateFormat;
mTemplateLocation = "";
}
}
Loading