Cppcheck
Classes | Macros | Enumerations | Functions
valueflow.cpp File Reference
#include "valueflow.h"
#include "analyzer.h"
#include "astutils.h"
#include "calculate.h"
#include "checkuninitvar.h"
#include "config.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "findtoken.h"
#include "forwardanalyzer.h"
#include "infer.h"
#include "library.h"
#include "mathlib.h"
#include "path.h"
#include "platform.h"
#include "programmemory.h"
#include "reverseanalyzer.h"
#include "settings.h"
#include "smallvector.h"
#include "sourcelocation.h"
#include "standards.h"
#include "symboldatabase.h"
#include "timer.h"
#include "token.h"
#include "tokenlist.h"
#include "utils.h"
#include "valueptr.h"
#include "vfvalue.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <functional>
#include <initializer_list>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

Go to the source code of this file.

Classes

struct  SingleRange< T >
 
class  SelectValueFromVarIdMapRange
 
struct  SelectValueFromVarIdMapRange::Iterator
 
struct  ValueFlowAnalyzer
 
struct  ValueFlowAnalyzer::ConditionState
 
struct  SingleValueFlowAnalyzer
 
struct  ExpressionAnalyzer
 
struct  SameExpressionAnalyzer
 
struct  OppositeExpressionAnalyzer
 
struct  SubExpressionAnalyzer
 
struct  MemberExpressionAnalyzer
 
struct  LifetimeStore
 
struct  Lambda
 
struct  SymbolicInferModel
 
struct  ConditionHandler
 
struct  ConditionHandler::Condition
 
struct  SimpleConditionHandler
 
struct  IntegralInferModel
 
struct  IteratorInferModel
 
struct  EndIteratorInferModel
 
struct  StartIteratorInferModel
 
struct  SymbolicConditionHandler
 
struct  MultiValueFlowAnalyzer
 
struct  IteratorRange< Iterator >
 
struct  ContainerExpressionAnalyzer
 
struct  IteratorConditionHandler
 
struct  ContainerConditionHandler
 
struct  ValueFlowState
 
struct  ValueFlowPass
 
struct  ValueFlowPassRunner
 
struct  ValueFlowPassAdaptor< F >
 

Macros

#define bailout2(type, tokenlist, errorLogger, tok, what)   bailoutInternal((type), (tokenlist), (errorLogger), (tok), (what), __FILE__, __LINE__, __func__)
 
#define bailout(tokenlist, errorLogger, tok, what)   bailout2("valueFlowBailout", (tokenlist), (errorLogger), (tok), (what))
 
#define bailoutIncompleteVar(tokenlist, errorLogger, tok, what)   bailoutInternal("valueFlowBailoutIncompleteVar", (tokenlist), (errorLogger), (tok), (what), "", 0, __func__)
 
#define VALUEFLOW_ADAPTOR(cpp, ...)
 
#define VFA(...)   VALUEFLOW_ADAPTOR(false, __VA_ARGS__)
 
#define VFA_CPP(...)   VALUEFLOW_ADAPTOR(true, __VA_ARGS__)
 

Enumerations

enum class  LifetimeCapture { Undefined , ByValue , ByReference }
 

Functions

static void bailoutInternal (const std::string &type, const TokenList &tokenlist, ErrorLogger &errorLogger, const Token *tok, const std::string &what, const std::string &file, int line, std::string function)
 This is the ValueFlow component in Cppcheck. More...
 
static std::string debugString (const ValueFlow::Value &v)
 
static void setSourceLocation (ValueFlow::Value &v, SourceLocation ctx, const Token *tok, SourceLocation local=SourceLocation::current())
 
static void changeKnownToPossible (std::list< ValueFlow::Value > &values, int indirect=-1)
 
static void removeImpossible (std::list< ValueFlow::Value > &values, int indirect=-1)
 
static void lowerToPossible (std::list< ValueFlow::Value > &values, int indirect=-1)
 
static void changePossibleToKnown (std::list< ValueFlow::Value > &values, int indirect=-1)
 
static bool isNonConditionalPossibleIntValue (const ValueFlow::Value &v)
 
static void setValueUpperBound (ValueFlow::Value &value, bool upper)
 
static void setValueBound (ValueFlow::Value &value, const Token *tok, bool invert)
 
static void setConditionalValue (ValueFlow::Value &value, const Token *tok, MathLib::bigint i)
 
static void setConditionalValues (const Token *tok, bool lhs, MathLib::bigint value, ValueFlow::Value &true_value, ValueFlow::Value &false_value)
 
static bool isSaturated (MathLib::bigint value)
 
static void parseCompareEachInt (const Token *tok, const std::function< void(const Token *varTok, ValueFlow::Value true_value, ValueFlow::Value false_value)> &each, const std::function< std::vector< ValueFlow::Value >(const Token *)> &evaluate)
 
static void parseCompareEachInt (const Token *tok, const std::function< void(const Token *varTok, ValueFlow::Value true_value, ValueFlow::Value false_value)> &each)
 
static bool isEscapeScope (const Token *tok, const Settings &settings, bool unknown=false)
 
static ValueFlow::Value castValue (ValueFlow::Value value, const ValueType::Sign sign, nonneg int bit)
 
static bool isNumeric (const ValueFlow::Value &value)
 
static const TokengetCastTypeStartToken (const Token *parent, const Settings &settings)
 
static bool isNonInvertibleOperation (const Token *tok)
 
static bool isComputableValue (const Token *parent, const ValueFlow::Value &value)
 
static Library::Container::Yield getContainerYield (Token *tok, const Settings &settings, Token **parent=nullptr)
 
static void setTokenValueCast (Token *parent, const ValueType &valueType, const ValueFlow::Value &value, const Settings &settings)
 Set token value for cast. More...
 
static bool isCompatibleValueTypes (ValueFlow::Value::ValueType x, ValueFlow::Value::ValueType y)
 
static bool isCompatibleValues (const ValueFlow::Value &value1, const ValueFlow::Value &value2)
 
static ValueFlow::Value truncateImplicitConversion (Token *parent, const ValueFlow::Value &value, const Settings &settings)
 
static long long truncateIntValue (long long value, size_t value_size, const ValueType::Sign dst_sign)
 
static void setTokenValue (Token *tok, ValueFlow::Value value, const Settings &settings, SourceLocation loc=SourceLocation::current())
 set ValueFlow value and perform calculations if possible More...
 
template<class F >
static size_t accumulateStructMembers (const Scope *scope, F f)
 
static size_t bitCeil (size_t x)
 
static size_t getAlignOf (const ValueType &vt, const Settings &settings, int maxRecursion=0)
 
static nonneg int getSizeOfType (const Token *typeTok, const Settings &settings)
 
static bool getMinMaxValues (const ValueType *vt, const Platform &platform, MathLib::bigint &minValue, MathLib::bigint &maxValue)
 
static TokenvalueFlowSetConstantValue (Token *tok, const Settings &settings)
 
