Skip to content

Commit 292cfa7

Browse files
authored
[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.
1 parent 4f107cd commit 292cfa7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llvm/unittests/Transforms/Utils/CloningTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,16 @@ class CloneModule : public ::testing::Test {
10041004
Function::Create(FuncType, GlobalValue::ExternalLinkage, "g", OldM);
10051005
G->addMetadata(LLVMContext::MD_type, *MDNode::get(C, {}));
10061006

1007+
auto *NonEntryBlock = BasicBlock::Create(C, "", F);
1008+
IBuilder.SetInsertPoint(NonEntryBlock);
1009+
IBuilder.CreateRetVoid();
1010+
1011+
// Create a global that contains the block address in its initializer.
1012+
auto *BlockAddress = BlockAddress::get(NonEntryBlock);
1013+
new GlobalVariable(*OldM, BlockAddress->getType(), /*isConstant=*/true,
1014+
GlobalVariable::ExternalLinkage, BlockAddress,
1015+
"blockaddr");
1016+
10071017
// Finalize the debug info
10081018
DBuilder.finalize();
10091019
}
@@ -1266,4 +1276,13 @@ TEST_F(CloneInstruction, cloneKeyInstructions) {
12661276
#undef EXPECT_ATOM
12671277
}
12681278

1279+
// Checks that block addresses in global initializers are properly cloned.
1280+
TEST_F(CloneModule, GlobalWithBlockAddressesInitializer) {
1281+
auto *OriginalBa = cast<BlockAddress>(
1282+
OldM->getGlobalVariable("blockaddr")->getInitializer());
1283+
auto *ClonedBa = cast<BlockAddress>(
1284+
NewM->getGlobalVariable("blockaddr")->getInitializer());
1285+
ASSERT_NE(OriginalBa->getBasicBlock(), ClonedBa->getBasicBlock());
1286+
}
1287+
12691288
} // namespace

0 commit comments

Comments
 (0)