Skip to content

Commit cd18c30

Browse files
committed
ValueFlow: extracted valueFlowDebug() into separate file
1 parent 8c95e39 commit cd18c30

File tree

8 files changed

+100
-22
lines changed

8 files changed

+100
-22
lines changed

Diff for: Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ LIBOBJ = $(libcppdir)/valueflow.o \
255255
$(libcppdir)/vf_array.o \
256256
$(libcppdir)/vf_bitand.o \
257257
$(libcppdir)/vf_common.o \
258+
$(libcppdir)/vf_debug.o \
258259
$(libcppdir)/vf_enumvalue.o \
259260
$(libcppdir)/vf_globalconstvar.o \
260261
$(libcppdir)/vf_globalstaticvar.o \
@@ -472,7 +473,7 @@ validateRules:
472473

473474
###### Build
474475

475-
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.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 lib/valueptr.h lib/vf_analyze.h lib/vf_array.h lib/vf_bitand.h lib/vf_common.h lib/vf_enumvalue.h lib/vf_globalconstvar.h lib/vf_globalstaticvar.h lib/vf_number.h lib/vf_pointeralias.h lib/vf_sameexpressions.h lib/vf_settokenvalue.h lib/vf_string.h lib/vf_unknownfunctionreturn.h lib/vfvalue.h
476+
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.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 lib/valueptr.h lib/vf_analyze.h lib/vf_array.h lib/vf_bitand.h lib/vf_common.h lib/vf_debug.h lib/vf_enumvalue.h lib/vf_globalconstvar.h lib/vf_globalstaticvar.h lib/vf_number.h lib/vf_pointeralias.h lib/vf_sameexpressions.h lib/vf_settokenvalue.h lib/vf_string.h lib/vf_unknownfunctionreturn.h lib/vfvalue.h
476477
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
477478

478479
$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.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 lib/vfvalue.h
@@ -667,6 +668,9 @@ $(libcppdir)/vf_bitand.o: lib/vf_bitand.cpp lib/config.h lib/mathlib.h lib/sourc
667668
$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
668669
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp
669670

671+
$(libcppdir)/vf_debug.o: lib/vf_debug.cpp lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_debug.h lib/vfvalue.h
672+
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_debug.cpp
673+
670674
$(libcppdir)/vf_enumvalue.o: lib/vf_enumvalue.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_enumvalue.h lib/vfvalue.h
671675
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp
672676

Diff for: lib/cppcheck.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<ClCompile Include="vf_array.cpp" />
9191
<ClCompile Include="vf_bitand.cpp" />
9292
<ClCompile Include="vf_common.cpp" />
93+
<ClCompile Include="vf_debug.cpp" />
9394
<ClCompile Include="vf_enumvalue.cpp" />
9495
<ClCompile Include="vf_globalconstvar.cpp" />
9596
<ClCompile Include="vf_globalstaticvar.cpp" />
@@ -182,6 +183,7 @@
182183
<ClInclude Include="vf_array.h" />
183184
<ClInclude Include="vf_bitand.h" />
184185
<ClInclude Include="vf_common.h" />
186+
<ClInclude Include="vf_debug.h" />
185187
<ClInclude Include="vf_enumvalue.h" />
186188
<ClInclude Include="vf_globalconstvar.h" />
187189
<ClInclude Include="vf_globalstaticvar.h" />

Diff for: lib/lib.pri

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ HEADERS += $${PWD}/addoninfo.h \
8181
$${PWD}/vf_array.h \
8282
$${PWD}/vf_bitand.h \
8383
$${PWD}/vf_common.h \
84+
$${PWD}/vf_debug.h \
8485
$${PWD}/vf_enumvalue.h \
8586
$${PWD}/vf_globalconstvar.h \
8687
$${PWD}/vf_globalstaticvar.h \
@@ -158,6 +159,7 @@ SOURCES += $${PWD}/valueflow.cpp \
158159
$${PWD}/vf_array.cpp \
159160
$${PWD}/vf_bitand.cpp \
160161
$${PWD}/vf_common.cpp \
162+
$${PWD}/vf_debug.cpp \
161163
$${PWD}/vf_enumvalue.cpp \
162164
$${PWD}/vf_globalconstvar.cpp \
163165
$${PWD}/vf_globalstaticvar.cpp \

