Skip to content

Commit 7fd4118

Browse files
authored
Fix #10039 (integrate --check-config include findings with normal analysis) / also fixes #11283 (cppcheck-opensource#3229)
1 parent 50eb064 commit 7fd4118

15 files changed

Lines changed: 125 additions & 228 deletions

.github/workflows/CI-unixish.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,6 @@ jobs:
449449
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"
450450
ec=0
451451
452-
# work around missingInclude not being reported with -j and the --check-config requirement for detailed warnings
453-
./cppcheck $selfcheck_options -DCHECK_INTERNAL cli lib --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
454-
./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
455-
./cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp --check-config --suppress=missingIncludeSystem --suppress=unmatchedSuppression || ec=1
456-
./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
457-
458452
# early exit
459453
if [ $ec -eq 1 ]; then
460454
exit $ec

.github/workflows/asan.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-22.04
1414

1515
env:
16+
QT_VERSION: 5.15.2
1617
ASAN_OPTIONS: detect_stack_use_after_return=1
1718

1819
steps:
@@ -35,9 +36,16 @@ jobs:
3536
chmod +x llvm.sh
3637
sudo ./llvm.sh 16
3738
39+
- name: Install Qt ${{ env.QT_VERSION }}
40+
uses: jurplel/install-qt-action@v3
41+
with:
42+
version: ${{ env.QT_VERSION }}
43+
modules: 'qtcharts'
44+
cache: true
45+
3846
- name: CMake
3947
run: |
40-
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
48+
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
4149
env:
4250
CC: clang-16
4351
CXX: clang++-16
@@ -53,6 +61,12 @@ jobs:
5361
- name: Run tests
5462
run: ./cmake.output/bin/testrunner
5563

64+
- name: Generate dependencies
65+
run: |
66+
# make sure auto-generated GUI files exist
67+
make -C cmake.output autogen
68+
make -C cmake.output gui-build-deps triage-build-ui-deps
69+
5670
# TODO: this is currently way too slow (~60 minutes) to enable it
5771
# TODO: only fail the step on sanitizer issues
5872
- name: Self check
@@ -61,7 +75,7 @@ jobs:
6175
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"
6276
ec=0
6377
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1
64-
./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
78+
./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
6579
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
66-
./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
80+
./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
6781
exit $ec

.github/workflows/ubsan.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-22.04
1414

1515
env:
16+
QT_VERSION: 5.15.2
1617
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1
1718

1819
steps:
@@ -35,9 +36,16 @@ jobs:
3536
chmod +x llvm.sh
3637
sudo ./llvm.sh 16
3738
39+
- name: Install Qt ${{ env.QT_VERSION }}
40+
uses: jurplel/install-qt-action@v3
41+
with:
42+
version: ${{ env.QT_VERSION }}
43+
modules: 'qtcharts'
44+
cache: true
45+
3846
- name: CMake
3947
run: |
40-
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
48+
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
4149
env:
4250
CC: clang-16
4351
CXX: clang++-16
@@ -53,13 +61,19 @@ jobs:
5361
- name: Run tests
5462
run: ./cmake.output/bin/testrunner
5563

