[llvm] 292cfa7 - [LLVM][Transforms] Add unit test for resolved cloning bug (#139223)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 12 04:03:52 PDT 2025
Author: Christian Ulmann
Date: 2025-05-12T13:03:49+02:00
New Revision: 292cfa715a2e110cab9c0aced0a8fba0e236a0f6
URL: https://github.com/llvm/llvm-project/commit/292cfa715a2e110cab9c0aced0a8fba0e236a0f6
DIFF: https://github.com/llvm/llvm-project/commit/292cfa715a2e110cab9c0aced0a8fba0e236a0f6.diff
LOG: [LLVM][Transforms] Add unit test for resolved cloning bug (#139223)
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.
Added:
Modified:
llvm/unittests/Transforms/Utils/CloningTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 8f6ec12ec77aa..09b32bf09df0e 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -1004,6 +1004,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();
}
@@ -1266,4 +1276,13 @@ TEST_F(CloneInstruction, cloneKeyInstructions) {
#undef EXPECT_ATOM
}
+// 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
More information about the llvm-commits
mailing list