From fdccad925c91aa981c097f51e3790069dcd0a49a Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 7 Apr 2016 01:22:45 +0000 Subject: [PATCH] ValueMapper: Allow RF_IgnoreMissingLocals and RF_NullMapMissingGlobalValues Remove the assertion that disallowed the combination, since RF_IgnoreMissingLocals should have no effect on globals. As it happens, RF_NullMapMissingGlobalValues asserted in MapValue(Constant*,...), so I also changed a cast to a cast_or_null to get my test passing. llvm-svn: 265633 --- llvm/include/llvm/Transforms/Utils/ValueMapper.h | 3 ++- llvm/lib/Transforms/Utils/ValueMapper.cpp | 8 +------- llvm/unittests/Transforms/Utils/ValueMapperTest.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/ValueMapper.h b/llvm/include/llvm/Transforms/Utils/ValueMapper.h index f986c01..e8023bd 100644 --- a/llvm/include/llvm/Transforms/Utils/ValueMapper.h +++ b/llvm/include/llvm/Transforms/Utils/ValueMapper.h @@ -128,7 +128,8 @@ inline Constant *MapValue(const Constant *V, ValueToValueMapTy &VM, RemapFlags Flags = RF_None, ValueMapTypeRemapper *TypeMapper = nullptr, ValueMaterializer *Materializer = nullptr) { - return cast( + // This can be null for RF_NullMapMissingGlobalValues. + return cast_or_null( MapValue((const Value *)V, VM, Flags, TypeMapper, Materializer)); } diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 8b12cd4..5a92b4c 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -276,14 +276,8 @@ Value *Mapper::mapValue(const Value *V) { // Global values do not need to be seeded into the VM if they // are using the identity mapping. if (isa(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(V); } diff --git a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp index 56e407b..b9cca22 100644 --- a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp +++ b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp @@ -209,4 +209,16 @@ TEST(ValueMapperTest, MapValueLocalAsMetadata) { 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 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 -- 2.7.4