Add a TrackingVH value handle.
This is designed for tracking a value even when it might move (like WeakVH), but it is an error to delete the referenced value (unlike WeakVH0. TrackingVH is templated like AssertingVH on the tracked Value subclass, it is an error to RAUW a tracked value to an incompatible type.
For implementation reasons the latter error is only diagnosed on accesses to a mis-RAUWed TrackingVH, because we don't want a virtual interface in a templated class.
The former error is also only diagnosed on access, so that clients are allowed to delete a tracked value, as long as they don't use it. This makes it easier for the client to reason about destruction.
llvm-svn: 82506
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index 773623b..6d9256f 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -503,6 +503,11 @@
#endif
llvm_unreachable("An asserting value handle still pointed to this"
" value!");
+ case Tracking:
+ // Mark that this value has been deleted by setting it to an invalid Value
+ // pointer.
+ ThisNode->operator=(DenseMapInfo<Value *>::getTombstoneKey());
+ break;
case Weak:
// Weak just goes to null, which will unlink it from the list.
ThisNode->operator=(0);
@@ -539,6 +544,14 @@
case Assert:
// Asserting handle does not follow RAUW implicitly.
break;
+ case Tracking:
+ // Tracking goes to new value like a WeakVH. Note that this may make it
+ // something incompatible with its templated type. We don't want to have a
+ // virtual (or inline) interface to handle this though, so instead we make
+ // the TrackingVH accessors guarantee that a client never seesl this
+ // value.
+
+ // FALLTHROUGH
case Weak:
// Weak goes to the new value, which will unlink it from Old's list.
ThisNode->operator=(New);