Skip to content

Commit 2b898af

Browse files
authored
[llvm] Add comment and assert for CloneModule edge case (#67734)
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 empty function bodies before the segmentation fault is triggered.
1 parent b19c40c commit 2b898af

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

llvm/lib/Transforms/Utils/CloneModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static void copyComdat(GlobalObject *Dst, const GlobalObject *Src) {
3434
/// copies of global variables and functions, and making their (initializers and
3535
/// references, respectively) refer to the right globals.
3636
///
37+
/// Cloning un-materialized modules is not currently supported, so any
38+
/// modules initialized via lazy loading should be materialized before cloning
3739
std::unique_ptr<Module> llvm::CloneModule(const Module &M) {
3840
// Create the value map that maps things from the old module over to the new
3941
// module.
@@ -49,6 +51,9 @@ std::unique_ptr<Module> llvm::CloneModule(const Module &M,
4951
std::unique_ptr<Module> llvm::CloneModule(
5052
const Module &M, ValueToValueMapTy &VMap,
5153
function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) {
54+
55+
assert(M.isMaterialized() && "Module must be materialized before cloning!");
56+
5257
// First off, we need to create the new module.
5358
std::unique_ptr<Module> New =
5459
std::make_unique<Module>(M.getModuleIdentifier(), M.getContext());

0 commit comments

Comments
 (0)