From 756e1c3db452165ddcc8b8d11df8a3d36fd427bb Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sun, 3 Apr 2016 20:54:51 +0000 Subject: ValueMapper: Disallow metadata mapping recursion through mapValue This adds an assertion to maintain the property from r265273. When Mapper::mapSimpleMetadata calls Mapper::mapValue, it should not find its way back to mapMetadataImpl. This guarantees that mapSimpleMetadata is not involved in any recursion. Since Mapper::mapValue calls out to arbitrary materializers, we need to save a bit on the ValueMap to make this assertion effective. There should be no functionality change here. This co-recursion should already have been impossible. llvm-svn: 265276 --- llvm/lib/Transforms/Utils/ValueMapper.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 64ba98e55c9..78f4618aef9 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -379,7 +379,11 @@ Optional Mapper::mapSimpleMetadata(const Metadata *MD) { return mapToSelf(MD); if (const auto *VMD = dyn_cast(MD)) { + // Disallow recursion into metadata mapping through mapValue. + VM.disableMapMetadata(); Value *MappedV = mapValue(VMD->getValue()); + VM.enableMapMetadata(); + if (VMD->getValue() == MappedV || (!MappedV && (Flags & RF_IgnoreMissingEntries))) return mapToSelf(MD); @@ -406,6 +410,7 @@ Optional Mapper::mapSimpleMetadata(const Metadata *MD) { } Metadata *Mapper::mapMetadataImpl(const Metadata *MD) { + assert(VM.mayMapMetadata() && "Unexpected co-recursion through mapValue"); if (Optional NewMD = mapSimpleMetadata(MD)) return *NewMD; -- cgit v1.2.3