[llvm] [llvm] Add comment and assert for CloneModule edge case (PR #67734)
Jacob Lambert via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 20:41:24 PDT 2023
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/67734
>From 459f35b413604445ed4675a7a8697ef03d62be96 Mon Sep 17 00:00:00 2001
From: Jacob Lambert <jacob.lambert at amd.com>
Date: Thu, 28 Sep 2023 13:26:11 -0700
Subject: [PATCH] [llvm] Add comment and assert for CloneModule edge case
CloneModule is not currently designed to handle un-materialized
Modules, for example one created via a lazy initializer like
getLazyBitcodeModule(). In this case we get a somewhat cryptic
segmentation fault without a clear path forward.
In this patch, we add a comment to inform CloneModule users of
this shortcoming, and an assert to test for unmaterialized modules
---
llvm/lib/Transforms/Utils/CloneModule.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp
index 55e051298a9a352..aae0a280afeb5c7 100644
--- a/llvm/lib/Transforms/Utils/CloneModule.cpp
+++ b/llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -34,6 +34,8 @@ static void copyComdat(GlobalObject *Dst, const GlobalObject *Src) {
/// copies of global variables and functions, and making their (initializers and
/// references, respectively) refer to the right globals.
///
+/// Cloning un-materialized modules is not currently supported, so any
+/// modules initialized via lazy loading should be materialized before cloning
std::unique_ptr<Module> llvm::CloneModule(const Module &M) {
// Create the value map that maps things from the old module over to the new
// module.
@@ -49,6 +51,9 @@ std::unique_ptr<Module> llvm::CloneModule(const Module &M,
std::unique_ptr<Module> llvm::CloneModule(
const Module &M, ValueToValueMapTy &VMap,
function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) {
+
+ assert(M.isMaterialized() && "Module must be materialized before cloning!");
+
// First off, we need to create the new module.
std::unique_ptr<Module> New =
std::make_unique<Module>(M.getModuleIdentifier(), M.getContext());
More information about the llvm-commits
mailing list