@@ -473,8 +473,7 @@ class MetadataLoader::MetadataLoaderImpl {
473
473
474
474
Error parseOneMetadata (SmallVectorImpl<uint64_t > &Record, unsigned Code,
475
475
PlaceholderQueue &Placeholders, StringRef Blob,
476
- unsigned &NextMetadataNo,
477
- BasicBlock *ConstExprInsertBB);
476
+ unsigned &NextMetadataNo);
478
477
Error parseMetadataStrings (ArrayRef<uint64_t > Record, StringRef Blob,
479
478
function_ref<void (StringRef)> CallBack);
480
479
Error parseGlobalObjectAttachment (GlobalObject &GO,
@@ -723,7 +722,7 @@ class MetadataLoader::MetadataLoaderImpl {
723
722
TheModule(TheModule), Callbacks(std::move(Callbacks)),
724
723
IsImporting(IsImporting) {}
725
724
726
- Error parseMetadata (bool ModuleLevel, BasicBlock *ConstExprInsertBB );
725
+ Error parseMetadata (bool ModuleLevel);
727
726
728
727
bool hasFwdRefs () const { return MetadataList.hasFwdRefs (); }
729
728
@@ -1048,8 +1047,7 @@ void MetadataLoader::MetadataLoaderImpl::callMDTypeCallback(Metadata **Val,
1048
1047
1049
1048
// / Parse a METADATA_BLOCK. If ModuleLevel is true then we are parsing
1050
1049
// / module level metadata.
1051
- Error MetadataLoader::MetadataLoaderImpl::parseMetadata (
1052
- bool ModuleLevel, BasicBlock *ConstExprInsertBB) {
1050
+ Error MetadataLoader::MetadataLoaderImpl::parseMetadata (bool ModuleLevel) {
1053
1051
if (!ModuleLevel && MetadataList.hasFwdRefs ())
1054
1052
return error (" Invalid metadata: fwd refs into function blocks" );
1055
1053
@@ -1132,7 +1130,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseMetadata(
1132
1130
if (Expected<unsigned > MaybeCode =
1133
1131
Stream.readRecord (Entry.ID , Record, &Blob)) {
1134
1132
if (Error Err = parseOneMetadata (Record, MaybeCode.get (), Placeholders,
1135
- Blob, NextMetadataNo, ConstExprInsertBB ))
1133
+ Blob, NextMetadataNo))
1136
1134
return Err;
1137
1135
} else
1138
1136
return MaybeCode.takeError ();
@@ -1173,8 +1171,7 @@ void MetadataLoader::MetadataLoaderImpl::lazyLoadOneMetadata(
1173
1171
if (Expected<unsigned > MaybeCode =
1174
1172
IndexCursor.readRecord (Entry.ID , Record, &Blob)) {
1175
1173
if (Error Err =
1176
- parseOneMetadata (Record, MaybeCode.get (), Placeholders, Blob, ID,
1177
- /* ConstExprInsertBB */ nullptr ))
1174
+ parseOneMetadata (Record, MaybeCode.get (), Placeholders, Blob, ID))
1178
1175
report_fatal_error (" Can't lazyload MD, parseOneMetadata: " +
1179
1176
Twine (toString (std::move (Err))));
1180
1177
} else
@@ -1216,10 +1213,29 @@ void MetadataLoader::MetadataLoaderImpl::resolveForwardRefsAndPlaceholders(
1216
1213
Placeholders.flush (MetadataList);
1217
1214
}
1218
1215
1216
+ static Value *getValueFwdRef (BitcodeReaderValueList &ValueList, unsigned Idx,
1217
+ Type *Ty, unsigned TyID) {
1218
+ Value *V = ValueList.getValueFwdRef (Idx, Ty, TyID,
1219
+ /* ConstExprInsertBB*/ nullptr );
1220
+ if (V)
1221
+ return V;
1222
+
1223
+ // This is a reference to a no longer supported constant expression.
1224
+ // Pretend that the constant was deleted, which will replace metadata
1225
+ // references with undef.
1226
+ // TODO: This is a rather indirect check. It would be more elegant to use
1227
+ // a separate ErrorInfo for constant materialization failure and thread
1228
+ // the error reporting through getValueFwdRef().
1229
+ if (Idx < ValueList.size () && ValueList[Idx] &&
1230
+ ValueList[Idx]->getType () == Ty)
1231
+ return UndefValue::get (Ty);
1232
+
1233
+ return nullptr ;
1234
+ }
1235
+
1219
1236
Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata (
1220
1237
SmallVectorImpl<uint64_t > &Record, unsigned Code,
1221
- PlaceholderQueue &Placeholders, StringRef Blob, unsigned &NextMetadataNo,
1222
- BasicBlock *ConstExprInsertBB) {
1238
+ PlaceholderQueue &Placeholders, StringRef Blob, unsigned &NextMetadataNo) {
1223
1239
1224
1240
bool IsDistinct = false ;
1225
1241
auto getMD = [&](unsigned ID) -> Metadata * {
@@ -1348,8 +1364,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1348
1364
if (Ty->isMetadataTy ())
1349
1365
Elts.push_back (getMD (Record[i + 1 ]));
1350
1366
else if (!Ty->isVoidTy ()) {
1351
- Value *V = ValueList.getValueFwdRef (Record[i + 1 ], Ty, TyID,
1352
- /* ConstExprInsertBB*/ nullptr );
1367
+ Value *V = getValueFwdRef (ValueList, Record[i + 1 ], Ty, TyID);
1353
1368
if (!V)
1354
1369
return error (" Invalid value reference from old metadata" );
1355
1370
Metadata *MD = ValueAsMetadata::get (V);
@@ -1373,7 +1388,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
1373
1388
if (!Ty || Ty->isMetadataTy () || Ty->isVoidTy ())
1374
1389
return error (" Invalid record" );
1375
1390
1376
- Value *V = ValueList. getValueFwdRef (Record[1 ], Ty, TyID, ConstExprInsertBB );
1391
+ Value *V = getValueFwdRef (ValueList, Record[1 ], Ty, TyID);
1377
1392
if (!V)
1378
1393
return error (" Invalid value reference from metadata" );
1379
1394
@@ -2462,9 +2477,8 @@ MetadataLoader::MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
2462
2477
: Pimpl(std::make_unique<MetadataLoaderImpl>(
2463
2478
Stream, TheModule, ValueList, std::move(Callbacks), IsImporting)) {}
2464
2479
2465
- Error MetadataLoader::parseMetadata (bool ModuleLevel,
2466
- BasicBlock *ConstExprInsertBB) {
2467
- return Pimpl->parseMetadata (ModuleLevel, ConstExprInsertBB);
2480
+ Error MetadataLoader::parseMetadata (bool ModuleLevel) {
2481
+ return Pimpl->parseMetadata (ModuleLevel);
2468
2482
}
2469
2483
2470
2484
bool MetadataLoader::hasFwdRefs () const { return Pimpl->hasFwdRefs (); }
0 commit comments