Skip to content

Commit d2d2124

Browse files
committed
Revert "Clang import; This experimental feature didn't "take off" much. After a lot of work we are still far fram the goal. I remove it now but don't rule out completely that it could ever be added again."
This reverts commit 207361b.
1 parent 59ef068 commit d2d2124

32 files changed

Lines changed: 3505 additions & 8 deletions

.github/workflows/CI-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
122122
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
123123
cd test/cli || exit /b !errorlevel!
124+
python -m pytest --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
124125
python -m pytest test-helloworld.py || exit /b !errorlevel!
125126
python -m pytest test-inline-suppress.py || exit /b !errorlevel!
126127
python -m pytest test-more-projects.py || exit /b !errorlevel!

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \
185185
$(libcppdir)/checkunusedfunctions.o \
186186
$(libcppdir)/checkunusedvar.o \
187187
$(libcppdir)/checkvaarg.o \
188+
$(libcppdir)/clangimport.o \
188189
$(libcppdir)/cppcheck.o \
189190
$(libcppdir)/ctu.o \
190191
$(libcppdir)/errorlogger.o \
@@ -232,6 +233,7 @@ TESTOBJ = test/options.o \
232233
test/testbufferoverrun.o \
233234
test/testbughuntingchecks.o \
234235
test/testcharvar.o \
236+
test/testclangimport.o \
235237
test/testclass.o \
236238
test/testcmdlineparser.o \
237239
test/testcondition.o \
@@ -491,7 +493,10 @@ $(libcppdir)/checkunusedvar.o: lib/checkunusedvar.cpp externals/simplecpp/simple
491493
$(libcppdir)/checkvaarg.o: lib/checkvaarg.cpp lib/astutils.h lib/check.h lib/checkvaarg.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h
492494
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/checkvaarg.o $(libcppdir)/checkvaarg.cpp
493495

494-
$(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/astutils.h lib/check.h lib/checkunusedfunctions.h lib/config.h lib/cppcheck.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/exprengine.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/version.h
496+
$(libcppdir)/clangimport.o: lib/clangimport.cpp lib/astutils.h lib/clangimport.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h
497+
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/clangimport.o $(libcppdir)/clangimport.cpp
498+
499+
$(libcppdir)/cppcheck.o: lib/cppcheck.cpp externals/picojson/picojson.h externals/simplecpp/simplecpp.h externals/tinyxml2/tinyxml2.h lib/analyzerinfo.h lib/astutils.h lib/check.h lib/checkunusedfunctions.h lib/clangimport.h lib/config.h lib/cppcheck.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/exprengine.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/version.h
495500
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/cppcheck.o $(libcppdir)/cppcheck.cpp
496501

497502
$(libcppdir)/ctu.o: lib/ctu.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/check.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h
@@ -617,6 +622,9 @@ test/testbughuntingchecks.o: test/testbughuntingchecks.cpp lib/astutils.h lib/co
617622
test/testcharvar.o: test/testcharvar.cpp lib/astutils.h lib/check.h lib/checkother.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
618623
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testcharvar.o test/testcharvar.cpp
619624

625+
test/testclangimport.o: test/testclangimport.cpp lib/astutils.h lib/clangimport.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
626+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclangimport.o test/testclangimport.cpp
627+
620628
test/testclass.o: test/testclass.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/check.h lib/checkclass.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h test/testsuite.h
621629
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclass.o test/testclass.cpp
622630

cli/cmdlineparser.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
235235
}
236236

237237
else if (std::strncmp(argv[i], "--clang", 7) == 0) {
238-
printMessage("Cppcheck: Clang import has been removed");
238+
mSettings->clang = true;
239+
if (std::strncmp(argv[i], "--clang=", 8) == 0) {
240+
mSettings->clangExecutable = argv[i] + 8;
241+
}
239242
}
240243

241244
else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
@@ -989,11 +992,18 @@ void CmdLineParser::printHelp()
989992
" * faster analysis; Cppcheck will reuse the results if\n"
990993
" the hash for a file is unchanged.\n"
991994
" * some useful debug information, i.e. commands used to\n"
992-
" execute clang-tidy/addons.\n"
995+
" execute clang/clang-tidy/addons.\n"
993996
" --check-config Check cppcheck configuration. The normal code\n"
994997
" analysis is disabled by this flag.\n"
995998
" --check-library Show information messages when library files have\n"
996999
" incomplete info.\n"
1000+
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
1001+
" parser. Takes the executable as optional parameter and\n"
1002+
" defaults to `clang`. Cppcheck will run the given Clang\n"
1003+
" executable, import the Clang AST and convert it into\n"
1004+
" Cppcheck data. After that the normal Cppcheck analysis is\n"
1005+
" used. You must have the executable in PATH if no path is\n"
1006+
" given.\n"
9971007
" --config-exclude=<dir>\n"
9981008
" Path (prefix) to be excluded from configuration\n"
9991009
" checking. Preprocessor configurations defined in\n"

