[PATCH] D127196: [clang][dataflow] Enable use of synthetic properties on all Value instances.
weiyi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 7 03:30:55 PDT 2022
wyt created this revision.
Herald added subscribers: tschuett, steakhal, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch moves the implementation of synthetic properties from the
StructValue class into the Value base class so that it can be used
across all Value instances.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127196
Files:
clang/include/clang/Analysis/FlowSensitive/Value.h
Index: clang/include/clang/Analysis/FlowSensitive/Value.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/Value.h
+++ 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<Value *> 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<const ValueDecl *, Value *> Children;
- llvm::StringMap<Value *> Properties;
};
} // namespace dataflow
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127196.434760.patch
Type: text/x-patch
Size: 1909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220607/90dd3de6/attachment.bin>
More information about the cfe-commits
mailing list