From a80e1181b78183dc36ec6568559d38faa86981f0 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 28 Apr 2007 13:45:00 +0000 Subject: Implement review feedback. Aliasees can be either GlobalValue's or bitcasts of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36537 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/Reader.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'lib/Bytecode/Reader/Reader.cpp') diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index f7606c6e5a..99aac056ff 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -1923,12 +1923,10 @@ void BytecodeReader::ParseModuleGlobalInfo() { // Read aliases... unsigned VarType = read_vbr_uint(); while (VarType != Type::VoidTyID) { // List is terminated by Void - unsigned TypeSlotNo = VarType >> 2; + unsigned TypeSlotNo = VarType >> 3; unsigned EncodedLinkage = VarType & 3; - unsigned AliaseeTypeSlotNo, AliaseeSlotNo; - - AliaseeTypeSlotNo = read_vbr_uint(); - AliaseeSlotNo = read_vbr_uint(); + bool isConstantAliasee = (VarType >> 2) & 1; + unsigned AliaseeSlotNo = read_vbr_uint(); const Type *Ty = getType(TypeSlotNo); if (!Ty) @@ -1937,11 +1935,11 @@ void BytecodeReader::ParseModuleGlobalInfo() { if (!isa(Ty)) error("Alias not a pointer type! Ty= " + Ty->getDescription()); - Value* V = getValue(AliaseeTypeSlotNo, AliaseeSlotNo, false); - if (!V) - error("Invalid aliasee! TypeSlotNo=" + utostr(AliaseeTypeSlotNo) + + Value* V = getValue(TypeSlotNo, AliaseeSlotNo, false); + if (!V && !isConstantAliasee) + error("Invalid aliasee! TypeSlotNo=" + utostr(TypeSlotNo) + " SlotNo=" + utostr(AliaseeSlotNo)); - if (!isa(V)) + if (!isConstantAliasee && !isa(V)) error("Aliasee is not global value! SlotNo=" + utostr(AliaseeSlotNo)); GlobalValue::LinkageTypes Linkage; @@ -1960,8 +1958,14 @@ void BytecodeReader::ParseModuleGlobalInfo() { } GlobalAlias *GA = new GlobalAlias(Ty, Linkage, "", - dyn_cast(V), TheModule); + dyn_cast_or_null(V), + TheModule); insertValue(GA, TypeSlotNo, ModuleValues); + if (!V && isConstantAliasee) + Aliasees.push_back(std::make_pair(GA, AliaseeSlotNo)); + + if (Handler) Handler->handleGlobalAlias(Ty, Linkage, + TypeSlotNo, AliaseeSlotNo); VarType = read_vbr_uint(); } } @@ -2068,6 +2072,23 @@ void BytecodeReader::ParseModule() { error("Cannot find initializer value."); } + // And aliasees + while (!Aliasees.empty()) { + GlobalAlias *GA = Aliasees.back().first; + unsigned Slot = Aliasees.back().second; + Aliasees.pop_back(); + + // Look up the aliasee value... + const llvm::PointerType* GAType = GA->getType(); + unsigned TypeSlot = getTypeSlot(GAType); + if (Constant *CV = getConstantValue(TypeSlot, Slot)) { + if (GA->getAliasee()) + error("Aliasee was *already* set?!"); + GA->setAliasee(CV); + } else + error("Cannot find aliasee value."); + } + if (!ConstantFwdRefs.empty()) error("Use of undefined constants in a module"); -- cgit v1.2.3-18-g5258