summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2018-10-23 22:57:21 +0000
committerTeresa Johnson <tejohnson@google.com>2018-10-23 22:57:21 +0000
commit3513dc245ec6666d20faf3a05a0f8b5e051fba0b (patch)
tree20f028358d11e00a973913c88d0d2571bdfe9484 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent02c7fae348405c49d5c9e024cdf11400b054ea3e (diff)
downloadbcm5719-llvm-3513dc245ec6666d20faf3a05a0f8b5e051fba0b.tar.gz
bcm5719-llvm-3513dc245ec6666d20faf3a05a0f8b5e051fba0b.zip
[ThinLTO] Fix a crash in lazy loading of Metadata
Summary: This is a revised version of D41474. When the debug location is parsed in BitcodeReader::parseFunction, the scope and inlinedAt MDNodes are obtained via MDLoader->getMDNodeFwdRefOrNull(), which will create a forward ref if they were not yet loaded. Specifically, if one of these MDNodes is in the module level metadata block, and this is during ThinLTO importing, that metadata block is lazily loaded. Most places in that invoke getMDNodeFwdRefOrNull have a corresponding call to resolveForwardRefsAndPlaceholders which will take care of resolving them. E.g. places that call getMetadataFwdRefOrLoad, or at the end of parsing a function-level metadata block, or at the end of the initial lazy load of module level metadata in order to handle invocations of getMDNodeFwdRefOrNull for named metadata and global object attachments. However, the calls for the scope/inlinedAt of debug locations are not backed by any such call to resolveForwardRefsAndPlaceholders. To fix this, change the scope and inlinedAt parsing to instead use getMetadataFwdRefOrLoad, which will ensure the forward refs to lazily loaded metadata are resolved. Fixes PR35472. Reviewers: dexonsmith, Sunil_Srivastava, vsk Subscribers: inglorion, eraman, steven_wu, sebpop, mehdi_amini, dmikulin, vsk, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D53596 llvm-svn: 345095
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index aa83955e646..1c4772968e7 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3520,12 +3520,14 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
MDNode *Scope = nullptr, *IA = nullptr;
if (ScopeID) {
- Scope = MDLoader->getMDNodeFwdRefOrNull(ScopeID - 1);
+ Scope = dyn_cast_or_null<MDNode>(
+ MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1));
if (!Scope)
return error("Invalid record");
}
if (IAID) {
- IA = MDLoader->getMDNodeFwdRefOrNull(IAID - 1);
+ IA = dyn_cast_or_null<MDNode>(
+ MDLoader->getMetadataFwdRefOrLoad(IAID - 1));
if (!IA)
return error("Invalid record");
}
OpenPOWER on IntegriCloud