From cb33799b9f4e152e3460faa83e59b53ff604c87d Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 10 May 2009 20:57:05 +0000 Subject: Make MDNode use CallbackVH. Also change MDNode to store Value* instead of Constant* in preperation of a future change to support holding non-Constants in an MDNode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71407 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index fe20f72587..d2b4544cb0 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -17,6 +17,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/InlineAsm.h" #include "llvm/Instructions.h" +#include "llvm/MDNode.h" #include "llvm/Module.h" #include "llvm/AutoUpgrade.h" #include "llvm/ADT/SmallString.h" @@ -287,12 +288,10 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() { UserCS->getType()->isPacked()); } else if (isa(UserC)) { NewC = ConstantVector::get(&NewOps[0], NewOps.size()); - } else if (isa(UserC)) { + } else { + assert(isa(UserC) && "Must be a ConstantExpr."); NewC = cast(UserC)->getWithOperands(&NewOps[0], NewOps.size()); - } else { - assert(isa(UserC) && "Must be a metadata node."); - NewC = MDNode::get(&NewOps[0], NewOps.size()); } UserC->replaceAllUsesWith(NewC); @@ -300,6 +299,8 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() { NewOps.clear(); } + // Update all ValueHandles, they should be the only users at this point. + Placeholder->replaceAllUsesWith(RealVal); delete Placeholder; } } @@ -1017,10 +1018,13 @@ bool BitcodeReader::ParseConstants() { return Error("Invalid CST_MDNODE record"); unsigned Size = Record.size(); - SmallVector Elts; + SmallVector Elts; for (unsigned i = 0; i != Size; i += 2) { const Type *Ty = getTypeByID(Record[i], false); - Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty)); + if (Ty != Type::VoidTy) + Elts.push_back(ValueList.getConstantFwdRef(Record[i+1], Ty)); + else + Elts.push_back(NULL); } V = MDNode::get(&Elts[0], Elts.size()); break; -- cgit v1.2.3-18-g5258