static void valueFlowNumber (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowString (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowArray (TokenList &tokenlist, const Settings &settings)
 
static bool isNonZero (const Token *tok)
 
static const TokengetOtherOperand (const Token *tok)
 
static void valueFlowArrayBool (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowArrayElement (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowPointerAlias (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowBitAnd (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowSameExpressions (TokenList &tokenlist, const Settings &settings)
 
static bool getExpressionRange (const Token *expr, MathLib::bigint *minvalue, MathLib::bigint *maxvalue)
 
static void valueFlowRightShift (TokenList &tokenList, const Settings &settings)
 
static std::vector< MathLib::bigintminUnsignedValue (const Token *tok, int depth=8)
 
static bool isConvertedToIntegral (const Token *tok, const Settings &settings)
 
static bool isSameToken (const Token *tok1, const Token *tok2)
 
static void valueFlowImpossibleValues (TokenList &tokenList, const Settings &settings)
 
static void valueFlowEnumValue (SymbolDatabase &symboldatabase, const Settings &settings)
 
static void valueFlowGlobalConstVar (TokenList &tokenList, const Settings &settings)
 
static void valueFlowGlobalStaticVar (TokenList &tokenList, const Settings &settings)
 
static ValuePtr< AnalyzermakeAnalyzer (const Token *exprTok, ValueFlow::Value value, const TokenList &tokenlist, const Settings &settings)
 
static ValuePtr< AnalyzermakeReverseAnalyzer (const Token *exprTok, ValueFlow::Value value, const TokenList &tokenlist, const Settings &settings)
 
static Analyzer::Result valueFlowForward (Token *startToken, const Token *endToken, const Token *exprTok, ValueFlow::Value value, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static Analyzer::Result valueFlowForward (Token *startToken, const Token *endToken, const Token *exprTok, std::list< ValueFlow::Value > values, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
template<class ValueOrValues >
static Analyzer::Result valueFlowForward (Token *startToken, const Token *exprTok, ValueOrValues v, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static Analyzer::Result valueFlowForwardRecursive (Token *top, const Token *exprTok, std::list< ValueFlow::Value > values, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static void valueFlowReverse (Token *tok, const Token *const endToken, const Token *const varToken, std::list< ValueFlow::Value > values, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static void valueFlowReverse (const TokenList &tokenlist, Token *tok, const Token *const varToken, ValueFlow::Value val, ErrorLogger &errorLogger, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static bool isConditionKnown (const Token *tok, bool then)
 
static const std::string & invertAssign (const std::string &assign)
 
static std::string removeAssign (const std::string &assign)
 
template<class T , class U >
static T calculateAssign (const std::string &assign, const T &x, const U &y, bool *error=nullptr)
 
template<class T , class U >
static void assignValueIfMutable (T &x, const U &y)
 
template<class T , class U >
static void assignValueIfMutable (const T &, const U &)
 
template<class Value , REQUIRES("Value must ValueFlow::Value", std::is_convertible< Value &, const ValueFlow::Value & >) >
static bool evalAssignment (Value &lhsValue, const std::string &assign, const ValueFlow::Value &rhsValue)
 
static ValueFlow::Value::MoveKind isMoveOrForward (const Token *tok)
 
template<class T >
static SingleRange< T > MakeSingleRange (T &x)
 
template<typename V >
static bool isAliasOf (const Variable *var, const Token *tok, nonneg int varid, const V &values, bool *inconclusive=nullptr)
 
static bool bifurcate (const Token *tok, const std::set< nonneg int > &varids, const Settings &settings, int depth=20)
 
static bool bifurcateVariableChanged (const Variable *var, const std::set< nonneg int > &varids, const Token *start, const Token *end, const Settings &settings, int depth=20)
 
static std::string lifetimeType (const Token *tok, const ValueFlow::Value *val)
 
static bool hasUniqueOwnership (const Token *tok)
 
static bool derefShared (const Token *tok)
 
template<class Predicate >
static std::vector< ValueFlow::LifetimeTokengetLifetimeTokens (const Token *tok, bool escape, ValueFlow::Value::ErrorPath errorPath, Predicate pred, const Settings &settings, int depth=20)
 
static const TokengetLifetimeToken (const Token *tok, ValueFlow::Value::ErrorPath &errorPath, const Settings &settings, bool *addressOf=nullptr)
 
static bool isNotLifetimeValue (const ValueFlow::Value &val)
 
static bool isLifetimeOwned (const ValueType *vtParent)
 
static bool isLifetimeOwned (const ValueType *vt, const ValueType *vtParent)
 
static bool isLifetimeBorrowed (const ValueType *vt, const ValueType *vtParent)
 
static const TokenskipCVRefs (const Token *tok, const Token *endTok)
 
static bool isNotEqual (std::pair< const Token *, const Token * > x, std::pair< const Token *, const Token * > y)
 
static bool isNotEqual (std::pair< const Token *, const Token * > x, const std::string &y, bool cpp)
 
static bool isNotEqual (std::pair< const Token *, const Token * > x, const ValueType *y, bool cpp)
 
static bool isDifferentType (const Token *src, const Token *dst)
 
static void valueFlowLifetimeFunction (Token *tok, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowLifetimeConstructor (Token *tok, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isRangeForScope (const Scope *scope)
 
static const TokengetEndOfVarScope (const Variable *var)
 
static void valueFlowForwardLifetime (Token *tok, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool hasBorrowingVariables (const std::list< Variable > &vars, const std::vector< const Token * > &args, int depth=10)
 
static void valueFlowLifetimeUserConstructor (Token *tok, const Function *constructor, const std::string &name, const std::vector< const Token * > &args, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isScope (const Token *tok)
 
static const FunctionfindConstructor (const Scope *scope, const Token *tok, const std::vector< const Token * > &args)
 
static void valueFlowLifetimeClassConstructor (Token *tok, const Type *t, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isDecayedPointer (const Token *tok)
 
static bool isConvertedToView (const Token *tok, const Settings &settings)
 
static bool isContainerOfPointers (const Token *tok, const Settings &settings)
 
static void valueFlowLifetime (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isStdMoveOrStdForwarded (Token *tok, ValueFlow::Value::MoveKind *moveKind, Token **varTok=nullptr)
 
static bool isOpenParenthesisMemberFunctionCallOfVarId (const Token *openParenthesisToken, nonneg int varId)
 
static TokenfindOpenParentesisOfMove (Token *moveVarTok)
 
static TokenfindEndOfFunctionCallForParameter (Token *parameterToken)
 
static void valueFlowAfterMove (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static const TokenfindIncompleteVar (const Token *start, const Token *end)
 
static ValueFlow::Value makeConditionValue (long long val, const Token *condTok, bool assume, bool impossible, const Settings &settings, SourceLocation loc=SourceLocation::current())
 
static std::vector< const Token * > getConditions (const Token *tok, const char *op)
 
static bool isBreakOrContinueScope (const Token *endToken)
 
static const ScopegetLoopScope (const Token *tok)
 
static void valueFlowConditionExpressions (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isTruncated (const ValueType *src, const ValueType *dst, const Settings &settings)
 
static void setSymbolic (ValueFlow::Value &value, const Token *tok)
 
static ValueFlow::Value makeSymbolic (const Token *tok, MathLib::bigint delta=0)
 
static std::set< nonneg int > getVarIds (const Token *tok)
 
static void valueFlowSymbolic (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static const TokenisStrlenOf (const Token *tok, const Token *expr, int depth=10)
 
static ValueFlow::Value inferCondition (const std::string &op, const Token *varTok, MathLib::bigint val)
 
static void valueFlowSymbolicOperators (const SymbolDatabase &symboldatabase, const Settings &settings)
 
static void valueFlowSymbolicInfer (const SymbolDatabase &symboldatabase, const Settings &settings)
 
template<class ContainerOfValue >
static void valueFlowForwardConst (Token *start, const Token *end, const Variable *var, const ContainerOfValue &values, const Settings &settings, int=0)
 
static void valueFlowForwardConst (Token *start, const Token *end, const Variable *var, const std::initializer_list< ValueFlow::Value > &values, const Settings &settings)
 
static ValueFlow::Value::Bound findVarBound (const Variable *var, const Token *start, const Token *end, const Settings &settings)
 
static bool isInitialVarAssign (const Token *tok)
 
static void valueFlowForwardAssign (Token *const tok, const Token *expr, std::vector< const Variable * > vars, std::list< ValueFlow::Value > values, const bool init, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowForwardAssign (Token *const tok, const Variable *const var, const std::list< ValueFlow::Value > &values, const bool, const bool init, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static std::list< ValueFlow::ValuetruncateValues (std::list< ValueFlow::Value > values, const ValueType *dst, const ValueType *src, const Settings &settings)
 
static bool isVariableInit (const Token *tok)
 
template<class C1 , class C2 >
static bool intersects (const C1 &c1, const C2 &c2)
 
static void valueFlowAfterAssign (TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings, const std::set< const Scope * > &skippedFunctions)
 
static std::vector< const Variable * > getVariables (const Token *tok)
 
static void valueFlowAfterSwap (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowSetConditionToKnown (const Token *tok, std::list< ValueFlow::Value > &values, bool then)
 
static bool isBreakScope (const Token *const endToken)
 
static void insertImpossible (std::list< ValueFlow::Value > &values, const std::list< ValueFlow::Value > &input)
 
static void insertNegateKnown (std::list< ValueFlow::Value > &values, const std::list< ValueFlow::Value > &input)
 
static void valueFlowCondition (const ValuePtr< ConditionHandler > &handler, TokenList &tokenlist, SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings, const std::set< const Scope * > &skippedFunctions)
 
static bool isIntegralOnlyOperator (const Token *tok)
 
static bool isIntegralOrPointer (const Token *tok)
 
static void valueFlowInferCondition (TokenList &tokenlist, const Settings &settings)
 
static bool valueFlowForLoop2 (const Token *tok, ProgramMemory *memory1, ProgramMemory *memory2, ProgramMemory *memoryAfter, const Settings &settings)
 
static void valueFlowForLoopSimplify (Token *const bodyStart, const Token *expr, bool globalvar, const MathLib::bigint value, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowForLoopSimplifyAfter (Token *fortok, nonneg int varid, const MathLib::bigint num, const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowForLoop (TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
template<class Key , class F >
static bool productParams (const Settings &settings, const std::unordered_map< Key, std::list< ValueFlow::Value >> &vars, F f)
 
static void valueFlowInjectParameter (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, const Scope *functionScope, const std::unordered_map< const Variable *, std::list< ValueFlow::Value >> &vars)
 
static void valueFlowInjectParameter (const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, const Variable *arg, const Scope *functionScope, const std::list< ValueFlow::Value > &argvalues)
 
static void valueFlowSwitchVariable (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static std::list< ValueFlow::ValuegetFunctionArgumentValues (const Token *argtok)
 
static void valueFlowLibraryFunction (Token *tok, const std::string &returnValue, const Settings &settings)
 
template<class Iterator >
static IteratorRange< Iterator > MakeIteratorRange (Iterator start, Iterator last)
 
static void valueFlowSubFunction (TokenList &tokenlist, SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowFunctionDefaultParameter (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static const ValueFlow::ValuegetKnownValueFromToken (const Token *tok)
 
static const ValueFlow::ValuegetKnownValueFromTokens (const std::vector< const Token * > &toks)
 
static void setFunctionReturnValue (const Function *f, Token *tok, ValueFlow::Value v, const Settings &settings)
 
static void valueFlowFunctionReturn (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool needsInitialization (const Variable *var)
 
static void addToErrorPath (ValueFlow::Value &value, const ValueFlow::Value &from)
 
static std::vector< Token * > findAllUsages (const Variable *var, Token *start, const Library &library)
 
static TokenfindStartToken (const Variable *var, Token *start, const Library &library)
 
static void valueFlowUninit (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static bool isContainerSizeChanged (const Token *expr, const Token *start, const Token *end, int indirect, const Settings &settings, int depth=20)
 
static bool isContainerSizeChangedByFunction (const Token *tok, int indirect, const Settings &settings, int depth=20)
 
static const TokenparseBinaryIntOp (const Token *expr, const std::function< std::vector< MathLib::bigint >(const Token *)> &eval, MathLib::bigint &known)
 
static const TokensolveExprValue (const Token *expr, ValueFlow::Value &value)
 
static void valueFlowSmartPointer (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
static Library::Container::Yield findIteratorYield (Token *tok, const Token **ftok, const Settings &settings)
 
static void valueFlowIterators (TokenList &tokenlist, const Settings &settings)
 
static std::list< ValueFlow::ValuegetIteratorValues (std::list< ValueFlow::Value > values, const ValueFlow::Value::ValueKind *kind=nullptr)
 
static void valueFlowIteratorInfer (TokenList &tokenlist, const Settings &settings)
 
static std::vector< ValueFlow::ValuegetContainerValues (const Token *tok)
 
static ValueFlow::Value makeContainerSizeValue (std::size_t s, bool known=true)
 
static std::vector< ValueFlow::ValuemakeContainerSizeValue (const Token *tok, bool known=true)
 
static std::vector< ValueFlow::ValuegetContainerSizeFromConstructorArgs (const std::vector< const Token * > &args, const Library::Container *container, bool known)
 
static bool valueFlowIsSameContainerType (const ValueType &contType, const Token *tok, const Settings &settings)
 
static std::vector< ValueFlow::ValuegetInitListSize (const Token *tok, const ValueType *valueType, const Settings &settings, bool known=true)
 
static std::vector< ValueFlow::ValuegetContainerSizeFromConstructor (const Token *tok, const ValueType *valueType, const Settings &settings, bool known=true)
 
static void valueFlowContainerSetTokValue (const TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings, const Token *tok, Token *initList)
 
static const ScopegetFunctionScope (const Scope *scope)
 
static MathLib::bigint valueFlowGetStrLength (const Token *tok)
 
static void valueFlowContainerSize (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings, const std::set< const Scope * > &skippedFunctions)
 
static void valueFlowDynamicBufferSize (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static bool getMinMaxValues (const std::string &typestr, const Settings &settings, bool cpp, MathLib::bigint &minvalue, MathLib::bigint &maxvalue)
 
static void valueFlowSafeFunctions (const TokenList &tokenlist, const SymbolDatabase &symboldatabase, ErrorLogger &errorLogger, const Settings &settings)
 
static void valueFlowUnknownFunctionReturn (TokenList &tokenlist, const Settings &settings)
 
static void valueFlowDebug (TokenList &tokenlist, ErrorLogger &errorLogger, const Settings &settings)
 
template<class F >
static ValueFlowPassAdaptor< F > makeValueFlowPassAdaptor (const char *name, bool cpp, F run)
 
static std::vector< ValueFlow::ValueisOutOfBoundsImpl (const ValueFlow::Value &size, const Token *indexTok, bool condition)
 

Macro Definition Documentation

◆ bailout

#define bailout (   tokenlist,
  errorLogger,
  tok,
  what 
)    bailout2("valueFlowBailout", (tokenlist), (errorLogger), (tok), (what))

Definition at line 144 of file valueflow.cpp.

◆ bailout2

#define bailout2 (   type,
  tokenlist,
  errorLogger,
  tok,
  what 
)    bailoutInternal((type), (tokenlist), (errorLogger), (tok), (what), __FILE__, __LINE__, __func__)

Definition at line 142 of file valueflow.cpp.

◆ bailoutIncompleteVar

#define bailoutIncompleteVar (   tokenlist,
  errorLogger,
  tok,
  what 
)    bailoutInternal("valueFlowBailoutIncompleteVar", (tokenlist), (errorLogger), (tok), (what), "", 0, __func__)

Definition at line 146 of file valueflow.cpp.

◆ VALUEFLOW_ADAPTOR

#define VALUEFLOW_ADAPTOR (   cpp,
  ... 
)
Value:
makeValueFlowPassAdaptor(#__VA_ARGS__, \
(cpp), \
[](TokenList& tokenlist, \
SymbolDatabase& symboldatabase, \
ErrorLogger& errorLogger, \
const Settings& settings, \
const std::set<const Scope*>& skippedFunctions) { \
(void)tokenlist; \
(void)symboldatabase; \
(void)errorLogger; \
(void)settings; \
(void)skippedFunctions; \
__VA_ARGS__; \
})
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
static ValueFlowPassAdaptor< F > makeValueFlowPassAdaptor(const char *name, bool cpp, F run)
Definition: valueflow.cpp:9580

Definition at line 9585 of file valueflow.cpp.

◆ VFA

#define VFA (   ...)    VALUEFLOW_ADAPTOR(false, __VA_ARGS__)

Definition at line 9601 of file valueflow.cpp.

◆ VFA_CPP

#define VFA_CPP (   ...)    VALUEFLOW_ADAPTOR(true, __VA_ARGS__)

Definition at line 9602 of file valueflow.cpp.

Enumeration Type Documentation

◆ LifetimeCapture

enum LifetimeCapture
strong
Enumerator
Undefined 
ByValue 
ByReference 

Definition at line 3462 of file valueflow.cpp.

Function Documentation

◆ accumulateStructMembers()

template<class F >
static size_t accumulateStructMembers ( const Scope scope,
f 
)
static

◆ addToErrorPath()

static void addToErrorPath ( ValueFlow::Value value,
const ValueFlow::Value from 
)
static

Definition at line 8030 of file valueflow.cpp.

References ValueFlow::Value::condition, and ValueFlow::Value::errorPath.

Referenced by valueFlowUninit().

◆ assignValueIfMutable() [1/2]

template<class T , class U >
static void assignValueIfMutable ( const T &  ,
const U &   
)
static

Definition at line 2308 of file valueflow.cpp.

◆ assignValueIfMutable() [2/2]

template<class T , class U >
static void assignValueIfMutable ( T &  x,
const U &  y 
)
static

Definition at line 2302 of file valueflow.cpp.

Referenced by evalAssignment().

◆ bailoutInternal()

static void bailoutInternal ( const std::string &  type,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Token tok,
const std::string &  what,
const std::string &  file,
int  line,
std::string  function 
)
static

This is the ValueFlow component in Cppcheck.

Each

See also
Token in the token list has a list of values. These are the "possible" values for the Token at runtime.

In the –debug and –debug-normal output you can see the ValueFlow data. For example:

int f()
{
    int x = 10;
    return 4 * x + 2;
}

The –debug-normal output says:

##Value flow
Line 3
  10 always 10
Line 4
  4 always 4
  * always 40
  x always 10
  + always 42
  2 always 2

All value flow analysis is executed in the ValueFlow::setValues() function. The ValueFlow analysis is executed after the tokenizer/ast/symboldatabase/etc.. The ValueFlow analysis is done in a series of valueFlow* function calls, where each such function call can only use results from previous function calls. The function calls should be arranged so that valueFlow* that do not require previous ValueFlow information should be first.

Type of analysis

This is "flow sensitive" value flow analysis. We usually track the value for 1 variable at a time.

How are calculations handled

Here is an example code:

x = 3 + 4;

The valueFlowNumber set the values for the "3" and "4" tokens by calling setTokenValue(). The setTokenValue() handle the calculations automatically. When both "3" and "4" have values, the "+" can be calculated. setTokenValue() recursively calls itself when parents in calculations can be calculated.

Forward / Reverse flow analysis

In forward value flow analysis we know a value and see what happens when we are stepping the program forward. Like normal execution. The valueFlowForward is used in this analysis.

In reverse value flow analysis we know the value of a variable at line X. And try to "execute backwards" to determine possible values before line X. The valueFlowReverse is used in this analysis.

Definition at line 131 of file valueflow.cpp.

References debug, TokenList::getSourceFilePath(), normal, ErrorLogger::reportErr(), and Path::stripDirectoryPart().

◆ bifurcate()

static bool bifurcate ( const Token tok,
const std::set< nonneg int > &  varids,
const Settings settings,
int  depth = 20 
)
static

◆ bifurcateVariableChanged()

static bool bifurcateVariableChanged ( const Variable var,
const std::set< nonneg int > &  varids,
const Token start,
const Token end,
const Settings settings,
int  depth = 20 
)
static

◆ bitCeil()

static size_t bitCeil ( size_t  x)
static

Definition at line 1148 of file valueflow.cpp.

Referenced by getAlignOf().

◆ calculateAssign()

template<class T , class U >
static T calculateAssign ( const std::string &  assign,
const T &  x,
const U &  y,
bool *  error = nullptr 
)
static

Definition at line 2289 of file valueflow.cpp.

References error, and removeAssign().

Referenced by evalAssignment().

◆ castValue()

static ValueFlow::Value castValue ( ValueFlow::Value  value,
const ValueType::Sign  sign,
nonneg int  bit 
)
static

◆ changeKnownToPossible()

static void changeKnownToPossible ( std::list< ValueFlow::Value > &  values,
int  indirect = -1 
)
static

◆ changePossibleToKnown()

static void changePossibleToKnown ( std::list< ValueFlow::Value > &  values,
int  indirect = -1 
)
static

◆ debugString()

static std::string debugString ( const ValueFlow::Value v)
static

◆ derefShared()

static bool derefShared ( const Token tok)
static

◆ evalAssignment()

template<class Value , REQUIRES("Value must ValueFlow::Value", std::is_convertible< Value &, const ValueFlow::Value & >) >
static bool evalAssignment ( Value &  lhsValue,
const std::string &  assign,
const ValueFlow::Value rhsValue 
)
static

◆ findAllUsages()

static std::vector<Token*> findAllUsages ( const Variable var,
Token start,
const Library library 
)
static

Definition at line 8049 of file valueflow.cpp.

References Scope::bodyEnd, findTokensSkipDeadCode(), and Variable::scope().

Referenced by findStartToken().

◆ findConstructor()

static const Function* findConstructor ( const Scope scope,
const Token tok,
const std::vector< const Token * > &  args 
)
static

◆ findEndOfFunctionCallForParameter()

static Token* findEndOfFunctionCallForParameter ( Token parameterToken)
static

◆ findIncompleteVar()

static const Token* findIncompleteVar ( const Token start,
const Token end 
)
static

Definition at line 5332 of file valueflow.cpp.

References Token::isIncompleteVar(), and Token::next().

Referenced by valueFlowConditionExpressions().

◆ findIteratorYield()

static Library::Container::Yield findIteratorYield ( Token tok,
const Token **  ftok,
const Settings settings 
)
static

Definition at line 8588 of file valueflow.cpp.

References astContainerYield(), astFunctionYield(), and Token::astParent().

Referenced by valueFlowIterators().

◆ findOpenParentesisOfMove()

static Token* findOpenParentesisOfMove ( Token moveVarTok)
static

Definition at line 5231 of file valueflow.cpp.

References Token::previous(), and Token::str().

Referenced by valueFlowAfterMove().

◆ findStartToken()

static Token* findStartToken ( const Variable var,
Token start,
const Library library 
)
static

◆ findVarBound()

static ValueFlow::Value::Bound findVarBound ( const Variable var,
const Token start,
const Token end,
const Settings settings 
)
static

◆ getAlignOf()

static size_t getAlignOf ( const ValueType vt,
const Settings settings,
int  maxRecursion = 0 
)
static

◆ getCastTypeStartToken()

static const Token* getCastTypeStartToken ( const Token parent,
const Settings settings 
)
static

◆ getConditions()

static std::vector<const Token*> getConditions ( const Token tok,
const char *  op 
)
static

Definition at line 5364 of file valueflow.cpp.

References astFlatten(), and Token::str().

Referenced by valueFlowConditionExpressions().

◆ getContainerSizeFromConstructor()

static std::vector<ValueFlow::Value> getContainerSizeFromConstructor ( const Token tok,
const ValueType valueType,
const Settings settings,
bool  known = true 
)
static

◆ getContainerSizeFromConstructorArgs()

static std::vector<ValueFlow::Value> getContainerSizeFromConstructorArgs ( const std::vector< const Token * > &  args,
const Library::Container container,
bool  known 
)
static

◆ getContainerValues()

static std::vector<ValueFlow::Value> getContainerValues ( const Token tok)
static

◆ getContainerYield()

static Library::Container::Yield getContainerYield ( Token tok,
const Settings settings,
Token **  parent = nullptr 
)
static

◆ getEndOfVarScope()

static const Token* getEndOfVarScope ( const Variable var)
static

◆ getExpressionRange()

static bool getExpressionRange ( const Token expr,
MathLib::bigint minvalue,
MathLib::bigint maxvalue 
)
static

◆ getFunctionArgumentValues()

static std::list<ValueFlow::Value> getFunctionArgumentValues ( const Token argtok)
static

◆ getFunctionScope()

static const Scope* getFunctionScope ( const Scope scope)
static

Definition at line 8843 of file valueflow.cpp.

References Scope::nestedIn, and Scope::type.

Referenced by valueFlowContainerSize().

◆ getInitListSize()

static std::vector<ValueFlow::Value> getInitListSize ( const Token tok,
const ValueType valueType,
const Settings settings,
bool  known = true 
)
static

◆ getIteratorValues()

static std::list<ValueFlow::Value> getIteratorValues ( std::list< ValueFlow::Value values,
const ValueFlow::Value::ValueKind kind = nullptr 
)
static

◆ getKnownValueFromToken()

static const ValueFlow::Value* getKnownValueFromToken ( const Token tok)
static

Definition at line 7907 of file valueflow.cpp.

References Token::values().

Referenced by getKnownValueFromTokens(), and valueFlowFunctionReturn().

◆ getKnownValueFromTokens()

static const ValueFlow::Value* getKnownValueFromTokens ( const std::vector< const Token * > &  toks)
static

Definition at line 7919 of file valueflow.cpp.

References getKnownValueFromToken().

Referenced by valueFlowFunctionReturn().

◆ getLifetimeToken()

static const Token* getLifetimeToken ( const Token tok,
ValueFlow::Value::ErrorPath errorPath,
const Settings settings,
bool *  addressOf = nullptr 
)
static

Definition at line 3752 of file valueflow.cpp.

References ValueFlow::getLifetimeTokens().

Referenced by ValueFlow::getLifetimeVariable().

◆ getLifetimeTokens()

template<class Predicate >
static std::vector<ValueFlow::LifetimeToken> getLifetimeTokens ( const Token tok,
bool  escape,
ValueFlow::Value::ErrorPath  errorPath,
Predicate  pred,
const Settings settings,
int  depth = 20 
)
static

◆ getLoopScope()

static const Scope* getLoopScope ( const Token tok)
static

◆ getMinMaxValues() [1/2]

static bool getMinMaxValues ( const std::string &  typestr,
const Settings settings,
bool  cpp,
MathLib::bigint minvalue,
MathLib::bigint maxvalue 
)
static

◆ getMinMaxValues() [2/2]

static bool getMinMaxValues ( const ValueType vt,
const Platform platform,
MathLib::bigint minValue,
MathLib::bigint maxValue 
)
static

◆ getOtherOperand()

static const Token* getOtherOperand ( const Token tok)
static

Definition at line 1569 of file valueflow.cpp.

References Token::astParent().

Referenced by valueFlowArrayBool().

◆ getSizeOfType()

static nonneg int getSizeOfType ( const Token typeTok,
const Settings settings 
)
static

Definition at line 1190 of file valueflow.cpp.

References ValueFlow::getSizeOf(), and ValueType::parseDecl().

Referenced by valueFlowSetConstantValue().

◆ getVariables()

static std::vector<const Variable*> getVariables ( const Token tok)
static

Definition at line 6209 of file valueflow.cpp.

References op1_and_op2, Token::variable(), and visitAstNodes().

Referenced by valueFlowAfterSwap(), and valueFlowSmartPointer().

◆ getVarIds()

static std::set<nonneg int> getVarIds ( const Token tok)
static

Definition at line 5530 of file valueflow.cpp.

References op1_and_op2, Token::varId(), and visitAstNodes().

Referenced by valueFlowSymbolic().

◆ hasBorrowingVariables()

static bool hasBorrowingVariables ( const std::list< Variable > &  vars,
const std::vector< const Token * > &  args,
int  depth = 10 
)
static

Definition at line 4384 of file valueflow.cpp.

Referenced by valueFlowLifetimeUserConstructor().

◆ hasUniqueOwnership()

static bool hasUniqueOwnership ( const Token tok)
static

◆ inferCondition()

static ValueFlow::Value inferCondition ( const std::string &  op,
const Token varTok,
MathLib::bigint  val 
)
static

◆ insertImpossible()

static void insertImpossible ( std::list< ValueFlow::Value > &  values,
const std::list< ValueFlow::Value > &  input 
)
static

◆ insertNegateKnown()

static void insertNegateKnown ( std::list< ValueFlow::Value > &  values,
const std::list< ValueFlow::Value > &  input 
)
static

◆ intersects()

template<class C1 , class C2 >
static bool intersects ( const C1 &  c1,
const C2 &  c2 
)
static

Definition at line 6071 of file valueflow.cpp.

Referenced by valueFlowAfterAssign().

◆ invertAssign()

static const std::string& invertAssign ( const std::string &  assign)
static

Definition at line 2267 of file valueflow.cpp.

References emptyString.

Referenced by ValueFlowAnalyzer::getAssign().

◆ isAliasOf()

template<typename V >
static bool isAliasOf ( const Variable var,
const Token tok,
nonneg int  varid,
const V &  values,
bool *  inconclusive = nullptr 
)
static

◆ isBreakOrContinueScope()

static bool isBreakOrContinueScope ( const Token endToken)
static

◆ isBreakScope()

static bool isBreakScope ( const Token *const  endToken)
static

Definition at line 6260 of file valueflow.cpp.

References Token::findmatch(), Token::link(), and Token::simpleMatch().

Referenced by ConditionHandler::afterCondition().

◆ isCompatibleValues()

static bool isCompatibleValues ( const ValueFlow::Value value1,
const ValueFlow::Value value2 
)
static

◆ isCompatibleValueTypes()

static bool isCompatibleValueTypes ( ValueFlow::Value::ValueType  x,
ValueFlow::Value::ValueType  y 
)
static

◆ isComputableValue()

static bool isComputableValue ( const Token parent,
const ValueFlow::Value value 
)
static

◆ isConditionKnown()

static bool isConditionKnown ( const Token tok,
bool  then 
)
static

◆ isContainerOfPointers()

static bool isContainerOfPointers ( const Token tok,
const Settings settings 
)
static

Definition at line 4907 of file valueflow.cpp.

References ValueType::parseDecl(), and ValueType::pointer.

Referenced by valueFlowLifetime().

◆ isContainerSizeChanged()

static bool isContainerSizeChanged ( const Token expr,
const Token start,
const Token end,
int  indirect,
const Settings settings,
int  depth = 20 
)
static

◆ isContainerSizeChangedByFunction()

static bool isContainerSizeChangedByFunction ( const Token tok,
int  indirect,
const Settings settings,
int  depth = 20 
)
static

◆ isConvertedToIntegral()

static bool isConvertedToIntegral ( const Token tok,
const Settings settings 
)
static

◆ isConvertedToView()

static bool isConvertedToView ( const Token tok,
const Settings settings 
)
static

Definition at line 4897 of file valueflow.cpp.

References getParentValueTypes().

Referenced by valueFlowLifetime().

◆ isDecayedPointer()

static bool isDecayedPointer ( const Token tok)
static

Definition at line 4882 of file valueflow.cpp.

References astIsPointer(), Token::astParent(), and Token::simpleMatch().

Referenced by valueFlowLifetime().

◆ isDifferentType()

static bool isDifferentType ( const Token src,
const Token dst 
)
static

◆ isEscapeScope()

static bool isEscapeScope ( const Token tok,
const Settings settings,
bool  unknown = false 
)
static

◆ isInitialVarAssign()

static bool isInitialVarAssign ( const Token tok)
static

Definition at line 5878 of file valueflow.cpp.

References Token::Match(), Token::tokAt(), Token::variable(), and Token::varId().

Referenced by valueFlowForwardAssign().

◆ isIntegralOnlyOperator()

static bool isIntegralOnlyOperator ( const Token tok)
static

Definition at line 7019 of file valueflow.cpp.

References Token::Match().

Referenced by isIntegralOrPointer().

◆ isIntegralOrPointer()

static bool isIntegralOrPointer ( const Token tok)
static

◆ isLifetimeBorrowed()

static bool isLifetimeBorrowed ( const ValueType vt,
const ValueType vtParent 
)
static

◆ isLifetimeOwned() [1/2]

static bool isLifetimeOwned ( const ValueType vt,
const ValueType vtParent 
)
static

◆ isLifetimeOwned() [2/2]

static bool isLifetimeOwned ( const ValueType vtParent)
static

◆ isMoveOrForward()

static ValueFlow::Value::MoveKind isMoveOrForward ( const Token tok)
static

◆ isNonConditionalPossibleIntValue()

static bool isNonConditionalPossibleIntValue ( const ValueFlow::Value v)
static

◆ isNonInvertibleOperation()

static bool isNonInvertibleOperation ( const Token tok)
static

Definition at line 495 of file valueflow.cpp.

References Token::Match().

Referenced by isComputableValue().

◆ isNonZero()

static bool isNonZero ( const Token tok)
static

Definition at line 1564 of file valueflow.cpp.

References Token::hasKnownIntValue(), and Token::values().

Referenced by valueFlowArrayBool().

◆ isNotEqual() [1/3]

static bool isNotEqual ( std::pair< const Token *, const Token * >  x,
const std::string &  y,
bool  cpp 
)
static

◆ isNotEqual() [2/3]

static bool isNotEqual ( std::pair< const Token *, const Token * >  x,
const ValueType y,
bool  cpp 
)
static

Definition at line 3878 of file valueflow.cpp.

References isNotEqual(), and ValueType::originalTypeName.

◆ isNotEqual() [3/3]

static bool isNotEqual ( std::pair< const Token *, const Token * >  x,
std::pair< const Token *, const Token * >  y 
)
static

Definition at line 3845 of file valueflow.cpp.

References Token::next(), skipCVRefs(), and Token::str().

Referenced by isDifferentType(), and isNotEqual().

◆ isNotLifetimeValue()

static bool isNotLifetimeValue ( const ValueFlow::Value val)
static

Definition at line 3779 of file valueflow.cpp.

References ValueFlow::Value::isLifetimeValue().

Referenced by valueFlowForwardLifetime().

◆ isNumeric()

static bool isNumeric ( const ValueFlow::Value value)
static

Definition at line 420 of file valueflow.cpp.

References ValueFlow::Value::isFloatValue(), and ValueFlow::Value::isIntValue().

Referenced by setTokenValueCast().

◆ isOpenParenthesisMemberFunctionCallOfVarId()

static bool isOpenParenthesisMemberFunctionCallOfVarId ( const Token openParenthesisToken,
nonneg int  varId 
)
static

Definition at line 5224 of file valueflow.cpp.

References Token::Match(), Token::next(), Token::originalName(), and Token::tokAt().

Referenced by valueFlowAfterMove().

◆ isOutOfBoundsImpl()

static std::vector<ValueFlow::Value> isOutOfBoundsImpl ( const ValueFlow::Value size,
const Token indexTok,
bool  condition 
)
static

◆ isRangeForScope()

static bool isRangeForScope ( const Scope scope)
static

◆ isSameToken()

static bool isSameToken ( const Token tok1,
const Token tok2 
)
static

Definition at line 1926 of file valueflow.cpp.

References Token::exprId(), Token::hasKnownIntValue(), and Token::values().

Referenced by valueFlowImpossibleValues().

◆ isSaturated()

static bool isSaturated ( MathLib::bigint  value)
static

Definition at line 291 of file valueflow.cpp.

Referenced by parseCompareEachInt().

◆ isScope()

static bool isScope ( const Token tok)
static

◆ isStdMoveOrStdForwarded()

static bool isStdMoveOrStdForwarded ( Token tok,
ValueFlow::Value::MoveKind moveKind,
Token **  varTok = nullptr 
)
static

◆ isStrlenOf()

static const Token* isStrlenOf ( const Token tok,
const Token expr,
int  depth = 10 
)
static

◆ isTruncated()

static bool isTruncated ( const ValueType src,
const ValueType dst,
const Settings settings 
)
static

◆ isVariableInit()

static bool isVariableInit ( const Token tok)
static

◆ lifetimeType()

static std::string lifetimeType ( const Token tok,
const ValueFlow::Value val 
)
static

◆ lowerToPossible()

static void lowerToPossible ( std::list< ValueFlow::Value > &  values,
int  indirect = -1 
)
static

Definition at line 198 of file valueflow.cpp.

References changeKnownToPossible(), and removeImpossible().

Referenced by valueFlowForwardAssign(), and valueFlowSubFunction().

◆ makeAnalyzer()

static ValuePtr< Analyzer > makeAnalyzer ( const Token exprTok,
ValueFlow::Value  value,
const TokenList tokenlist,
const Settings settings 
)
static

◆ makeConditionValue()

static ValueFlow::Value makeConditionValue ( long long  val,
const Token condTok,
bool  assume,
bool  impossible,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

◆ makeContainerSizeValue() [1/2]

static std::vector<ValueFlow::Value> makeContainerSizeValue ( const Token tok,
bool  known = true 
)
static

◆ makeContainerSizeValue() [2/2]

static ValueFlow::Value makeContainerSizeValue ( std::size_t  s,
bool  known = true 
)
static

◆ MakeIteratorRange()

template<class Iterator >
static IteratorRange<Iterator> MakeIteratorRange ( Iterator  start,
Iterator  last 
)
static

Definition at line 7792 of file valueflow.cpp.

Referenced by valueFlowSubFunction().

◆ makeReverseAnalyzer()

static ValuePtr< Analyzer > makeReverseAnalyzer ( const Token exprTok,
ValueFlow::Value  value,
const TokenList tokenlist,
const Settings settings 
)
static

Definition at line 8454 of file valueflow.cpp.

References ValueFlow::Value::isContainerSizeValue().

Referenced by valueFlowReverse().

◆ MakeSingleRange()

template<class T >
static SingleRange<T> MakeSingleRange ( T &  x)
static

Definition at line 2360 of file valueflow.cpp.

Referenced by SingleValueFlowAnalyzer::isAlias().

◆ makeSymbolic()

static ValueFlow::Value makeSymbolic ( const Token tok,
MathLib::bigint  delta = 0 
)
static

◆ makeValueFlowPassAdaptor()

template<class F >
static ValueFlowPassAdaptor<F> makeValueFlowPassAdaptor ( const char *  name,
bool  cpp,
run 
)
static

Definition at line 9580 of file valueflow.cpp.

References ValueFlowPass::cpp(), ValueFlowPass::name(), and ValueFlowPass::run().

◆ minUnsignedValue()

static std::vector<MathLib::bigint> minUnsignedValue ( const Token tok,
int  depth = 8 
)
static

◆ needsInitialization()

static bool needsInitialization ( const Variable var)
static

◆ parseBinaryIntOp()

static const Token* parseBinaryIntOp ( const Token expr,
const std::function< std::vector< MathLib::bigint >(const Token *)> &  eval,
MathLib::bigint known 
)
static

Definition at line 8365 of file valueflow.cpp.

References Token::astOperand1(), and Token::astOperand2().

Referenced by ValueFlow::solveExprValue().

◆ parseCompareEachInt() [1/2]

static void parseCompareEachInt ( const Token tok,
const std::function< void(const Token *varTok, ValueFlow::Value true_value, ValueFlow::Value false_value)> &  each 
)
static

Definition at line 331 of file valueflow.cpp.

References Token::hasKnownIntValue(), parseCompareEachInt(), and Token::values().

◆ parseCompareEachInt() [2/2]

static void parseCompareEachInt ( const Token tok,
const std::function< void(const Token *varTok, ValueFlow::Value true_value, ValueFlow::Value false_value)> &  each,
const std::function< std::vector< ValueFlow::Value >(const Token *)> &  evaluate 
)
static

◆ productParams()

template<class Key , class F >
static bool productParams ( const Settings settings,
const std::unordered_map< Key, std::list< ValueFlow::Value >> &  vars,
f 
)
static

◆ removeAssign()

static std::string removeAssign ( const std::string &  assign)
static

Definition at line 2284 of file valueflow.cpp.

Referenced by calculateAssign().

◆ removeImpossible()

static void removeImpossible ( std::list< ValueFlow::Value > &  values,
int  indirect = -1 
)
static

◆ setConditionalValue()

static void setConditionalValue ( ValueFlow::Value value,
const Token tok,
MathLib::bigint  i 
)
static

◆ setConditionalValues()

static void setConditionalValues ( const Token tok,
bool  lhs,
MathLib::bigint  value,
ValueFlow::Value true_value,
ValueFlow::Value false_value 
)
static

◆ setFunctionReturnValue()

static void setFunctionReturnValue ( const Function f,
Token tok,
ValueFlow::Value  v,
const Settings settings 
)
static

◆ setSourceLocation()

static void setSourceLocation ( ValueFlow::Value v,
SourceLocation  ctx,
const Token tok,
SourceLocation  local = SourceLocation::current() 
)
static

◆ setSymbolic()

static void setSymbolic ( ValueFlow::Value value,
const Token tok 
)
static

◆ setTokenValue()

static void setTokenValue ( Token tok,
ValueFlow::Value  value,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

set ValueFlow value and perform calculations if possible

Definition at line 619 of file valueflow.cpp.

References Token::addValue(), astIsContainer(), astIsIterator(), astIsPointer(), astIsRHS(), astIsUnsigned(), Token::astOperand1(), Token::astOperand2(), Token::astParent(), ValueFlow::Value::bound, calculate(), ValueFlow::Value::changeKnownToPossible(), ValueFlow::combineValueProperties(), ValueFlow::Value::conditional, ValueFlow::Value::CONTAINER_SIZE, contains(), Settings::debugnormal, done, Library::Container::EMPTY, Token::eString, findParent(), getCastTypeStartToken(), getContainerYield(), ValueFlow::getSizeOf(), Token::getStrLength(), ValueFlow::Value::indirect, ValueFlow::Value::INT, ValueFlow::Value::intvalue, Token::isArithmeticalOp(), Token::isCast(), ValueFlow::Value::isContainerSizeValue(), ValueFlow::Value::isImpossible(), Token::isInitComma(), ValueFlow::Value::isIntValue(), ValueFlow::isLifetimeBorrowed(), ValueFlow::Value::isLifetimeValue(), Library::isNotLibraryFunction(), ValueFlow::Value::isTokValue(), Token::isUnaryOp(), ValueFlow::Value::isUninitValue(), ValueFlow::Value::Iterator, Settings::library, ValueFlow::Value::lifetimeKind, ValueFlow::Value::Lower, Token::Match(), Token::next(), nonneg, op1_and_op2, Token::originalName(), ValueType::parseDecl(), ValueFlow::Value::path, ValueFlow::Value::Point, Token::previous(), ValueFlow::Value::setKnown(), ValueFlow::Value::setPossible(), setSourceLocation(), setTokenValueCast(), ValueType::sign, ValueType::SIGNED, Token::simpleMatch(), Library::Container::SIZE, Token::str(), ValueFlow::Value::subexpressions, ValueFlow::Value::SYMBOLIC, truncateImplicitConversion(), ValueFlow::Value::Upper, Token::values(), Token::valueType(), ValueFlow::Value::valueType, and visitAstNodes().

Referenced by LifetimeStore::byRef(), LifetimeStore::byVal(), setFunctionReturnValue(), setTokenValueCast(), ValueFlowAnalyzer::update(), valueFlowAfterMove(), valueFlowArray(), valueFlowArrayBool(), valueFlowArrayElement(), valueFlowBitAnd(), valueFlowContainerSize(), valueFlowForLoopSimplify(), valueFlowForwardConst(), valueFlowForwardLifetime(), valueFlowGlobalConstVar(), valueFlowGlobalStaticVar(), valueFlowImpossibleValues(), valueFlowInferCondition(), valueFlowIteratorInfer(), valueFlowIterators(), valueFlowLibraryFunction(), valueFlowLifetime(), valueFlowLifetimeFunction(), valueFlowNumber(), valueFlowPointerAlias(), valueFlowRightShift(), valueFlowSameExpressions(), valueFlowSetConstantValue(), valueFlowSmartPointer(), valueFlowString(), valueFlowSymbolicInfer(), valueFlowSymbolicOperators(), valueFlowUninit(), and valueFlowUnknownFunctionReturn().

◆ setTokenValueCast()

static void setTokenValueCast ( Token parent,
const ValueType valueType,
const ValueFlow::Value value,
const Settings settings 
)
static

◆ setValueBound()

static void setValueBound ( ValueFlow::Value value,
const Token tok,
bool  invert 
)
static

Definition at line 238 of file valueflow.cpp.

References Token::Match(), and setValueUpperBound().

Referenced by setConditionalValues().

◆ setValueUpperBound()

static void setValueUpperBound ( ValueFlow::Value value,
bool  upper 
)
static

Definition at line 230 of file valueflow.cpp.

References ValueFlow::Value::bound, ValueFlow::Value::Lower, and ValueFlow::Value::Upper.

Referenced by setValueBound().

◆ skipCVRefs()

static const Token* skipCVRefs ( const Token tok,
const Token endTok 
)
static

Definition at line 3838 of file valueflow.cpp.

References Token::Match(), and Token::next().

Referenced by isNotEqual().

◆ solveExprValue()

static const Token* solveExprValue ( const Token expr,
ValueFlow::Value value 
)
static

Definition at line 8434 of file valueflow.cpp.

References Token::hasKnownIntValue(), and ValueFlow::solveExprValue().

Referenced by makeAnalyzer(), and ProgramMemory::setValue().

◆ truncateImplicitConversion()

static ValueFlow::Value truncateImplicitConversion ( Token parent,
const ValueFlow::Value value,
const Settings settings 
)
static

◆ truncateIntValue()

static long long truncateIntValue ( long long  value,
size_t  value_size,
const ValueType::Sign  dst_sign 
)
static

Definition at line 607 of file valueflow.cpp.

Referenced by truncateValues(), and ValueFlowAnalyzer::writeValue().

◆ truncateValues()

static std::list<ValueFlow::Value> truncateValues ( std::list< ValueFlow::Value values,
const ValueType dst,
const ValueType src,
const Settings settings 
)
static

◆ valueFlowAfterAssign()

static void valueFlowAfterAssign ( TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings,
const std::set< const Scope * > &  skippedFunctions 
)
static

◆ valueFlowAfterMove()

static void valueFlowAfterMove ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowAfterSwap()

static void valueFlowAfterSwap ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowArray()

static void valueFlowArray ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowArrayBool()

static void valueFlowArrayBool ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowArrayElement()

static void valueFlowArrayElement ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowBitAnd()

static void valueFlowBitAnd ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowCondition()

static void valueFlowCondition ( const ValuePtr< ConditionHandler > &  handler,
TokenList tokenlist,
SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings,
const std::set< const Scope * > &  skippedFunctions 
)
static

Definition at line 6911 of file valueflow.cpp.

Referenced by ValueFlow::setValues().

◆ valueFlowConditionExpressions()

static void valueFlowConditionExpressions ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowContainerSetTokValue()

static void valueFlowContainerSetTokValue ( const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
const Token tok,
Token initList 
)
static

◆ valueFlowContainerSize()

static void valueFlowContainerSize ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings,
const std::set< const Scope * > &  skippedFunctions 
)
static

◆ valueFlowDebug()

static void valueFlowDebug ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowDynamicBufferSize()

static void valueFlowDynamicBufferSize ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowEnumValue()

static void valueFlowEnumValue ( SymbolDatabase symboldatabase,
const Settings settings 
)
static

◆ valueFlowForLoop()

static void valueFlowForLoop ( TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowForLoop2()

static bool valueFlowForLoop2 ( const Token tok,
ProgramMemory memory1,
ProgramMemory memory2,
ProgramMemory memoryAfter,
const Settings settings 
)
static

◆ valueFlowForLoopSimplify()

static void valueFlowForLoopSimplify ( Token *const  bodyStart,
const Token expr,
bool  globalvar,
const MathLib::bigint  value,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowForLoopSimplifyAfter()

static void valueFlowForLoopSimplifyAfter ( Token fortok,
nonneg int  varid,
const MathLib::bigint  num,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowForward() [1/3]

static Analyzer::Result valueFlowForward ( Token startToken,
const Token endToken,
const Token exprTok,
std::list< ValueFlow::Value values,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

Definition at line 2175 of file valueflow.cpp.

References Analyzer::Result::update(), and valueFlowForward().

◆ valueFlowForward() [2/3]

static Analyzer::Result valueFlowForward ( Token startToken,
const Token endToken,
const Token exprTok,
ValueFlow::Value  value,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

◆ valueFlowForward() [3/3]

template<class ValueOrValues >
static Analyzer::Result valueFlowForward ( Token startToken,
const Token exprTok,
ValueOrValues  v,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

◆ valueFlowForwardAssign() [1/2]

static void valueFlowForwardAssign ( Token *const  tok,
const Token expr,
std::vector< const Variable * >  vars,
std::list< ValueFlow::Value values,
const bool  init,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowForwardAssign() [2/2]

static void valueFlowForwardAssign ( Token *const  tok,
const Variable *const  var,
const std::list< ValueFlow::Value > &  values,
const bool  ,
const bool  init,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

Definition at line 6002 of file valueflow.cpp.

References Variable::nameToken(), and valueFlowForwardAssign().

◆ valueFlowForwardConst() [1/2]

template<class ContainerOfValue >
static void valueFlowForwardConst ( Token start,
const Token end,
const Variable var,
const ContainerOfValue &  values,
const Settings settings,
int  = 0 
)
static

◆ valueFlowForwardConst() [2/2]

static void valueFlowForwardConst ( Token start,
const Token end,
const Variable var,
const std::initializer_list< ValueFlow::Value > &  values,
const Settings settings 
)
static

Definition at line 5843 of file valueflow.cpp.

References valueFlowForwardConst().

◆ valueFlowForwardLifetime()

static void valueFlowForwardLifetime ( Token tok,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowForwardRecursive()

static Analyzer::Result valueFlowForwardRecursive ( Token top,
const Token exprTok,
std::list< ValueFlow::Value values,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

◆ valueFlowFunctionDefaultParameter()

static void valueFlowFunctionDefaultParameter ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowFunctionReturn()

static void valueFlowFunctionReturn ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowGetStrLength()

static MathLib::bigint valueFlowGetStrLength ( const Token tok)
static

◆ valueFlowGlobalConstVar()

static void valueFlowGlobalConstVar ( TokenList tokenList,
const Settings settings 
)
static

◆ valueFlowGlobalStaticVar()

static void valueFlowGlobalStaticVar ( TokenList tokenList,
const Settings settings 
)
static

◆ valueFlowImpossibleValues()

static void valueFlowImpossibleValues ( TokenList tokenList,
const Settings settings 
)
static

◆ valueFlowInferCondition()

static void valueFlowInferCondition ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowInjectParameter() [1/2]

static void valueFlowInjectParameter ( const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
const Variable arg,
const Scope functionScope,
const std::list< ValueFlow::Value > &  argvalues 
)
static

◆ valueFlowInjectParameter() [2/2]

static void valueFlowInjectParameter ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
const Scope functionScope,
const std::unordered_map< const Variable *, std::list< ValueFlow::Value >> &  vars 
)
static

◆ valueFlowIsSameContainerType()

static bool valueFlowIsSameContainerType ( const ValueType contType,
const Token tok,
const Settings settings 
)
static

◆ valueFlowIteratorInfer()

static void valueFlowIteratorInfer ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowIterators()

static void valueFlowIterators ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowLibraryFunction()

static void valueFlowLibraryFunction ( Token tok,
const std::string &  returnValue,
const Settings settings 
)
static

◆ valueFlowLifetime()

static void valueFlowLifetime ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

Definition at line 4918 of file valueflow.cpp.

References ValueFlow::Value::Address, astFunctionYield(), astIsContainer(), astIsContainerOwned(), astIsContainerView(), astIsIterator(), astIsLHS(), astIsPointer(), astIsUniqueSmartPointer(), Token::astOperand1(), Token::astParent(), astParentSkipParens(), Lambda::bodyTok, LifetimeStore::byRef(), ByReference, ByValue, Settings::certainty, ValueType::containerTypeToken, contains(), Variable::declarationId(), Scope::eGlobal, Library::Container::END_ITERATOR, ValueFlow::Value::errorPath, Lambda::explicitCaptures, exprDependsOnThis(), followAllReferences(), TokenList::front(), ValueFlow::getLifetimeTokens(), ValueFlow::getLifetimeVariable(), Lambda::implicitCapture, inconclusive, Variable::isArgument(), Variable::isArray(), isContainerOfPointers(), isConvertedToView(), isDecayedPointer(), SimpleEnableGroup< T >::isEnabled(), Lambda::isLambda(), ValueFlow::Value::isLifetimeValue(), Variable::isLocal(), Scope::isNestedIn(), isScope(), Variable::isStlType(), Token::isUnaryOp(), ValueFlow::Value::Iterator, ValueFlow::Value::Lambda, ValueFlow::Value::LIFETIME, ValueFlow::Value::lifetimeKind, ValueFlow::Value::lifetimeScope, Token::link(), ValueFlow::Value::Local, Token::Match(), Variable::nameToken(), Token::next(), ValueFlow::Value::Object, Token::originalName(), Token::previous(), Variable::scope(), Token::scope(), ValueFlow::Value::setInconclusive(), setTokenValue(), Token::simpleMatch(), Library::Container::START_ITERATOR, ValueFlow::Value::SubObject, ValueFlow::Value::ThisPointer, ValueFlow::Value::ThisValue, Token::tokAt(), ValueFlow::Value::tokvalue, valueFlowForwardLifetime(), valueFlowLifetimeConstructor(), valueFlowLifetimeFunction(), Token::values(), Token::valueType(), ValueFlow::Value::valueType, Token::variable(), and Token::varId().

Referenced by ValueFlow::setValues().

◆ valueFlowLifetimeClassConstructor()

static void valueFlowLifetimeClassConstructor ( Token tok,
const Type t,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowLifetimeConstructor()

static void valueFlowLifetimeConstructor ( Token tok,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowLifetimeFunction()

static void valueFlowLifetimeFunction ( Token tok,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowLifetimeUserConstructor()

static void valueFlowLifetimeUserConstructor ( Token tok,
const Function constructor,
const std::string &  name,
const std::vector< const Token * > &  args,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowNumber()

static void valueFlowNumber ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowPointerAlias()

static void valueFlowPointerAlias ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowReverse() [1/2]

static void valueFlowReverse ( const TokenList tokenlist,
Token tok,
const Token *const  varToken,
ValueFlow::Value  val,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

Definition at line 2242 of file valueflow.cpp.

References valueFlowReverse().

◆ valueFlowReverse() [2/2]

static void valueFlowReverse ( Token tok,
const Token *const  endToken,
const Token *const  varToken,
std::list< ValueFlow::Value values,
const TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings,
SourceLocation  loc = SourceLocation::current() 
)
static

◆ valueFlowRightShift()

static void valueFlowRightShift ( TokenList tokenList,
const Settings settings 
)
static

◆ valueFlowSafeFunctions()

static void valueFlowSafeFunctions ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowSameExpressions()

static void valueFlowSameExpressions ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowSetConditionToKnown()

static void valueFlowSetConditionToKnown ( const Token tok,
std::list< ValueFlow::Value > &  values,
bool  then 
)
static

◆ valueFlowSetConstantValue()

static Token* valueFlowSetConstantValue ( Token tok,
const Settings settings 
)
static

Definition at line 1256 of file valueflow.cpp.

References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Type::classScope, Standards::cpp, Standards::CPP20, Variable::dimension(), Variable::dimensionKnown(), Variable::dimensions(), Token::eChar, Token::enumerator(), Scope::enumType, Token::eString, ValueFlow::Value::FLOAT, ValueFlow::Value::floatValue, getMinMaxValues(), ValueFlow::getSizeOf(), getSizeOfType(), Token::getStrSize(), Token::isCChar(), Token::isCMultiChar(), Token::isCpp(), Variable::isEnumType(), MathLib::isFloat(), MathLib::isInt(), ValueType::isIntegral(), Token::isLong(), Token::isNumber(), Token::isStandardType(), Token::isTemplateArg(), Token::isUtf16(), Token::isUtf32(), Token::isUtf8(), Token::linkAt(), Token::Match(), Token::next(), nonneg, ValueType::parseDecl(), Settings::platform, ValueType::pointer, Enumerator::scope, ValueFlow::Value::setKnown(), setTokenValue(), ValueType::sign, Token::simpleMatch(), Platform::sizeof_int, Platform::sizeof_wchar_t, Settings::standards, Token::str(), MathLib::toBigNumber(), MathLib::toBigUNumber(), MathLib::toDoubleNumber(), Token::tokAt(), Token::tokType(), Platform::type, Variable::type(), Token::type(), Variable::typeEndToken(), Variable::typeStartToken(), ValueType::UNSIGNED, Enumerator::value, Enumerator::value_known, Variable::valueType(), Token::valueType(), ValueFlow::Value::valueType, Token::variable(), and Token::varId().

Referenced by ValueFlow::valueFlowConstantFoldAST(), and valueFlowNumber().

◆ valueFlowSmartPointer()

static void valueFlowSmartPointer ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowString()

static void valueFlowString ( TokenList tokenlist,
const Settings settings 
)
static

◆ valueFlowSubFunction()

static void valueFlowSubFunction ( TokenList tokenlist,
SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowSwitchVariable()

static void valueFlowSwitchVariable ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowSymbolic()

static void valueFlowSymbolic ( const TokenList tokenlist,
const SymbolDatabase symboldatabase,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowSymbolicInfer()

static void valueFlowSymbolicInfer ( const SymbolDatabase symboldatabase,
const Settings settings 
)
static

◆ valueFlowSymbolicOperators()

static void valueFlowSymbolicOperators ( const SymbolDatabase symboldatabase,
const Settings settings 
)
static

◆ valueFlowUninit()

static void valueFlowUninit ( TokenList tokenlist,
ErrorLogger errorLogger,
const Settings settings 
)
static

◆ valueFlowUnknownFunctionReturn()

static void valueFlowUnknownFunctionReturn ( TokenList tokenlist,
const Settings settings 
)
static