Diff for: lib/valueflow.cpp

+1-20
Original file line numberDiff line numberDiff line change
@@ -8098,25 +8098,6 @@ static void valueFlowSafeFunctions(const TokenList& tokenlist, const SymbolDatab
80988098
}
80998099
}
81008100

8101-
static void valueFlowDebug(TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings)
8102-
{
8103-
if (!settings.debugnormal && !settings.debugwarnings)
8104-
return;
8105-
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
8106-
if (tok->getTokenDebug() != TokenDebug::ValueFlow)
8107-
continue;
8108-
if (tok->astParent() && tok->astParent()->getTokenDebug() == TokenDebug::ValueFlow)
8109-
continue;
8110-
for (const ValueFlow::Value& v : tok->values()) {
8111-
std::string msg = "The value is " + debugString(v);
8112-
ErrorPath errorPath = v.errorPath;
8113-
errorPath.insert(errorPath.end(), v.debugPath.cbegin(), v.debugPath.cend());
8114-
errorPath.emplace_back(tok, "");
8115-
errorLogger.reportErr({errorPath, &tokenlist, Severity::debug, "valueFlow", msg, CWE{0}, Certainty::normal});
8116-
}
8117-
}
8118-
}
8119-
81208101
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(Token *expr, const Settings &settings)
81218102
{
81228103
if (expr && expr->values().empty()) {
@@ -8387,7 +8368,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
83878368

83888369
runner.run_once({
83898370
VFA(valueFlowDynamicBufferSize(tokenlist, symboldatabase, errorLogger, settings)),
8390-
VFA(valueFlowDebug(tokenlist, errorLogger, settings)),
8371+
VFA(analyzeDebug(tokenlist, errorLogger, settings)),
83918372
});
83928373
}
83938374

Diff for: lib/vf_analyze.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "vf_array.h" // IWYU pragma: export
2323
#include "vf_bitand.h" // IWYU pragma: export
24+
#include "vf_debug.h" // IWYU pragma: export
2425
#include "vf_enumvalue.h" // IWYU pragma: export
2526
#include "vf_globalconstvar.h" // IWYU pragma: export
2627
#include "vf_globalstaticvar.h" // IWYU pragma: export

Diff for: lib/vf_debug.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2024 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "vf_debug.h"
20+
21+
#include "errorlogger.h"
22+
#include "errortypes.h"
23+
#include "settings.h"
24+
#include "token.h"
25+
#include "tokenlist.h"
26+
#include "vfvalue.h"
27+
28+
#include "vf_common.h"
29+
30+
#include <list>
31+
#include <string>
32+
33+
namespace ValueFlow
34+
{
35+
void analyzeDebug(TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings)
36+
{
37+
if (!settings.debugnormal && !settings.debugwarnings)
38+
return;
39+
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
40+
if (tok->getTokenDebug() != TokenDebug::ValueFlow)
41+
continue;
42+
if (tok->astParent() && tok->astParent()->getTokenDebug() == TokenDebug::ValueFlow)
43+
continue;
44+
for (const Value& v : tok->values()) {
45+
std::string msg = "The value is " + debugString(v);
46+
ErrorPath errorPath = v.errorPath;
47+
errorPath.insert(errorPath.end(), v.debugPath.cbegin(), v.debugPath.cend());
48+
errorPath.emplace_back(tok, "");
49+
errorLogger.reportErr({errorPath, &tokenlist, Severity::debug, "valueFlow", msg, CWE{0}, Certainty::normal});
50+
}
51+
}
52+
}
53+
}

Diff for: lib/vf_debug.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2024 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef vfDebugH
20+
#define vfDebugH
21+
22+
class TokenList;
23+
class ErrorLogger;
24+
class Settings;
25+
26+
namespace ValueFlow
27+
{
28+
void analyzeDebug(TokenList& tokenlist, ErrorLogger& errorLogger, const Settings& settings);
29+
}
30+
31+
#endif // vfDebugH

