+/// Support for lazy parsing of function bodies. This is required if we
+/// either have an old bitcode file without a VST forward declaration record,
+/// or if we have an anonymous function being materialized, since anonymous
+/// functions do not have a name and are therefore not in the VST.
+std::error_code BitcodeReader::rememberAndSkipFunctionBodies() {
+ Stream.JumpToBit(NextUnreadBit);
+
+ if (Stream.AtEndOfStream()) return error("Could not find function in stream");
+
+ assert(SeenFirstFunctionBody);
+ // An old bitcode file with the symbol table at the end would have
+ // finished the parse greedily.
+ assert(SeenValueSymbolTable);
+
+ SmallVector<uint64_t, 64> Record;
+
+ while (1) {
+ BitstreamEntry Entry = Stream.advance();
+ switch (Entry.Kind) {
+ default:
+ return error("Expect SubBlock");
+ case BitstreamEntry::SubBlock:
+ switch (Entry.ID) {
+ default:
+ return error("Expect function block");
+ case bitc::FUNCTION_BLOCK_ID:
+ if (std::error_code EC = rememberAndSkipFunctionBody()) return EC;
+ NextUnreadBit = Stream.GetCurrentBitNo();
+ return std::error_code();
+ }
+ }
+ }
+}
+
+std::error_code BitcodeReader::parseModule(uint64_t ResumeBit,