aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp46
1 files changed, 32 insertions, 14 deletions
diff --git a/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 0a9a80688a41..910e97489dbb 100644
--- a/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -22,7 +22,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/ilist_iterator.h"
-#include "llvm/ADT/iterator_range.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/LLVMBitCodes.h"
@@ -555,12 +554,12 @@ class MetadataLoader::MetadataLoaderImpl {
if (!CU)
continue;
- if (auto *RawImported = CU->getRawImportedEntities()) {
+ if (CU->getRawImportedEntities()) {
// Collect a set of imported entities to be moved.
SetVector<Metadata *> EntitiesToRemove;
for (Metadata *Op : CU->getImportedEntities()->operands()) {
auto *IE = cast<DIImportedEntity>(Op);
- if (auto *S = dyn_cast_or_null<DILocalScope>(IE->getScope())) {
+ if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
EntitiesToRemove.insert(IE);
}
}
@@ -705,10 +704,11 @@ class MetadataLoader::MetadataLoaderImpl {
return Error::success();
}
- void upgradeDebugInfo() {
+ void upgradeDebugInfo(bool ModuleLevel) {
upgradeCUSubprograms();
upgradeCUVariables();
- upgradeCULocals();
+ if (ModuleLevel)
+ upgradeCULocals();
}
void callMDTypeCallback(Metadata **Val, unsigned TypeID);
@@ -1085,7 +1085,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
// Reading the named metadata created forward references and/or
// placeholders, that we flush here.
resolveForwardRefsAndPlaceholders(Placeholders);
- upgradeDebugInfo();
+ upgradeDebugInfo(ModuleLevel);
// Return at the beginning of the block, since it is easy to skip it
// entirely from there.
Stream.ReadBlockEnd(); // Pop the abbrev block context.
@@ -1116,7 +1116,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(bool ModuleLevel) {
return error("Malformed block");
case BitstreamEntry::EndBlock:
resolveForwardRefsAndPlaceholders(Placeholders);
- upgradeDebugInfo();
+ upgradeDebugInfo(ModuleLevel);
return Error::success();
case BitstreamEntry::Record:
// The interesting case.
@@ -1213,6 +1213,26 @@ void MetadataLoader::MetadataLoaderImpl::resolveForwardRefsAndPlaceholders(
Placeholders.flush(MetadataList);
}
+static Value *getValueFwdRef(BitcodeReaderValueList &ValueList, unsigned Idx,
+ Type *Ty, unsigned TyID) {
+ Value *V = ValueList.getValueFwdRef(Idx, Ty, TyID,
+ /*ConstExprInsertBB*/ nullptr);
+ if (V)
+ return V;
+
+ // This is a reference to a no longer supported constant expression.
+ // Pretend that the constant was deleted, which will replace metadata
+ // references with undef.
+ // TODO: This is a rather indirect check. It would be more elegant to use
+ // a separate ErrorInfo for constant materialization failure and thread
+ // the error reporting through getValueFwdRef().
+ if (Idx < ValueList.size() && ValueList[Idx] &&
+ ValueList[Idx]->getType() == Ty)
+ return UndefValue::get(Ty);
+
+ return nullptr;
+}
+
Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
SmallVectorImpl<uint64_t> &Record, unsigned Code,
PlaceholderQueue &Placeholders, StringRef Blob, unsigned &NextMetadataNo) {
@@ -1315,7 +1335,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
unsigned TyID = Record[0];
Type *Ty = Callbacks.GetTypeByID(TyID);
- if (Ty->isMetadataTy() || Ty->isVoidTy()) {
+ if (!Ty || Ty->isMetadataTy() || Ty->isVoidTy()) {
dropRecord();
break;
}
@@ -1344,8 +1364,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
if (Ty->isMetadataTy())
Elts.push_back(getMD(Record[i + 1]));
else if (!Ty->isVoidTy()) {
- Value *V = ValueList.getValueFwdRef(Record[i + 1], Ty, TyID,
- /*ConstExprInsertBB*/ nullptr);
+ Value *V = getValueFwdRef(ValueList, Record[i + 1], Ty, TyID);
if (!V)
return error("Invalid value reference from old metadata");
Metadata *MD = ValueAsMetadata::get(V);
@@ -1366,11 +1385,10 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
unsigned TyID = Record[0];
Type *Ty = Callbacks.GetTypeByID(TyID);
- if (Ty->isMetadataTy() || Ty->isVoidTy())
+ if (!Ty || Ty->isMetadataTy() || Ty->isVoidTy())
return error("Invalid record");
- Value *V = ValueList.getValueFwdRef(Record[1], Ty, TyID,
- /*ConstExprInsertBB*/ nullptr);
+ Value *V = getValueFwdRef(ValueList, Record[1], Ty, TyID);
if (!V)
return error("Invalid value reference from metadata");
@@ -1615,7 +1633,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
// DICompositeType flag specifying whether template parameters are
// required on declarations of this type.
StringRef NameStr = Name->getString();
- if (!NameStr.contains('<') || NameStr.startswith("_STN|"))
+ if (!NameStr.contains('<') || NameStr.starts_with("_STN|"))
TemplateParams = getMDOrNull(Record[14]);
}
} else {