diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1403,15 +1403,12 @@ if (!Value::hasMetadata()) return; // Nothing to remove! - if (KnownIDs.empty()) { - // Just drop our entry at the store. - clearMetadata(); - return; - } - SmallSet KnownSet; KnownSet.insert(KnownIDs.begin(), KnownIDs.end()); + // A DIAssignID attachment is debug metadata, don't drop it. + KnownSet.insert(LLVMContext::MD_DIAssignID); + auto &MetadataStore = getContext().pImpl->ValueMetadata; auto &Info = MetadataStore[this]; assert(!Info.empty() && "bit out of sync with hash table"); diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -665,6 +665,17 @@ EXPECT_EQ(NewID0, NewID1); EXPECT_EQ(Markers[0]->getAssignID(), NewID0); } + + // Test 5 - dropUnknownNonDebugMetadata. + // + // Input store0->dropUnknownNonDebugMetadata() + // ----- ------------------------- + // store0 !x store0 !x + { + Stores[0]->dropUnknownNonDebugMetadata(); + Metadata *NewID0 = Stores[0]->getMetadata(LLVMContext::MD_DIAssignID); + EXPECT_NE(NewID0, nullptr); + } } } // end namespace