+/// Associate a value with its name from the given index in the provided record.
+ErrorOr<Value *> BitcodeReader::recordValue(SmallVectorImpl<uint64_t> &Record,
+ unsigned NameIndex, Triple &TT) {
+ SmallString<128> ValueName;
+ if (convertToString(Record, NameIndex, ValueName))
+ return error("Invalid record");
+ unsigned ValueID = Record[0];
+ if (ValueID >= ValueList.size() || !ValueList[ValueID])
+ return error("Invalid record");
+ Value *V = ValueList[ValueID];
+
+ V->setName(StringRef(ValueName.data(), ValueName.size()));
+ auto *GO = dyn_cast<GlobalObject>(V);
+ if (GO) {
+ if (GO->getComdat() == reinterpret_cast<Comdat *>(1)) {
+ if (TT.isOSBinFormatMachO())
+ GO->setComdat(nullptr);
+ else
+ GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
+ }
+ }
+ return V;
+}
+
+/// Parse the value symbol table at either the current parsing location or
+/// at the given bit offset if provided.
+std::error_code BitcodeReader::parseValueSymbolTable(unsigned Offset) {
+ uint64_t CurrentBit;
+ // Pass in the Offset to distinguish between calling for the module-level
+ // VST (where we want to jump to the VST offset) and the function-level
+ // VST (where we don't).
+ if (Offset > 0) {
+ // Save the current parsing location so we can jump back at the end
+ // of the VST read.
+ CurrentBit = Stream.GetCurrentBitNo();
+ Stream.JumpToBit(Offset * 32);
+#ifndef NDEBUG
+ // Do some checking if we are in debug mode.
+ BitstreamEntry Entry = Stream.advance();
+ assert(Entry.Kind == BitstreamEntry::SubBlock);
+ assert(Entry.ID == bitc::VALUE_SYMTAB_BLOCK_ID);
+#else
+ // In NDEBUG mode ignore the output so we don't get an unused variable
+ // warning.
+ Stream.advance();
+#endif
+ }
+
+ // Compute the delta between the bitcode indices in the VST (the word offset
+ // to the word-aligned ENTER_SUBBLOCK for the function block, and that
+ // expected by the lazy reader. The reader's EnterSubBlock expects to have
+ // already read the ENTER_SUBBLOCK code (size getAbbrevIDWidth) and BlockID
+ // (size BlockIDWidth). Note that we access the stream's AbbrevID width here
+ // just before entering the VST subblock because: 1) the EnterSubBlock
+ // changes the AbbrevID width; 2) the VST block is nested within the same
+ // outer MODULE_BLOCK as the FUNCTION_BLOCKs and therefore have the same
+ // AbbrevID width before calling EnterSubBlock; and 3) when we want to
+ // jump to the FUNCTION_BLOCK using this offset later, we don't want
+ // to rely on the stream's AbbrevID width being that of the MODULE_BLOCK.
+ unsigned FuncBitcodeOffsetDelta =
+ Stream.getAbbrevIDWidth() + bitc::BlockIDWidth;
+