Index: llvm/lib/IR/Metadata.cpp =================================================================== --- llvm/lib/IR/Metadata.cpp +++ llvm/lib/IR/Metadata.cpp @@ -1307,15 +1307,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"); Index: llvm/unittests/IR/DebugInfoTest.cpp =================================================================== --- llvm/unittests/IR/DebugInfoTest.cpp +++ llvm/unittests/IR/DebugInfoTest.cpp @@ -589,6 +589,17 @@ EXPECT_EQ(NewID0, NewID1); EXPECT_EQ(Markers[0]->getAssignID(), NewID0); } + + // Test 4 - 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