Skip to content

Commit

Permalink
reduced size of ValueFlow::Value (#6784)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Dec 16, 2024
1 parent d030f66 commit 6209da5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 45 deletions.
9 changes: 9 additions & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,29 @@ static const std::string emptyString;
#define SUPPRESS_WARNING_GCC_POP
#define SUPPRESS_WARNING_CLANG_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
#define SUPPRESS_WARNING_CLANG_POP SUPPRESS_WARNING_POP
#define FORCE_WARNING_PUSH(warn) _Pragma("clang diagnostic push") _Pragma(STRINGISIZE(clang diagnostic warning warn))
#define FORCE_WARNING_CLANG_PUSH(warning) FORCE_WARNING_PUSH(warning)
#define FORCE_WARNING_CLANG_POP SUPPRESS_WARNING_POP
#elif defined(__GNUC__)
#define SUPPRESS_WARNING_PUSH(warning) _Pragma("GCC diagnostic push") _Pragma(STRINGISIZE(GCC diagnostic ignored warning))
#define SUPPRESS_WARNING_POP _Pragma("GCC diagnostic pop")
#define SUPPRESS_WARNING_GCC_PUSH(warning) SUPPRESS_WARNING_PUSH(warning)
#define SUPPRESS_WARNING_GCC_POP SUPPRESS_WARNING_POP
#define SUPPRESS_WARNING_CLANG_PUSH(warning)
#define SUPPRESS_WARNING_CLANG_POP
#define FORCE_WARNING_PUSH(warning)
#define FORCE_WARNING_CLANG_PUSH(warning)
#define FORCE_WARNING_CLANG_POP
#else
#define SUPPRESS_WARNING_PUSH(warning)
#define SUPPRESS_WARNING_POP
#define SUPPRESS_WARNING_GCC_PUSH(warning)
#define SUPPRESS_WARNING_GCC_POP
#define SUPPRESS_WARNING_CLANG_PUSH(warning)
#define SUPPRESS_WARNING_CLANG_POP
#define FORCE_WARNING_PUSH(warning)
#define FORCE_WARNING_CLANG_PUSH(warning)
#define FORCE_WARNING_CLANG_POP
#endif

#if !defined(NO_WINDOWS_SEH) && defined(_WIN32) && defined(_MSC_VER)
Expand Down
4 changes: 4 additions & 0 deletions lib/vfvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
namespace ValueFlow {
Value::Value(const Token *c, long long val, Bound b)
: bound(b),
safe(false),
conditional(false),
macro(false),
defaultArg(false),
intvalue(val),
varvalue(val),
condition(c) {
Expand Down
103 changes: 58 additions & 45 deletions lib/vfvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <type_traits>
#include <vector>

FORCE_WARNING_CLANG_PUSH("-Wpadded")

class Token;

namespace ValueFlow
Expand All @@ -43,6 +45,10 @@ namespace ValueFlow

explicit Value(long long val = 0, Bound b = Bound::Point) :
bound(b),
safe(false),
conditional(false),
macro(false),
defaultArg(false),
intvalue(val),
varvalue(val),
wideintvalue(val)
Expand Down Expand Up @@ -262,6 +268,53 @@ namespace ValueFlow
/** The value bound */
Bound bound = Bound::Point;

/** value relies on safe checking */
// cppcheck-suppress premium-misra-cpp-2023-12.2.1
bool safe : 1;

/** Conditional value */
bool conditional : 1;

/** Value is is from an expanded macro */
bool macro : 1;

/** Is this value passed as default parameter to the function? */
bool defaultArg : 1;

long long : 4; // padding

/** kind of moved */
enum class MoveKind : std::uint8_t { NonMovedVariable, MovedVariable, ForwardedVariable } moveKind = MoveKind::NonMovedVariable;

enum class LifetimeScope : std::uint8_t { Local, Argument, SubFunction, ThisPointer, ThisValue } lifetimeScope = LifetimeScope::Local;

enum class LifetimeKind : std::uint8_t {
// Pointer points to a member of lifetime
Object,
// A member of object points to the lifetime
SubObject,
// Lambda has captured lifetime(similar to SubObject)
Lambda,
// Iterator points to the lifetime of a container(similar to Object)
Iterator,
// A pointer that holds the address of the lifetime
Address
} lifetimeKind = LifetimeKind::Object;

/** How known is this value */
enum class ValueKind : std::uint8_t {
/** This value is possible, other unlisted values may also be possible */
Possible,
/** Only listed values are possible */
Known,
/** Inconclusive */
Inconclusive,
/** Listed values are impossible */
Impossible
} valueKind = ValueKind::Possible;

std::int8_t indirect{}; // TODO: can we reduce the size?

/** int value (or sometimes bool value?) */
long long intvalue{};

Expand All @@ -279,35 +332,20 @@ namespace ValueFlow

ErrorPath errorPath;

ErrorPath debugPath;
ErrorPath debugPath; // TODO: make lighter by default

/** For calculated values - varId that calculated value depends on */
nonneg int varId{};

enum class UnknownFunctionReturn : uint8_t {
enum class UnknownFunctionReturn : std::uint8_t {
no, // not unknown function return
outOfMemory, // out of memory
outOfResources, // out of resource
other // other
};
UnknownFunctionReturn unknownFunctionReturn{UnknownFunctionReturn::no};

/** value relies on safe checking */
bool safe{};

/** Conditional value */
bool conditional{};

/** Value is is from an expanded macro */
bool macro{};

/** Is this value passed as default parameter to the function? */
bool defaultArg{};

int8_t indirect{};

/** kind of moved */
enum class MoveKind : std::uint8_t { NonMovedVariable, MovedVariable, ForwardedVariable } moveKind = MoveKind::NonMovedVariable;
long long : 24; // padding

/** Path id */
MathLib::bigint path{};
Expand All @@ -320,38 +358,11 @@ namespace ValueFlow
// Set to where a lifetime is captured by value
const Token* capturetok{};

enum class LifetimeKind : std::uint8_t {
// Pointer points to a member of lifetime
Object,
// A member of object points to the lifetime
SubObject,
// Lambda has captured lifetime(similar to SubObject)
Lambda,
// Iterator points to the lifetime of a container(similar to Object)
Iterator,
// A pointer that holds the address of the lifetime
Address
} lifetimeKind = LifetimeKind::Object;

enum class LifetimeScope : std::uint8_t { Local, Argument, SubFunction, ThisPointer, ThisValue } lifetimeScope = LifetimeScope::Local;

RET_NONNULL static const char* toString(MoveKind moveKind);
RET_NONNULL static const char* toString(LifetimeKind lifetimeKind);
RET_NONNULL static const char* toString(LifetimeScope lifetimeScope);
RET_NONNULL static const char* toString(Bound bound);

/** How known is this value */
enum class ValueKind : std::uint8_t {
/** This value is possible, other unlisted values may also be possible */
Possible,
/** Only listed values are possible */
Known,
/** Inconclusive */
Inconclusive,
/** Listed values are impossible */
Impossible
} valueKind = ValueKind::Possible;

void setKnown() {
valueKind = ValueKind::Known;
}
Expand Down Expand Up @@ -419,4 +430,6 @@ namespace ValueFlow
};
}

FORCE_WARNING_CLANG_POP

#endif // vfvalueH

0 comments on commit 6209da5

Please sign in to comment.