Skip to content

Commit f5b7079

Browse files
committed
[BOLT][NFC] Add MCPlusBuilder unittests for PAuth helpers
PR llvm#120064 added several MCPlusBuilder helpers for recognising instructions which sign or authenticate the link register. This patch adds MCPlusBuilder unittests for these helpers.
1 parent 5260920 commit f5b7079

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

bolt/unittests/Core/MCPlusBuilder.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,62 @@ TEST_P(MCPlusBuilderTester, testAccessedRegsMultipleDefs) {
261261
{AArch64::W5, AArch64::X5, AArch64::W5_HI});
262262
}
263263

264+
TEST_P(MCPlusBuilderTester, AArch64_Psign_Pauth_variants) {
265+
if (GetParam() != Triple::aarch64)
266+
GTEST_SKIP();
267+
268+
MCInst Paciasp = MCInstBuilder(AArch64::PACIASP);
269+
MCInst Pacibsp = MCInstBuilder(AArch64::PACIBSP);
270+
ASSERT_TRUE(BC->MIB->isPSignOnLR(Paciasp));
271+
ASSERT_TRUE(BC->MIB->isPSignOnLR(Pacibsp));
272+
273+
MCInst PaciaSPLR =
274+
MCInstBuilder(AArch64::PACIA).addReg(AArch64::LR).addReg(AArch64::SP);
275+
MCInst PacibSPLR =
276+
MCInstBuilder(AArch64::PACIB).addReg(AArch64::LR).addReg(AArch64::SP);
277+
ASSERT_TRUE(BC->MIB->isPSignOnLR(PaciaSPLR));
278+
ASSERT_TRUE(BC->MIB->isPSignOnLR(PacibSPLR));
279+
280+
MCInst Pacia1716 = MCInstBuilder(AArch64::PACIA1716);
281+
MCInst Pacib1716 = MCInstBuilder(AArch64::PACIB1716);
282+
ASSERT_FALSE(BC->MIB->isPSignOnLR(Pacia1716));
283+
ASSERT_FALSE(BC->MIB->isPSignOnLR(Pacib1716));
284+
285+
MCInst Pacia171615 = MCInstBuilder(AArch64::PACIA171615);
286+
MCInst Pacib171615 = MCInstBuilder(AArch64::PACIB171615);
287+
ASSERT_FALSE(BC->MIB->isPSignOnLR(Pacia171615));
288+
ASSERT_FALSE(BC->MIB->isPSignOnLR(Pacib171615));
289+
290+
MCInst Autiasp = MCInstBuilder(AArch64::AUTIASP);
291+
MCInst Autibsp = MCInstBuilder(AArch64::AUTIBSP);
292+
ASSERT_TRUE(BC->MIB->isPAuthOnLR(Autiasp));
293+
ASSERT_TRUE(BC->MIB->isPAuthOnLR(Autibsp));
294+
295+
MCInst AutiaSPLR =
296+
MCInstBuilder(AArch64::AUTIA).addReg(AArch64::LR).addReg(AArch64::SP);
297+
MCInst AutibSPLR =
298+
MCInstBuilder(AArch64::AUTIB).addReg(AArch64::LR).addReg(AArch64::SP);
299+
ASSERT_TRUE(BC->MIB->isPAuthOnLR(AutiaSPLR));
300+
ASSERT_TRUE(BC->MIB->isPAuthOnLR(AutibSPLR));
301+
302+
MCInst Autia1716 = MCInstBuilder(AArch64::AUTIA1716);
303+
MCInst Autib1716 = MCInstBuilder(AArch64::AUTIB1716);
304+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Autia1716));
305+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Autib1716));
306+
307+
MCInst Autia171615 = MCInstBuilder(AArch64::AUTIA171615);
308+
MCInst Autib171615 = MCInstBuilder(AArch64::AUTIB171615);
309+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Autia171615));
310+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Autib171615));
311+
312+
MCInst Retaa = MCInstBuilder(AArch64::RETAA);
313+
MCInst Retab = MCInstBuilder(AArch64::RETAB);
314+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Retaa));
315+
ASSERT_FALSE(BC->MIB->isPAuthOnLR(Retab));
316+
ASSERT_TRUE(BC->MIB->isPAuthAndRet(Retaa));
317+
ASSERT_TRUE(BC->MIB->isPAuthAndRet(Retab));
318+
}
319+
264320
#endif // AARCH64_AVAILABLE
265321

266322
#ifdef X86_AVAILABLE

0 commit comments

Comments
 (0)