RemapFlags Flags = RF_None,
ValueMapTypeRemapper *TypeMapper = nullptr,
ValueMaterializer *Materializer = nullptr) {
- return cast<Constant>(
+ // This can be null for RF_NullMapMissingGlobalValues.
+ return cast_or_null<Constant>(
MapValue((const Value *)V, VM, Flags, TypeMapper, Materializer));
}
// Global values do not need to be seeded into the VM if they
// are using the identity mapping.
if (isa<GlobalValue>(V)) {
- if (Flags & RF_NullMapMissingGlobalValues) {
- // FIXME: Remove this assertion. RF_IgnoreMissingLocals is unrelated to
- // RF_NullMapMissingGlobalValues.
- assert(!(Flags & RF_IgnoreMissingLocals) &&
- "Illegal to specify both RF_NullMapMissingGlobalValues and "
- "RF_IgnoreMissingLocals");
+ if (Flags & RF_NullMapMissingGlobalValues)
return nullptr;
- }
return VM[V] = const_cast<Value*>(V);
}
EXPECT_EQ(&A, MapValue(MAV, VM, RF_IgnoreMissingLocals));
}
+TEST(ValueMapperTest, MapMetadataNullMapGlobalWithIgnoreMissingLocals) {
+ LLVMContext C;
+ FunctionType *FTy =
+ FunctionType::get(Type::getVoidTy(C), Type::getInt8Ty(C), false);
+ std::unique_ptr<Function> F(
+ Function::Create(FTy, GlobalValue::ExternalLinkage, "F"));
+
+ ValueToValueMapTy VM;
+ RemapFlags Flags = RF_IgnoreMissingLocals | RF_NullMapMissingGlobalValues;
+ EXPECT_EQ(nullptr, MapValue(F.get(), VM, Flags));
+}
+
} // end namespace