From 02f50d05d5fea4e9c5fac310abccc5f7d770b25b Mon Sep 17 00:00:00 2001 From: OCHyams Date: Wed, 9 Nov 2022 10:49:55 +0000 Subject: [PATCH] [Assignment Tracking][9/*] Don't drop DIAssignID in dropUnknownNonDebugMetadata The Assignment Tracking debug-info feature is outlined in this RFC: https://discourse.llvm.org/t/ rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir A DIAssignID attachment is debug metadata, so don't drop it. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D133292 --- llvm/lib/IR/Metadata.cpp | 9 +++------ llvm/unittests/IR/DebugInfoTest.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 5336902..bde8371 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1403,15 +1403,12 @@ void Instruction::dropUnknownNonDebugMetadata(ArrayRef KnownIDs) { 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 index 970de06..bf676f9 100644 --- a/llvm/unittests/IR/DebugInfoTest.cpp +++ b/llvm/unittests/IR/DebugInfoTest.cpp @@ -665,6 +665,17 @@ TEST(AssignmentTrackingTest, InstrMethods) { 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 -- 2.7.4