64+
- name: Generate dependencies
65+
run: |
66+
# make sure auto-generated GUI files exist
67+
make -C cmake.output autogen
68+
make -C cmake.output gui-build-deps triage-build-ui-deps
69+
5670
# TODO: only fail the step on sanitizer issues
5771
- name: Self check
5872
run: |
5973
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"
6074
ec=0
6175
./cmake.output/bin/cppcheck $selfcheck_options --addon=naming.json -DCHECK_INTERNAL cli lib || ec=1
62-
./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
76+
./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
6377
./cmake.output/bin/cppcheck $selfcheck_options -Icli test/*.cpp tools/*.cpp || ec=1
64-
./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
78+
./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
6579
exit $ec

.selfcheck_suppressions

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
missingIncludeSystem
12
shadowFunction
23
bitwiseOnBoolean
34

@@ -11,7 +12,9 @@ simplifyUsing:gui/temp/moc_*.cpp
1112
funcArgNamesDifferent:gui/temp/moc_*.cpp
1213
symbolDatabaseWarning:tools/triage/temp/moc_*.cpp
1314
naming-varname:gui/temp/ui_*.h
15+
naming-varname:cmake.output/gui/ui_*.h
1416
functionStatic:gui/temp/ui_fileview.h
17+
functionStatic:cmake.output/gui/ui_fileview.h
1518

1619
# --debug-warnings suppressions
1720
valueFlowBailout

cli/cmdlineparser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,7 @@ void CmdLineParser::printHelp()
11361136
" to only enable this when the whole program is\n"
11371137
" scanned.\n"
11381138
" * missingInclude\n"
1139-
" Warn if there are missing includes. For\n"
1140-
" detailed information, use '--check-config'.\n"
1139+
" Warn if there are missing includes.\n"
11411140
" Several ids can be given if you separate them with\n"
11421141
" commas. See also --std\n"
11431142
" --error-exitcode=<n> If errors are found, integer [n] is returned instead of\n"

cli/cppcheckexecutor.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,6 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
198198

199199
int CppCheckExecutor::check(int argc, const char* const argv[])
200200
{
201-
Preprocessor::missingIncludeFlag = false;
202-
Preprocessor::missingSystemIncludeFlag = false;
203-
204201
CheckUnusedFunctions::clear();
205202

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

381378
if (!settings.checkConfiguration) {
382379
cppcheck.tooManyConfigsError(emptyString,0U);
383-
384-
if (settings.checks.isEnabled(Checks::missingInclude) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
385-
const std::list<ErrorMessage::FileLocation> callStack;
386-
ErrorMessage msg(callStack,
387-
emptyString,
388-
Severity::information,
389-
"Cppcheck cannot find all the include files (use --check-config for details)\n"
390-
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
391-
"include files found. But the results will probably be more accurate if all the include "
392-
"files are found. Please check your project's include directories and add all of them "
393-
"as include directories for Cppcheck. To see what files Cppcheck cannot find use "
394-
"--check-config.",
395-
"",
396-
Certainty::normal);
397-
if (Preprocessor::missingIncludeFlag) {
398-
msg.id = "missingInclude";
399-
reportInfo(msg);
400-
}
401-
if (Preprocessor::missingSystemIncludeFlag) {
402-
msg.id = "missingIncludeSystem";
403-
reportInfo(msg);
404-
}
405-
}
406380
}
407381

408382
if (settings.xml) {

lib/preprocessor.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ Directive::Directive(std::string _file, const int _linenr, const std::string &_s
6262
str(trim(_str))
6363
{}
6464

65-
std::atomic<bool> Preprocessor::missingIncludeFlag;
66-
std::atomic<bool> Preprocessor::missingSystemIncludeFlag;
67-
6865
char Preprocessor::macroChar = char(1);
6966

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

842839
std::string fname = Path::fromNativeSeparators(filename);
840+
std::string errorId = (headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude";
843841
Suppressions::ErrorMessage errorMessage;
844-
errorMessage.errorId = "missingInclude";
842+
errorMessage.errorId = errorId;
845843
errorMessage.setFileName(std::move(fname));
846844
errorMessage.lineNumber = linenr;
847845
if (mSettings.nomsg.isSuppressed(errorMessage))
848846
return;
849-
errorMessage.errorId = "missingIncludeSystem";
850-
if (headerType == SystemHeader && mSettings.nomsg.isSuppressed(errorMessage))
851-
return;
852-
853-
if (headerType == SystemHeader)
854-
missingSystemIncludeFlag = true;
855-
else
856-
missingIncludeFlag = true;
857-
858-
if (mErrorLogger && mSettings.checkConfiguration) {
859847

848+
if (mErrorLogger) {
860849
std::list<ErrorMessage::FileLocation> locationList;
861850
if (!filename.empty()) {
862851
ErrorMessage::FileLocation loc;
863852
loc.line = linenr;
864853
loc.setfile(Path::toNativeSeparators(filename));
865854
locationList.push_back(std::move(loc));
866855
}
867-
ErrorMessage errmsg(locationList, mFile0, Severity::information,
856+
ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information,
868857
(headerType==SystemHeader) ?
869858
"Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." :
870859
"Include file: \"" + header + "\" not found.",
871-
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
860+
std::move(errorId),
872861
Certainty::normal);
873-
mErrorLogger->reportInfo(errmsg);
862+
mErrorLogger->reportErr(errmsg);
874863
}
875864
}
876865

877866
void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
878867
{
879868
Settings settings2(*settings);
880869
Preprocessor preprocessor(settings2, errorLogger);
881-
settings2.checkConfiguration = true;
882870
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
883871
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
884872
preprocessor.error(emptyString, 1, "#error message"); // #error ..

lib/preprocessor.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "config.h"
2525

26-
#include <atomic>
2726
#include <cstddef>
2827
#include <istream>
2928
#include <list>
@@ -87,9 +86,6 @@ class CPPCHECKLIB Preprocessor {
8786
explicit Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr);
8887
virtual ~Preprocessor();
8988

90-
static std::atomic<bool> missingIncludeFlag;
91-
static std::atomic<bool> missingSystemIncludeFlag;
92-
9389
void inlineSuppressions(const simplecpp::TokenList &tokens);
9490

9591
void setDirectives(const simplecpp::TokenList &tokens);

man/cppcheck.1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Example: '-UDEBUG'</para>
295295
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
296296
severities 'style', 'performance' and 'portability' are
297297
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
298-
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>
298+
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>
299299
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
300300
</para>
301301
</listitem>

releasenotes.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
release notes for cppcheck-2.11
22

3-
- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.
3+
- The platform type 'Unspecified' within .cppcheck projects has been deprecated and will be removed in Cppcheck 2.14. Please use 'unspecified' instead.
4+
- 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.
5+
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
6+
- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied

0 commit comments

Comments
 (0)