Skip to content

Commit

Permalink
Clang import; This experimental feature didn't "take off" much. After…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
danmar committed Apr 21, 2021
1 parent b5aaf8d commit 207361b
Show file tree
Hide file tree
Showing 32 changed files with 8 additions and 3,505 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ jobs:
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
cd test/cli || exit /b !errorlevel!
python -m pytest --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
python -m pytest test-helloworld.py || exit /b !errorlevel!
python -m pytest test-inline-suppress.py || exit /b !errorlevel!
python -m pytest test-more-projects.py || exit /b !errorlevel!
Expand Down
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \
$(libcppdir)/checkunusedfunctions.o \
$(libcppdir)/checkunusedvar.o \
$(libcppdir)/checkvaarg.o \
$(libcppdir)/clangimport.o \
$(libcppdir)/cppcheck.o \
$(libcppdir)/ctu.o \
$(libcppdir)/errorlogger.o \
Expand Down Expand Up @@ -233,7 +232,6 @@ TESTOBJ = test/options.o \
test/testbufferoverrun.o \
test/testbughuntingchecks.o \
test/testcharvar.o \
test/testclangimport.o \
test/testclass.o \
test/testcmdlineparser.o \
test/testcondition.o \
Expand Down Expand Up @@ -493,10 +491,7 @@ $(libcppdir)/checkunusedvar.o: lib/checkunusedvar.cpp externals/simplecpp/simple
$(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
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/checkvaarg.o $(libcppdir)/checkvaarg.cpp

$(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
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/clangimport.o $(libcppdir)/clangimport.cpp

$(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
$(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
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/cppcheck.o $(libcppdir)/cppcheck.cpp

$(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
Expand Down Expand Up @@ -622,9 +617,6 @@ test/testbughuntingchecks.o: test/testbughuntingchecks.cpp lib/astutils.h lib/co
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
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testcharvar.o test/testcharvar.cpp

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
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclangimport.o test/testclangimport.cpp

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
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testclass.o test/testclass.cpp

Expand Down
14 changes: 2 additions & 12 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}

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

else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
Expand Down Expand Up @@ -992,18 +989,11 @@ void CmdLineParser::printHelp()
" * faster analysis; Cppcheck will reuse the results if\n"
" the hash for a file is unchanged.\n"
" * some useful debug information, i.e. commands used to\n"
" execute clang/clang-tidy/addons.\n"
" execute clang-tidy/addons.\n"
" --check-config Check cppcheck configuration. The normal code\n"
" analysis is disabled by this flag.\n"
" --check-library Show information messages when library files have\n"
" incomplete info.\n"
" --clang=<path> Experimental: Use Clang parser instead of the builtin Cppcheck\n"
" parser. Takes the executable as optional parameter and\n"
" defaults to `clang`. Cppcheck will run the given Clang\n"
" executable, import the Clang AST and convert it into\n"
" Cppcheck data. After that the normal Cppcheck analysis is\n"
" used. You must have the executable in PATH if no path is\n"
" given.\n"
" --config-exclude=<dir>\n"
" Path (prefix) to be excluded from configuration\n"
" checking. Preprocessor configurations defined in\n"
Expand Down
1 change: 0 additions & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ Settings MainWindow::getCppcheckSettings()
result.userDefines += define.toStdString();
}

result.clang = mProjectFile->clangParser;
result.bugHunting = mProjectFile->bugHunting;
result.bugHuntingReport = " ";

Expand Down
17 changes: 1 addition & 16 deletions gui/projectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
void ProjectFile::clear()
{
const Settings settings;
clangParser = false;
bugHunting = false;
mRootPath.clear();
mBuildDir.clear();
Expand All @@ -62,7 +61,7 @@ void ProjectFile::clear()
mPlatform.clear();
mSuppressions.clear();
mAddons.clear();
mClangAnalyzer = mClangTidy = false;
mClangTidy = false;
mAnalyzeAllVsConfigs = false;
mCheckHeaders = true;
mCheckUnusedTemplates = true;
Expand Down Expand Up @@ -118,9 +117,6 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
mAnalyzeAllVsConfigs = readBool(xmlReader);

if (xmlReader.name() == CppcheckXml::Parser)
clangParser = true;

if (xmlReader.name() == CppcheckXml::BugHunting)
bugHunting = true;

Expand Down Expand Up @@ -186,7 +182,6 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == CppcheckXml::ToolsElementName) {
QStringList tools;
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
mClangTidy = tools.contains(CLANG_TIDY);
}

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

if (clangParser) {
xmlWriter.writeStartElement(CppcheckXml::Parser);
xmlWriter.writeCharacters("clang");
xmlWriter.writeEndElement();
}

if (bugHunting) {
xmlWriter.writeStartElement(CppcheckXml::BugHunting);
xmlWriter.writeEndElement();
Expand Down Expand Up @@ -1016,8 +1005,6 @@ bool ProjectFile::write(const QString &filename)
CppcheckXml::AddonElementName);

QStringList tools;
if (mClangAnalyzer)
tools << CLANG_ANALYZER;
if (mClangTidy)
tools << CLANG_TIDY;
writeStringList(xmlWriter,
Expand Down Expand Up @@ -1077,8 +1064,6 @@ QStringList ProjectFile::fromNativeSeparators(const QStringList &paths)
QStringList ProjectFile::getAddonsAndTools() const
{
QStringList ret(mAddons);
if (mClangAnalyzer)
ret << CLANG_ANALYZER;
if (mClangTidy)
ret << CLANG_TIDY;
return ret;
Expand Down
14 changes: 0 additions & 14 deletions gui/projectfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ class ProjectFile : public QObject {
*/
QStringList getAddonsAndTools() const;

bool getClangAnalyzer() const {
return false; //mClangAnalyzer;
}

void setClangAnalyzer(bool c) {
mClangAnalyzer = c;
}

bool getClangTidy() const {
return mClangTidy;
}
Expand Down Expand Up @@ -388,9 +380,6 @@ class ProjectFile : public QObject {
mCheckUnknownFunctionReturn = s;
}

/** Use Clang parser */
bool clangParser;

/** Bug hunting */
bool bugHunting;
protected:
Expand Down Expand Up @@ -583,9 +572,6 @@ class ProjectFile : public QObject {
*/
QStringList mAddons;

/** @brief Execute clang analyzer? */
bool mClangAnalyzer;

/** @brief Execute clang-tidy? */
bool mClangTidy;

Expand Down
7 changes: 0 additions & 7 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,6 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI.mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
mUI.mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
mUI.mMaxTemplateRecursion->setValue(projectFile->getMaxTemplateRecursion());
if (projectFile->clangParser)
mUI.mBtnClangParser->setChecked(true);
else
mUI.mBtnCppcheckParser->setChecked(true);
mUI.mBtnSafeClasses->setChecked(projectFile->safeChecks.classes);
mUI.mBtnBugHunting->setChecked(projectFile->bugHunting);
setExcludedPaths(projectFile->getExcludedPaths());
Expand Down Expand Up @@ -341,7 +337,6 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI.mAddonMisra->setText(mUI.mAddonMisra->text() + ' ' + tr("(no rule texts file)"));
}

mUI.mToolClangAnalyzer->setChecked(projectFile->getClangAnalyzer());
mUI.mToolClangTidy->setChecked(projectFile->getClangTidy());
if (CheckThread::clangTidyCmd().isEmpty()) {
mUI.mToolClangTidy->setText(tr("Clang-tidy (not found)"));
Expand All @@ -368,7 +363,6 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setCheckPaths(getCheckPaths());
projectFile->setExcludedPaths(getExcludedPaths());
projectFile->setLibraries(getLibraries());
projectFile->clangParser = mUI.mBtnClangParser->isChecked();
projectFile->safeChecks.classes = mUI.mBtnSafeClasses->isChecked();
projectFile->bugHunting = mUI.mBtnBugHunting->isChecked();
if (mUI.mComboBoxPlatform->currentText().endsWith(".xml"))
Expand Down Expand Up @@ -408,7 +402,6 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
if (mUI.mAddonMisra->isChecked())
list << "misra";
projectFile->setAddons(list);
projectFile->setClangAnalyzer(mUI.mToolClangAnalyzer->isChecked());
projectFile->setClangTidy(mUI.mToolClangTidy->isChecked());
projectFile->setTags(mUI.mEditTags->text().split(";", QString::SkipEmptyParts));
}
Expand Down
26 changes: 0 additions & 26 deletions gui/projectfiledialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -426,32 +426,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_10">
<property name="title">
<string>Parser</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QRadioButton" name="mBtnCppcheckParser">
<property name="text">
<string>Cppcheck (built in)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mBtnClangParser">
<property name="text">
<string>Clang (experimental)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_11">
<property name="title">
Expand Down
4 changes: 0 additions & 4 deletions gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
QChartView *chartView;
chartView = createChart(statsFile, "cppcheck");
mUI.mTabHistory->layout()->addWidget(chartView);
if (projectFile->getClangAnalyzer()) {
chartView = createChart(statsFile, CLANG_ANALYZER);
mUI.mTabHistory->layout()->addWidget(chartView);
}
if (projectFile->getClangTidy()) {
chartView = createChart(statsFile, CLANG_TIDY);
mUI.mTabHistory->layout()->addWidget(chartView);
Expand Down
2 changes: 1 addition & 1 deletion lib/bughuntingchecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static void divByZero(const Token *tok, const ExprEngine::Value &value, ExprEngi
if (tok->astParent()->astOperand2() == tok && value.isEqual(dataBase, 0)) {
const char * const id = (tok->valueType() && tok->valueType()->isFloat()) ? "bughuntingDivByZeroFloat" : "bughuntingDivByZero";
const bool bailout = (value.type == ExprEngine::ValueType::BailoutValue);
dataBase->reportError(dataBase->settings->clang ? tok : tok->astParent(),
dataBase->reportError(tok->astParent(),
Severity::SeverityType::error,
id,
"There is division, cannot determine that there can't be a division by zero.",
Expand Down
3 changes: 0 additions & 3 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ void CheckLeakAutoVar::doubleFreeError(const Token *tok, const Token *prevFreeTo

void CheckLeakAutoVar::check()
{
if (mSettings->clang)
return;

const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();

// Local variables that are known to be non-zero.
Expand Down
3 changes: 0 additions & 3 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,6 @@ void CheckMemoryLeakInClass::publicAllocationError(const Token *tok, const std::

void CheckMemoryLeakStructMember::check()
{
if (mSettings->clang)
return;

const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || !var->isLocal() || var->isStatic() || var->isReference())
Expand Down
3 changes: 0 additions & 3 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,9 +884,6 @@ void CheckOther::unreachableCodeError(const Token *tok, bool inconclusive)
//---------------------------------------------------------------------------
void CheckOther::checkVariableScope()
{
if (mSettings->clang)
return;

if (!mSettings->severity.isEnabled(Severity::style))
return;

Expand Down
3 changes: 0 additions & 3 deletions lib/checkuninitvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class CPPCHECKLIB CheckUninitVar : public Check {

/** @brief Run checks against the normal token list */
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) OVERRIDE {
if (settings->clang)
return;

CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger);
checkUninitVar.check();
checkUninitVar.valueFlowUninit();
Expand Down
3 changes: 0 additions & 3 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,6 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (!mSettings->severity.isEnabled(Severity::style))
return;

if (mSettings->clang)
return;

// Parse all executing scopes..
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();

Expand Down
2 changes: 0 additions & 2 deletions lib/checkvaarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ void CheckVaarg::referenceAs_va_start_error(const Token *tok, const std::string&

void CheckVaarg::va_list_usage()
{
if (mSettings->clang)
return;
const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || var->isPointer() || var->isReference() || var->isArray() || !var->scope() || var->typeStartToken()->str() != "va_list")
Expand Down

0 comments on commit 207361b

Please sign in to comment.