From 201540a3f2abe103797351306f2fac945b0e0f9a Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 3 Mar 2025 17:09:49 +0100 Subject: [PATCH] use forward declarations for `ValueFlow::Value` in more cases --- lib/checkbufferoverrun.cpp | 1 + lib/checkbufferoverrun.h | 6 +++++- lib/checknullpointer.cpp | 8 ++++++++ lib/checknullpointer.h | 12 ++++++------ lib/infer.cpp | 1 + lib/infer.h | 6 +++++- lib/symboldatabase.cpp | 1 + lib/valueflow.h | 6 +++++- lib/vf_common.cpp | 1 + lib/vf_common.h | 6 +++++- 10 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index b33ea6dec8e..2c5e9ada26a 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -35,6 +35,7 @@ #include "tokenlist.h" #include "utils.h" #include "valueflow.h" +#include "vfvalue.h" #include #include diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 116b9ed7c8c..d945fd7b1e5 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -25,7 +25,6 @@ #include "check.h" #include "config.h" #include "ctu.h" -#include "vfvalue.h" #include #include @@ -41,6 +40,11 @@ class Variable; struct Dimension; enum class Certainty : std::uint8_t; +namespace ValueFlow +{ + class Value; +} + /// @addtogroup Checks /// @{ diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 58b897d931f..f8b7a3385f2 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -32,6 +32,7 @@ #include "tokenize.h" #include "tokenlist.h" #include "valueflow.h" +#include "vfvalue.h" #include #include @@ -433,6 +434,13 @@ void CheckNullPointer::nullConstantDereference() } } +void CheckNullPointer::nullPointerError(const Token *tok) +{ + ValueFlow::Value v(0); + v.setKnown(); + nullPointerError(tok, "", &v, false); +} + void CheckNullPointer::nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value *value, bool inconclusive) { const std::string errmsgcond("$symbol:" + varname + '\n' + ValueFlow::eitherTheConditionIsRedundant(value ? value->condition : nullptr) + " or there is possible null pointer dereference: $symbol."); diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index e4b7e20e36c..fb59771a64e 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -24,7 +24,6 @@ #include "check.h" #include "config.h" -#include "vfvalue.h" #include #include @@ -35,6 +34,11 @@ class Settings; class Token; class Tokenizer; +namespace ValueFlow +{ + class Value; +} + /// @addtogroup Checks /// @{ @@ -85,11 +89,7 @@ class CPPCHECKLIB CheckNullPointer : public Check { /** @brief dereferencing null constant (after Tokenizer::simplifyKnownVariables) */ void nullConstantDereference(); - void nullPointerError(const Token *tok) { - ValueFlow::Value v(0); - v.setKnown(); - nullPointerError(tok, "", &v, false); - } + void nullPointerError(const Token *tok); void nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value* value, bool inconclusive); /** @brief Parse current TU and extract file info */ diff --git a/lib/infer.cpp b/lib/infer.cpp index 1d888949a4e..cad0761f68b 100644 --- a/lib/infer.cpp +++ b/lib/infer.cpp @@ -22,6 +22,7 @@ #include "errortypes.h" #include "token.h" #include "valueptr.h" +#include "vfvalue.h" #include #include diff --git a/lib/infer.h b/lib/infer.h index 5cd8a8d3c87..8d66d7da016 100644 --- a/lib/infer.h +++ b/lib/infer.h @@ -21,7 +21,6 @@ #include "config.h" #include "mathlib.h" -#include "vfvalue.h" #include #include @@ -30,6 +29,11 @@ class Token; template class ValuePtr; +namespace ValueFlow +{ + class Value; +} + struct InferModel { virtual bool match(const ValueFlow::Value& value) const = 0; virtual ValueFlow::Value yield(MathLib::bigint value) const = 0; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 4b7158add45..52dc28cb18f 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -35,6 +35,7 @@ #include "tokenlist.h" #include "utils.h" #include "valueflow.h" +#include "vfvalue.h" #include #include diff --git a/lib/valueflow.h b/lib/valueflow.h index 924f29dbfca..af3715e474a 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -24,7 +24,6 @@ #include "config.h" #include "errortypes.h" #include "mathlib.h" -#include "vfvalue.h" #include #include @@ -43,6 +42,11 @@ class ValueType; class Variable; class Scope; +namespace ValueFlow +{ + class Value; +} + namespace ValueFlow { /// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues). const Value * valueFlowConstantFoldAST(Token *expr, const Settings &settings); diff --git a/lib/vf_common.cpp b/lib/vf_common.cpp index 5a1c1ff1b45..0c4f3028451 100644 --- a/lib/vf_common.cpp +++ b/lib/vf_common.cpp @@ -27,6 +27,7 @@ #include "symboldatabase.h" #include "token.h" #include "valueflow.h" +#include "vfvalue.h" #include "vf_settokenvalue.h" diff --git a/lib/vf_common.h b/lib/vf_common.h index 79e467ed241..64000b979cf 100644 --- a/lib/vf_common.h +++ b/lib/vf_common.h @@ -23,7 +23,6 @@ #include "mathlib.h" #include "sourcelocation.h" #include "symboldatabase.h" -#include "vfvalue.h" #include #include @@ -32,6 +31,11 @@ class Token; class Settings; class Platform; +namespace ValueFlow +{ + class Value; +} + namespace ValueFlow { bool getMinMaxValues(const ValueType* vt, const Platform& platform, MathLib::bigint& minValue, MathLib::bigint& maxValue);