gui/mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ Settings MainWindow::getCppcheckSettings()
873873
result.userDefines += define.toStdString();
874874
}
875875

876+
result.clang = mProjectFile->clangParser;
876877
result.bugHunting = mProjectFile->bugHunting;
877878
result.bugHuntingReport = " ";
878879

gui/projectfile.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
4545
void ProjectFile::clear()
4646
{
4747
const Settings settings;
48+
clangParser = false;
4849
bugHunting = false;
4950
mRootPath.clear();
5051
mBuildDir.clear();
@@ -61,7 +62,7 @@ void ProjectFile::clear()
6162
mPlatform.clear();
6263
mSuppressions.clear();
6364
mAddons.clear();
64-
mClangTidy = false;
65+
mClangAnalyzer = mClangTidy = false;
6566
mAnalyzeAllVsConfigs = false;
6667
mCheckHeaders = true;
6768
mCheckUnusedTemplates = true;
@@ -117,6 +118,9 @@ bool ProjectFile::read(const QString &filename)
117118
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
118119
mAnalyzeAllVsConfigs = readBool(xmlReader);
119120

121+
if (xmlReader.name() == CppcheckXml::Parser)
122+
clangParser = true;
123+
120124
if (xmlReader.name() == CppcheckXml::BugHunting)
121125
bugHunting = true;
122126

@@ -182,6 +186,7 @@ bool ProjectFile::read(const QString &filename)
182186
if (xmlReader.name() == CppcheckXml::ToolsElementName) {
183187
QStringList tools;
184188
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
189+
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
185190
mClangTidy = tools.contains(CLANG_TIDY);
186191
}
187192

@@ -870,6 +875,12 @@ bool ProjectFile::write(const QString &filename)
870875
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
871876
xmlWriter.writeEndElement();
872877

878+
if (clangParser) {
879+
xmlWriter.writeStartElement(CppcheckXml::Parser);
880+
xmlWriter.writeCharacters("clang");
881+
xmlWriter.writeEndElement();
882+
}
883+
873884
if (bugHunting) {
874885
xmlWriter.writeStartElement(CppcheckXml::BugHunting);
875886
xmlWriter.writeEndElement();
@@ -1005,6 +1016,8 @@ bool ProjectFile::write(const QString &filename)
10051016
CppcheckXml::AddonElementName);
10061017

10071018
QStringList tools;
1019+
if (mClangAnalyzer)
1020+
tools << CLANG_ANALYZER;
10081021
if (mClangTidy)
10091022
tools << CLANG_TIDY;
10101023
writeStringList(xmlWriter,
@@ -1064,6 +1077,8 @@ QStringList ProjectFile::fromNativeSeparators(const QStringList &paths)
10641077
QStringList ProjectFile::getAddonsAndTools() const
10651078
{
10661079
QStringList ret(mAddons);
1080+
if (mClangAnalyzer)
1081+
ret << CLANG_ANALYZER;
10671082
if (mClangTidy)
10681083
ret << CLANG_TIDY;
10691084
return ret;

gui/projectfile.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class ProjectFile : public QObject {
192192
*/
193193
QStringList getAddonsAndTools() const;
194194

195+
bool getClangAnalyzer() const {
196+
return false; //mClangAnalyzer;
197+
}
198+
199+
void setClangAnalyzer(bool c) {
200+
mClangAnalyzer = c;
201+
}
202+
195203
bool getClangTidy() const {
196204
return mClangTidy;
197205
}
@@ -380,6 +388,9 @@ class ProjectFile : public QObject {
380388
mCheckUnknownFunctionReturn = s;
381389
}
382390

391+
/** Use Clang parser */
392+
bool clangParser;
393+
383394
/** Bug hunting */
384395
bool bugHunting;
385396
protected:
@@ -572,6 +583,9 @@ class ProjectFile : public QObject {
572583
*/
573584
QStringList mAddons;
574585

586+
/** @brief Execute clang analyzer? */
587+
bool mClangAnalyzer;
588+
575589
/** @brief Execute clang-tidy? */
576590
bool mClangTidy;
577591

gui/projectfiledialog.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
270270
mUI.mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
271271
mUI.mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
272272
mUI.mMaxTemplateRecursion->setValue(projectFile->getMaxTemplateRecursion());
273+
if (projectFile->clangParser)
274+
mUI.mBtnClangParser->setChecked(true);
275+
else
276+
mUI.mBtnCppcheckParser->setChecked(true);
273277
mUI.mBtnSafeClasses->setChecked(projectFile->safeChecks.classes);
274278
mUI.mBtnBugHunting->setChecked(projectFile->bugHunting);
275279
setExcludedPaths(projectFile->getExcludedPaths());
@@ -337,6 +341,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
337341
mUI.mAddonMisra->setText(mUI.mAddonMisra->text() + ' ' + tr("(no rule texts file)"));
338342
}
339343

344+
mUI.mToolClangAnalyzer->setChecked(projectFile->getClangAnalyzer());
340345
mUI.mToolClangTidy->setChecked(projectFile->getClangTidy());
341346
if (CheckThread::clangTidyCmd().isEmpty()) {
342347
mUI.mToolClangTidy->setText(tr("Clang-tidy (not found)"));
@@ -363,6 +368,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
363368
projectFile->setCheckPaths(getCheckPaths());
364369
projectFile->setExcludedPaths(getExcludedPaths());
365370
projectFile->setLibraries(getLibraries());
371+
projectFile->clangParser = mUI.mBtnClangParser->isChecked();
366372
projectFile->safeChecks.classes = mUI.mBtnSafeClasses->isChecked();
367373
projectFile->bugHunting = mUI.mBtnBugHunting->isChecked();
368374
if (mUI.mComboBoxPlatform->currentText().endsWith(".xml"))
@@ -402,6 +408,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
402408
if (mUI.mAddonMisra->isChecked())
403409
list << "misra";
404410
projectFile->setAddons(list);
411+
projectFile->setClangAnalyzer(mUI.mToolClangAnalyzer->isChecked());
405412
projectFile->setClangTidy(mUI.mToolClangTidy->isChecked());
406413
projectFile->setTags(mUI.mEditTags->text().split(";", QString::SkipEmptyParts));
407414
}

gui/projectfiledialog.ui

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,32 @@
426426
</layout>
427427
</widget>
428428
</item>
429+
<item>
430+
<widget class="QGroupBox" name="groupBox_10">
431+
<property name="title">
432+
<string>Parser</string>
433+
</property>
434+
<layout class="QVBoxLayout" name="verticalLayout_14">
435+
<item>
436+
<widget class="QRadioButton" name="mBtnCppcheckParser">
437+
<property name="text">
438+
<string>Cppcheck (built in)</string>
439+
</property>
440+
<property name="checked">
441+
<bool>true</bool>
442+
</property>
443+
</widget>
444+
</item>
445+
<item>
446+
<widget class="QRadioButton" name="mBtnClangParser">
447+
<property name="text">
448+
<string>Clang (experimental)</string>
449+
</property>
450+
</widget>
451+
</item>
452+
</layout>
453+
</widget>
454+
</item>
429455
<item>
430456
<widget class="QGroupBox" name="groupBox_11">
431457
<property name="title">

gui/statsdialog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
6969
QChartView *chartView;
7070
chartView = createChart(statsFile, "cppcheck");
7171
mUI.mTabHistory->layout()->addWidget(chartView);
72+
if (projectFile->getClangAnalyzer()) {
73+
chartView = createChart(statsFile, CLANG_ANALYZER);
74+
mUI.mTabHistory->layout()->addWidget(chartView);
75+
}
7276
if (projectFile->getClangTidy()) {
7377
chartView = createChart(statsFile, CLANG_TIDY);
7478
mUI.mTabHistory->layout()->addWidget(chartView);

lib/bughuntingchecks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static void divByZero(const Token *tok, const ExprEngine::Value &value, ExprEngi
211211
if (tok->astParent()->astOperand2() == tok && value.isEqual(dataBase, 0)) {
212212
const char * const id = (tok->valueType() && tok->valueType()->isFloat()) ? "bughuntingDivByZeroFloat" : "bughuntingDivByZero";
213213
const bool bailout = (value.type == ExprEngine::ValueType::BailoutValue);
214-
dataBase->reportError(tok->astParent(),
214+
dataBase->reportError(dataBase->settings->clang ? tok : tok->astParent(),
215215
Severity::SeverityType::error,
216216
id,
217217
"There is division, cannot determine that there can't be a division by zero.",

0 commit comments

Comments
 (0)