Skip to content

[LLVM][Transforms] Add unit test for resolved cloning bug #139223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions llvm/unittests/Transforms/Utils/CloningTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Loading