From 6290dbc0f7f71dbf9e5408a1b4222cbbfba43bdb Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Sat, 21 Nov 2015 21:55:48 +0000 Subject: [ThinLTO] Handle bitcode without function summary sections gracefully Summary: Several fixes to the handling of bitcode files without function summary sections so that they are skipped during ThinLTO processing in llvm-lto and the gold plugin when appropriate instead of aborting. 1 Don't assert when trying to add a FunctionInfo that doesn't have a summary attached. 2 Skip FunctionInfo structures that don't have attached function summary sections when trying to create the combined function summary. 3 In both llvm-lto and gold-plugin, check whether a bitcode file has a function summary section before trying to parse the index, and skip the bitcode file if it does not. 4 Fix hasFunctionSummaryInMemBuffer in BitcodeReader, which had a bug where we returned to early while looking for the summary section. Also added llvm-lto and gold-plugin based tests for cases where we don't have function summaries in the bitcode file. I verified that either the first couple fixes described above are enough to avoid the crashes, or fixes 1,3,4. But have combined them all here for added robustness. Reviewers: joker.eph Subscribers: llvm-commits, joker.eph Differential Revision: http://reviews.llvm.org/D14903 llvm-svn: 253796 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Bitcode') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 9d907773cb3..11c9b131da7 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5566,12 +5566,14 @@ std::error_code FunctionIndexBitcodeReader::parseModule() { case BitstreamEntry::SubBlock: if (CheckFuncSummaryPresenceOnly) { - if (Entry.ID == bitc::FUNCTION_SUMMARY_BLOCK_ID) + if (Entry.ID == bitc::FUNCTION_SUMMARY_BLOCK_ID) { SeenFuncSummary = true; + // No need to parse the rest since we found the summary. + return std::error_code(); + } if (Stream.SkipBlock()) return error("Invalid record"); - // No need to parse the rest since we found the summary. - return std::error_code(); + continue; } switch (Entry.ID) { default: // Skip unknown content. -- cgit v1.2.3