[llvm] [LLVM][Transforms] Add unit test for resolved cloning bug (PR #139223)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 9 01:28:19 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Christian Ulmann (Dinistro)
<details>
<summary>Changes</summary>
This commit introduces a new unit test that covers a block address cloning bug. Specifically, this test covers the bug tracked in http://github.com/llvm/llvm-project/issues/47769 which has been resolved in the meantime.
---
Full diff: https://github.com/llvm/llvm-project/pull/139223.diff
1 Files Affected:
- (modified) llvm/unittests/Transforms/Utils/CloningTest.cpp (+19)
``````````diff
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 03769ff59e372..11ff1a88ee299 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -1001,6 +1001,16 @@ class CloneModule : public ::testing::Test {
Function::Create(FuncType, GlobalValue::ExternalLinkage, "g", OldM);
G->addMetadata(LLVMContext::MD_type, *MDNode::get(C, {}));
+ auto *NonEntryBlock = BasicBlock::Create(C, "", F);
+ IBuilder.SetInsertPoint(NonEntryBlock);
+ IBuilder.CreateRetVoid();
+
+ // Create a global that contains the block address in its initializer.
+ auto *BlockAddress = BlockAddress::get(NonEntryBlock);
+ new GlobalVariable(*OldM, BlockAddress->getType(), /*isConstant=*/true,
+ GlobalVariable::ExternalLinkage, BlockAddress,
+ "blockaddr");
+
// Finalize the debug info
DBuilder.finalize();
}
@@ -1162,4 +1172,13 @@ declare i64 @foo(i32 noundef) local_unnamed_addr
auto NewM = llvm::CloneModule(*M);
EXPECT_FALSE(verifyModule(*NewM, &errs()));
}
+
+// Checks that block addresses in global initializers are properly cloned.
+TEST_F(CloneModule, GlobalWithBlockAddressesInitializer) {
+ auto *OriginalBa = cast<BlockAddress>(
+ OldM->getGlobalVariable("blockaddr")->getInitializer());
+ auto *ClonedBa = cast<BlockAddress>(
+ NewM->getGlobalVariable("blockaddr")->getInitializer());
+ ASSERT_NE(OriginalBa->getBasicBlock(), ClonedBa->getBasicBlock());
+}
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/139223
More information about the llvm-commits
mailing list