Diff for: oss-fuzz/Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ LIBOBJ = $(libcppdir)/valueflow.o \
9898
$(libcppdir)/vf_array.o \
9999
$(libcppdir)/vf_bitand.o \
100100
$(libcppdir)/vf_common.o \
101+
$(libcppdir)/vf_debug.o \
101102
$(libcppdir)/vf_enumvalue.o \
102103
$(libcppdir)/vf_globalconstvar.o \
103104
$(libcppdir)/vf_globalstaticvar.o \
@@ -151,7 +152,7 @@ simplecpp.o: ../externals/simplecpp/simplecpp.cpp ../externals/simplecpp/simplec
151152
tinyxml2.o: ../externals/tinyxml2/tinyxml2.cpp ../externals/tinyxml2/tinyxml2.h
152153
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ ../externals/tinyxml2/tinyxml2.cpp
153154

154-
$(libcppdir)/valueflow.o: ../lib/valueflow.cpp ../lib/addoninfo.h ../lib/analyzer.h ../lib/astutils.h ../lib/calculate.h ../lib/check.h ../lib/checkuninitvar.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/findtoken.h ../lib/forwardanalyzer.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/programmemory.h ../lib/reverseanalyzer.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.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 ../lib/valueptr.h ../lib/vf_analyze.h ../lib/vf_array.h ../lib/vf_bitand.h ../lib/vf_common.h ../lib/vf_enumvalue.h ../lib/vf_globalconstvar.h ../lib/vf_globalstaticvar.h ../lib/vf_number.h ../lib/vf_pointeralias.h ../lib/vf_sameexpressions.h ../lib/vf_settokenvalue.h ../lib/vf_string.h ../lib/vf_unknownfunctionreturn.h ../lib/vfvalue.h
155+
$(libcppdir)/valueflow.o: ../lib/valueflow.cpp ../lib/addoninfo.h ../lib/analyzer.h ../lib/astutils.h ../lib/calculate.h ../lib/check.h ../lib/checkuninitvar.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/findtoken.h ../lib/forwardanalyzer.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/programmemory.h ../lib/reverseanalyzer.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.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 ../lib/valueptr.h ../lib/vf_analyze.h ../lib/vf_array.h ../lib/vf_bitand.h ../lib/vf_common.h ../lib/vf_debug.h ../lib/vf_enumvalue.h ../lib/vf_globalconstvar.h ../lib/vf_globalstaticvar.h ../lib/vf_number.h ../lib/vf_pointeralias.h ../lib/vf_sameexpressions.h ../lib/vf_settokenvalue.h ../lib/vf_string.h ../lib/vf_unknownfunctionreturn.h ../lib/vfvalue.h
155156
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
156157

157158
$(libcppdir)/tokenize.o: ../lib/tokenize.cpp ../externals/simplecpp/simplecpp.h ../lib/addoninfo.h ../lib/astutils.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/preprocessor.h ../lib/settings.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/summaries.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 ../lib/vfvalue.h
@@ -346,6 +347,9 @@ $(libcppdir)/vf_bitand.o: ../lib/vf_bitand.cpp ../lib/config.h ../lib/mathlib.h
346347
$(libcppdir)/vf_common.o: ../lib/vf_common.cpp ../lib/addoninfo.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/vf_common.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h
347348
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp
348349

350+
$(libcppdir)/vf_debug.o: ../lib/vf_debug.cpp ../lib/addoninfo.h ../lib/color.h ../lib/config.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/settings.h ../lib/sourcelocation.h ../lib/standards.h ../lib/suppressions.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vf_common.h ../lib/vf_debug.h ../lib/vfvalue.h
351+
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_debug.cpp
352+
349353
$(libcppdir)/vf_enumvalue.o: ../lib/vf_enumvalue.cpp ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/utils.h ../lib/valueflow.h ../lib/vf_enumvalue.h ../lib/vfvalue.h
350354
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp
351355

0 commit comments

Comments
 (0)