Implemented deserialization of references. References are handled
just like pointers, except that they cannot be backpatched. This
means that references are essentially non-owning pointers where the
referred object must be deserialized prior to the reference being
deserialized. Because of the nature of references, this ordering of
objects is always possible.
Fixed a bug in backpatching code (returning the backpatched pointer
would accidentally include a bit flag).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43570 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp
index ff0dd44..4b58cf4 100644
--- a/lib/Bitcode/Reader/Deserialize.cpp
+++ b/lib/Bitcode/Reader/Deserialize.cpp
@@ -115,7 +115,7 @@
BPatchEntry& E = BPatchMap[PtrId];
if (E.hasFinalPtr())
- PtrRef = E.getRawPtr();
+ PtrRef = E.getFinalPtr();
else {
// Register backpatch. Check the freelist for a BPNode.
BPNode* N;
@@ -132,6 +132,18 @@
}
}
+uintptr_t Deserializer::ReadInternalRefPtr() {
+ unsigned PtrId = ReadInt();
+
+ assert (PtrId != 0 && "References cannot refer the NULL address.");
+
+ BPatchEntry& E = BPatchMap[PtrId];
+
+ assert (E.hasFinalPtr() &&
+ "Cannot backpatch references. Object must be already deserialized.");
+
+ return E.getFinalPtr();
+}
void Deserializer::BPatchEntry::setFinalPtr(BPNode*& FreeList, void* P) {
assert (!hasFinalPtr());