Skip to content

Commit 56251e7

Browse files
committed
[BOLT] Test fillUnknownStubs
1 parent 99fa15e commit 56251e7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

bolt/unittests/Passes/InsertNegateRAState.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,67 @@ TEST_P(PassTester, fillUnknownStateInBBTest) {
221221
EXPECT_EQ(CFILoc[0], 4);
222222
}
223223

224+
TEST_P(PassTester, fillUnknownStubs) {
225+
/*
226+
* Stubs that are not part of the function's CFG should inherit the RAState of
227+
the BasicBlock before it.
228+
*
229+
* LBB1 is not part of the CFG: LBB0 jumps unconditionally to LBB2.
230+
* LBB1 would be a stub inserted in LongJmp in real code.
231+
* We do not add any NegateRAState CFIs, as other CFIs are not added either.
232+
* See issue #160989 for more details.
233+
*
234+
* .LBB0 (1 instructions, align : 1)
235+
Entry Point
236+
00000000: b .LBB2
237+
Successors: .LBB2
238+
239+
.LBB1 (1 instructions, align : 1)
240+
00000004: ret
241+
242+
.LBB2 (1 instructions, align : 1)
243+
Predecessors: .LBB0
244+
00000008: ret
245+
*/
246+
if (GetParam() != Triple::aarch64)
247+
GTEST_SKIP();
248+
249+
ASSERT_NE(TextSection, nullptr);
250+
251+
PREPARE_FUNC("FuncWithStub");
252+
BinaryBasicBlock *BB2 = BF->addBasicBlock();
253+
BB2->setCFIState(0);
254+
BinaryBasicBlock *BB3 = BF->addBasicBlock();
255+
BB3->setCFIState(0);
256+
257+
BB->addSuccessor(BB3);
258+
259+
// Jumping over BB2, to BB3.
260+
MCInst Jump;
261+
BC->MIB->createUncondBranch(Jump, BB3->getLabel(), BC->Ctx.get());
262+
BB->addInstruction(Jump);
263+
BC->MIB->setRAState(Jump, false);
264+
265+
// BB2, in real code it would be a ShortJmp.
266+
// Unknown RAState.
267+
MCInst StubInst;
268+
BC->MIB->createReturn(StubInst);
269+
BB2->addInstruction(StubInst);
270+
271+
// Can be any instruction.
272+
MCInst Ret;
273+
BC->MIB->createReturn(Ret);
274+
BB3->addInstruction(Ret);
275+
BC->MIB->setRAState(Ret, false);
276+
277+
Error E = PassManager->runPasses();
278+
EXPECT_FALSE(E);
279+
280+
// Check that we did not generate any NegateRAState CFIs.
281+
auto CFILoc = findCFIOffsets(*BF);
282+
EXPECT_EQ(CFILoc.size(), 0u);
283+
}
284+
224285
#ifdef AARCH64_AVAILABLE
225286
INSTANTIATE_TEST_SUITE_P(AArch64, PassTester,
226287
::testing::Values(Triple::aarch64));

0 commit comments

Comments
 (0)