aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
authorStephen Tozer <Stephen.Tozer@Sony.com>2021-04-21 16:56:38 +0100
committerStephen Tozer <Stephen.Tozer@Sony.com>2021-04-22 12:03:33 +0100
commite5d844b5874488599dc79e788a2dd6efa02940fb (patch)
treec41cfeeb57a1064fd660a6b83cf77870b3b025d0 /llvm/lib/Bitcode/Reader/MetadataLoader.cpp
parentbe2277fbf233cca8e1bd698fa9ab6de404001c3a (diff)
downloadllvm-e5d844b5874488599dc79e788a2dd6efa02940fb.zip
llvm-e5d844b5874488599dc79e788a2dd6efa02940fb.tar.gz
llvm-e5d844b5874488599dc79e788a2dd6efa02940fb.tar.bz2
[Bitcode] Ensure DIArgList in bitcode has no null or forward metadata refs
This patch fixes an issue in which ConstantAsMetadata arguments to a DIArglist, as well as the Constant values referenced by that metadata, would not be always be emitted correctly into bitcode. This patch fixes this issue firstly by searching for ConstantAsMetadata in DIArgLists (previously we would only search for them when directly wrapped in MetadataAsValue), and secondly by enumerating all of a DIArgList's arguments directly prior to enumerating the DIArgList itself. This patch also adds a number of asserts, and no longer treats the arguments to a DIArgList as optional fields when reading/writing to bitcode. Differential Revision: https://reviews.llvm.org/D100572
Diffstat (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 0cf547c..8493eb7 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -2078,8 +2078,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
case bitc::METADATA_ARG_LIST: {
SmallVector<ValueAsMetadata *, 4> Elts;
Elts.reserve(Record.size());
- for (uint64_t Elt : Record)
- Elts.push_back(dyn_cast_or_null<ValueAsMetadata>(getMDOrNull(Elt)));
+ for (uint64_t Elt : Record) {
+ Metadata *MD = getMD(Elt);
+ if (isa<MDNode>(MD) && cast<MDNode>(MD)->isTemporary())
+ return error(
+ "Invalid record: DIArgList should not contain forward refs");
+ if (!isa<ValueAsMetadata>(MD))
+ return error("Invalid record");
+ Elts.push_back(cast<ValueAsMetadata>(MD));
+ }
MetadataList.assignValue(DIArgList::get(Context, Elts), NextMetadataNo);
NextMetadataNo++;