[llvm] [IR] Fix Module move-assignment missing NamedMDSymTab, ComdatSymTab and Parent update (PR #175501)
Zichen Lu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 12 00:54:59 PST 2026
https://github.com/MikaOvO updated https://github.com/llvm/llvm-project/pull/175501
>From 0925e1d2b51f8f9497d0bf4f7ae838c8a925959f Mon Sep 17 00:00:00 2001
From: Zichen Lu <mikaovo2000 at gmail.com>
Date: Mon, 12 Jan 2026 16:27:26 +0800
Subject: [PATCH] [IR] Fix Module move-assignment missing NamedMDSymTab,
ComdatSymTab and Parent update
---
llvm/lib/IR/Module.cpp | 5 +++++
llvm/unittests/IR/ModuleTest.cpp | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index e19336efd1c8a..858ffae23b8f6 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -98,6 +98,11 @@ Module &Module::operator=(Module &&Other) {
NamedMDList.clear();
NamedMDList.splice(NamedMDList.begin(), Other.NamedMDList);
+ for (NamedMDNode &NMD : NamedMDList)
+ namedMDNode.setParent(this);
+
+ NamedMDSymTab = std::move(Other.NamedMDSymTab);
+ ComdatSymTab = std::move(Other.ComdatSymTab);
GlobalScopeAsm = std::move(Other.GlobalScopeAsm);
OwnedMemoryBuffer = std::move(Other.OwnedMemoryBuffer);
Materializer = std::move(Other.Materializer);
diff --git a/llvm/unittests/IR/ModuleTest.cpp b/llvm/unittests/IR/ModuleTest.cpp
index 1e4565b219386..255216dc17b2f 100644
--- a/llvm/unittests/IR/ModuleTest.cpp
+++ b/llvm/unittests/IR/ModuleTest.cpp
@@ -423,6 +423,13 @@ define void @Foo2() {
ASSERT_EQ(GV2->getParent(), &*M2);
*M1 = std::move(*M2);
ASSERT_EQ(GV2->getParent(), &*M1);
+
+ ASSERT_NE(M1->getNamedMetadata("foo2"), nullptr);
+ ASSERT_NE(M1->getNamedMetadata("bar2"), nullptr);
+ ASSERT_EQ(M1->getNamedMetadata("foo1"), nullptr);
+
+ for (const NamedMDNode &NMD : M1->named_metadata())
+ ASSERT_EQ(NMD.getParent(), &*M1);
}
std::string M1Print;
More information about the llvm-commits
mailing list