aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Transforms/Utils/CloningTest.cpp
diff options
context:
space:
mode:
authorChristian Ulmann <christianulmann@gmail.com>2025-05-12 13:03:49 +0200
committerGitHub <noreply@github.com>2025-05-12 13:03:49 +0200
commit292cfa715a2e110cab9c0aced0a8fba0e236a0f6 (patch)
treeb05a6cbcb94bb14a0879280c1c510af849da44a4 /llvm/unittests/Transforms/Utils/CloningTest.cpp
parent4f107cd8f8b879fa611a7afbd70b9d029d2bdf29 (diff)
downloadllvm-292cfa715a2e110cab9c0aced0a8fba0e236a0f6.zip
llvm-292cfa715a2e110cab9c0aced0a8fba0e236a0f6.tar.gz
llvm-292cfa715a2e110cab9c0aced0a8fba0e236a0f6.tar.bz2
[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.
Diffstat (limited to 'llvm/unittests/Transforms/Utils/CloningTest.cpp')
-rw-r--r--llvm/unittests/Transforms/Utils/CloningTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 8f6ec12..09b32bf 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -1004,6 +1004,16 @@ protected:
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