[llvm] 159feac - [Bitcode] Report metadata decoding error more gracefully
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 14 07:50:41 PDT 2022
Author: Nikita Popov
Date: 2022-07-14T16:50:33+02:00
New Revision: 159feac1c0a26dccc6dd8726bd71d073cda5faea
URL: https://github.com/llvm/llvm-project/commit/159feac1c0a26dccc6dd8726bd71d073cda5faea
DIFF: https://github.com/llvm/llvm-project/commit/159feac1c0a26dccc6dd8726bd71d073cda5faea.diff
LOG: [Bitcode] Report metadata decoding error more gracefully
Added:
Modified:
llvm/lib/Bitcode/Reader/MetadataLoader.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 0d57ae4ef9df9..13d53a35084da 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1226,10 +1226,12 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
- MetadataList.assignValue(
- LocalAsMetadata::get(ValueList.getValueFwdRef(
- Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)),
- NextMetadataNo);
+ Value *V = ValueList.getValueFwdRef(Record[1], Ty, TyID,
+ /*ConstExprInsertBB*/ nullptr);
+ if (!V)
+ return error("Invalid value reference from old fn metadata");
+
+ MetadataList.assignValue(LocalAsMetadata::get(V), NextMetadataNo);
NextMetadataNo++;
break;
}
@@ -1248,8 +1250,11 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Ty->isMetadataTy())
Elts.push_back(getMD(Record[i + 1]));
else if (!Ty->isVoidTy()) {
- auto *MD = ValueAsMetadata::get(ValueList.getValueFwdRef(
- Record[i + 1], Ty, TyID, /*ConstExprInsertBB*/ nullptr));
+ Value *V = ValueList.getValueFwdRef(Record[i + 1], Ty, TyID,
+ /*ConstExprInsertBB*/ nullptr);
+ if (!V)
+ return error("Invalid value reference from old metadata");
+ auto *MD = ValueAsMetadata::get(V);
assert(isa<ConstantAsMetadata>(MD) &&
"Expected non-function-local metadata");
Elts.push_back(MD);
@@ -1269,10 +1274,12 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Ty->isMetadataTy() || Ty->isVoidTy())
return error("Invalid record");
- MetadataList.assignValue(
- ValueAsMetadata::get(ValueList.getValueFwdRef(
- Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)),
- NextMetadataNo);
+ Value *V = ValueList.getValueFwdRef(Record[1], Ty, TyID,
+ /*ConstExprInsertBB*/ nullptr);
+ if (!V)
+ return error("Invalid value reference from metadata");
+
+ MetadataList.assignValue(ValueAsMetadata::get(V), NextMetadataNo);
NextMetadataNo++;
break;
}
More information about the llvm-commits
mailing list