Visitar URL original
ExprEngine: Add new experimental path-sensitive data flow analysis. I… · napcode/cppcheck@2d651b0 · GitHub
Skip to content

Commit 2d651b0

Browse files
committed
ExprEngine: Add new experimental path-sensitive data flow analysis. Initially used for 'verification' but could possibly later be used as a complement in the normal analysis. The code is work-in-progress and hacky!
1 parent a8456b5 commit 2d651b0

9 files changed

Lines changed: 935 additions & 0 deletions

File tree

‎Makefile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ LIBOBJ = $(libcppdir)/analyzerinfo.o \
171171
$(libcppdir)/cppcheck.o \
172172
$(libcppdir)/ctu.o \
173173
$(libcppdir)/errorlogger.o \
174+
$(libcppdir)/exprengine.o \
174175
$(libcppdir)/importproject.o \
175176
$(libcppdir)/library.o \
176177
$(libcppdir)/mathlib.o \
@@ -213,6 +214,7 @@ TESTOBJ = test/options.o \
213214
test/testcppcheck.o \
214215
test/testerrorlogger.o \
215216
test/testexceptionsafety.o \
217+
test/testexprengine.o \
216218
test/testfilelister.o \
217219
test/testfunctions.o \
218220
test/testgarbage.o \
@@ -463,6 +465,9 @@ $(libcppdir)/ctu.o: lib/ctu.cpp lib/ctu.h lib/check.h lib/config.h lib/errorlogg
463465
$(libcppdir)/errorlogger.o: lib/errorlogger.cpp lib/errorlogger.h lib/config.h lib/suppressions.h lib/cppcheck.h lib/analyzerinfo.h lib/importproject.h lib/platform.h lib/utils.h lib/check.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/timer.h lib/token.h lib/valueflow.h lib/templatesimplifier.h lib/tokenize.h lib/tokenlist.h lib/path.h externals/tinyxml/tinyxml2.h
464466
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/errorlogger.o $(libcppdir)/errorlogger.cpp
465467

468+
$(libcppdir)/exprengine.o: lib/exprengine.cpp lib/exprengine.h lib/mathlib.h lib/config.h lib/settings.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/utils.h lib/library.h lib/standards.h lib/timer.h lib/symboldatabase.h lib/token.h lib/valueflow.h lib/templatesimplifier.h lib/tokenize.h lib/tokenlist.h
469+
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/exprengine.o $(libcppdir)/exprengine.cpp
470+
466471
$(libcppdir)/importproject.o: lib/importproject.cpp lib/importproject.h lib/config.h lib/platform.h lib/utils.h lib/path.h lib/settings.h lib/errorlogger.h lib/suppressions.h lib/library.h lib/mathlib.h lib/standards.h lib/timer.h externals/tinyxml/tinyxml2.h lib/token.h lib/valueflow.h lib/templatesimplifier.h lib/tokenize.h lib/tokenlist.h externals/picojson.h
467472
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(libcppdir)/importproject.o $(libcppdir)/importproject.cpp
468473

@@ -574,6 +579,9 @@ test/testerrorlogger.o: test/testerrorlogger.cpp lib/config.h lib/cppcheck.h lib
574579
test/testexceptionsafety.o: test/testexceptionsafety.cpp lib/checkexceptionsafety.h lib/check.h lib/config.h lib/errorlogger.h lib/suppressions.h lib/settings.h lib/importproject.h lib/platform.h lib/utils.h lib/library.h lib/mathlib.h lib/standards.h lib/timer.h lib/token.h lib/valueflow.h lib/templatesimplifier.h lib/tokenize.h lib/tokenlist.h test/testsuite.h
575580
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testexceptionsafety.o test/testexceptionsafety.cpp
576581

582+
test/testexprengine.o: test/testexprengine.cpp lib/exprengine.h lib/mathlib.h lib/config.h lib/settings.h lib/errorlogger.h lib/suppressions.h lib/importproject.h lib/platform.h lib/utils.h lib/library.h lib/standards.h lib/timer.h lib/symboldatabase.h lib/token.h lib/valueflow.h lib/templatesimplifier.h lib/tokenize.h lib/tokenlist.h test/testsuite.h
583+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testexprengine.o test/testexprengine.cpp
584+
577585
test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/pathmatch.h lib/config.h test/testsuite.h lib/errorlogger.h lib/suppressions.h
578586
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CPPFILESDIR) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o test/testfilelister.o test/testfilelister.cpp
579587

‎cli/cmdlineparser.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
189189
else if (std::strcmp(argv[i], "--safe-functions") == 0)
190190
mSettings->safeChecks.externalFunctions = mSettings->safeChecks.internalFunctions = true;
191191

192+
// Experimental: Verify
193+
else if (std::strcmp(argv[i], "--verify") == 0)
194+
mSettings->verification = true;
195+
192196
// Enforce language (--language=, -x)
193197
else if (std::strncmp(argv[i], "--language=", 11) == 0 || std::strcmp(argv[i], "-x") == 0) {
194198
std::string str;

‎lib/cppcheck.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "tokenlist.h"
3333
#include "version.h"
3434

35+
#include "exprengine.h"
36+
3537
#define PICOJSON_USE_INT64
3638
#include <picojson.h>
3739
#include <simplecpp.h>
@@ -725,6 +727,11 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
725727
check->runChecks(&tokenizer, &mSettings, this);
726728
}
727729

730+
// Verification using ExprEngine..
731+
if (mSettings.verification) {
732+
ExprEngine::runChecks(this, &tokenizer, &mSettings);
733+
}
734+
728735
// Analyse the tokens..
729736

730737
CTU::FileInfo *fi1 = CTU::getFileInfo(&tokenizer);

0 commit comments

Comments
 (0)