diff --git a/clang/include/clang/Analysis/FlowSensitive/Value.h b/clang/include/clang/Analysis/FlowSensitive/Value.h --- a/clang/include/clang/Analysis/FlowSensitive/Value.h +++ b/clang/include/clang/Analysis/FlowSensitive/Value.h @@ -26,6 +26,8 @@ namespace dataflow { /// Base class for all values computed by abstract interpretation. +/// All Value instances should be separately allocated and stored by pointer +/// for pointer stability. class Value { public: enum class Kind { @@ -48,8 +50,22 @@ Kind getKind() const { return ValKind; } + /// Returns the value of the synthetic property with the given `Name` or null + /// if the property isn't assigned a value. + Value *getProperty(llvm::StringRef Name) const { + auto It = Properties.find(Name); + return It == Properties.end() ? nullptr : It->second; + } + + /// Assigns `Val` as the value of the synthetic property with the given + /// `Name`. + void setProperty(llvm::StringRef Name, Value &Val) { + Properties.insert_or_assign(Name, &Val); + } + private: Kind ValKind; + llvm::StringMap Properties; }; /// Models a boolean. @@ -215,22 +231,8 @@ /// Assigns `Val` as the child value for `D`. void setChild(const ValueDecl &D, Value &Val) { Children[&D] = &Val; } - /// Returns the value of the synthetic property with the given `Name` or null - /// if the property isn't assigned a value. - Value *getProperty(llvm::StringRef Name) const { - auto It = Properties.find(Name); - return It == Properties.end() ? nullptr : It->second; - } - - /// Assigns `Val` as the value of the synthetic property with the given - /// `Name`. - void setProperty(llvm::StringRef Name, Value &Val) { - Properties.insert_or_assign(Name, &Val); - } - private: llvm::DenseMap Children; - llvm::StringMap Properties; }; } // namespace dataflow