Skip to content

Commit a742d68

Browse files
committed
Address review feedback.
- test invoke for ELF as well - consolidate GISel/SDAG invoke test - check key/disc validity in consistent ways - misc. nits
1 parent 93755da commit a742d68

File tree

5 files changed

+237
-323
lines changed

5 files changed

+237
-323
lines changed

llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,18 +1552,20 @@ void AArch64AsmPrinter::emitPtrauthBranch(const MachineInstr *MI) {
15521552
unsigned InstsEmitted = 0;
15531553

15541554
unsigned BrTarget = MI->getOperand(0).getReg();
1555+
15551556
auto Key = (AArch64PACKey::ID)MI->getOperand(1).getImm();
1557+
assert((Key == AArch64PACKey::IA || Key == AArch64PACKey::IB) &&
1558+
"Invalid auth call key");
1559+
15561560
uint64_t Disc = MI->getOperand(2).getImm();
1561+
assert(isUInt<16>(Disc));
1562+
15571563
unsigned AddrDisc = MI->getOperand(3).getReg();
15581564

15591565
// Compute discriminator into x17
1560-
assert(isUInt<16>(Disc));
15611566
unsigned DiscReg = emitPtrauthDiscriminator(Disc, AddrDisc, InstsEmitted);
15621567
bool IsZeroDisc = DiscReg == AArch64::XZR;
15631568

1564-
assert((Key == AArch64PACKey::IA || Key == AArch64PACKey::IB) &&
1565-
"Invalid auth call key");
1566-
15671569
unsigned Opc;
15681570
if (Key == AArch64PACKey::IA)
15691571
Opc = IsZeroDisc ? AArch64::BLRAAZ : AArch64::BLRAA;
@@ -1726,8 +1728,12 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
17261728
case AArch64::AUTH_TCRETURN:
17271729
case AArch64::AUTH_TCRETURN_BTI: {
17281730
const uint64_t Key = MI->getOperand(2).getImm();
1729-
assert(Key < 2 && "Unknown key kind for authenticating tail-call return");
1731+
assert((Key == AArch64PACKey::IA || Key == AArch64PACKey::IB) &&
1732+
"Invalid auth key for tail-call return");
1733+
17301734
const uint64_t Disc = MI->getOperand(3).getImm();
1735+
assert(isUInt<16>(Disc) && "Integer discriminator is too wide");
1736+
17311737
Register AddrDisc = MI->getOperand(4).getReg();
17321738

17331739
Register ScratchReg = MI->getOperand(0).getReg() == AArch64::X16
@@ -1736,8 +1742,6 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
17361742

17371743
unsigned DiscReg = AddrDisc;
17381744
if (Disc) {
1739-
assert(isUInt<16>(Disc) && "Integer discriminator is too wide");
1740-
17411745
if (AddrDisc != AArch64::NoRegister) {
17421746
EmitToStreamer(*OutStreamer, MCInstBuilder(AArch64::ORRXrs)
17431747
.addReg(ScratchReg)
@@ -1758,14 +1762,14 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
17581762
DiscReg = ScratchReg;
17591763
}
17601764

1761-
const bool isZero = DiscReg == AArch64::NoRegister;
1765+
const bool IsZero = DiscReg == AArch64::NoRegister;
17621766
const unsigned Opcodes[2][2] = {{AArch64::BRAA, AArch64::BRAAZ},
17631767
{AArch64::BRAB, AArch64::BRABZ}};
17641768

17651769
MCInst TmpInst;
1766-
TmpInst.setOpcode(Opcodes[Key][isZero]);
1770+
TmpInst.setOpcode(Opcodes[Key][IsZero]);
17671771
TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1768-
if (!isZero)
1772+
if (!IsZero)
17691773
TmpInst.addOperand(MCOperand::createReg(DiscReg));
17701774
EmitToStreamer(*OutStreamer, TmpInst);
17711775
return;

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8468,8 +8468,9 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
84688468
Ops.insert(Ops.begin() + 1, GA);
84698469
} else if (CallConv == CallingConv::ARM64EC_Thunk_X64) {
84708470
Opc = AArch64ISD::CALL_ARM64EC_TO_X64;
8471-
} else if (GuardWithBTI)
8471+
} else if (GuardWithBTI) {
84728472
Opc = AArch64ISD::CALL_BTI;
8473+
}
84738474

84748475
if (IsTailCall) {
84758476
// Each tail call may have to adjust the stack by a different amount, so
@@ -8480,9 +8481,8 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
84808481

84818482
if (CLI.PAI) {
84828483
const uint64_t Key = CLI.PAI->Key;
8483-
// Authenticated calls only support IA and IB.
8484-
if (Key > 1)
8485-
report_fatal_error("Unsupported key kind for authenticating call");
8484+
assert((Key == AArch64PACKey::IA || Key == AArch64PACKey::IB) &&
8485+
"Invalid auth call key");
84868486

84878487
// Split the discriminator into address/integer components.
84888488
SDValue AddrDisc, IntDisc;

llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,10 +1021,11 @@ static unsigned getCallOpcode(const MachineFunction &CallerF, bool IsIndirect,
10211021

10221022
if (!IsTailCall) {
10231023
if (!PAI)
1024-
return IsIndirect ? getBLRCallOpcode(CallerF) : (unsigned)AArch64::BL;
1024+
return IsIndirect ? getBLRCallOpcode(CallerF) : AArch64::BL;
10251025

1026-
assert(IsIndirect && "authenticated direct call");
1027-
assert(PAI->Key == 0 || PAI->Key == 1 && "invalid ptrauth key");
1026+
assert(IsIndirect && "Direct call should not be authenticated");
1027+
assert((PAI->Key == AArch64PACKey::IA || PAI->Key == AArch64PACKey::IB) &&
1028+
"Invalid auth call key");
10281029
return AArch64::BLRA;
10291030
}
10301031

@@ -1036,11 +1037,12 @@ static unsigned getCallOpcode(const MachineFunction &CallerF, bool IsIndirect,
10361037
if (FuncInfo->branchTargetEnforcement()) {
10371038
if (PAI)
10381039
return AArch64::AUTH_TCRETURN_BTI;
1039-
else if (FuncInfo->branchProtectionPAuthLR())
1040+
if (FuncInfo->branchProtectionPAuthLR())
10401041
return AArch64::TCRETURNrix17;
1041-
else
1042-
return AArch64::TCRETURNrix16x17;
1043-
} else if (FuncInfo->branchProtectionPAuthLR())
1042+
return AArch64::TCRETURNrix16x17;
1043+
}
1044+
1045+
if (FuncInfo->branchProtectionPAuthLR())
10441046
return AArch64::TCRETURNrinotx16;
10451047

10461048
if (PAI)
@@ -1104,7 +1106,9 @@ bool AArch64CallLowering::lowerTailCall(
11041106

11051107
// Authenticated tail calls always take key/discriminator arguments.
11061108
if (Opc == AArch64::AUTH_TCRETURN || Opc == AArch64::AUTH_TCRETURN_BTI) {
1107-
assert(Info.PAI->Key == 0 || Info.PAI->Key == 1 && "invalid key");
1109+
assert((Info.PAI->Key == AArch64PACKey::IA ||
1110+
Info.PAI->Key == AArch64PACKey::IB) &&
1111+
"Invalid auth call key");
11081112
MIB.addImm(Info.PAI->Key);
11091113

11101114
Register AddrDisc = 0;
@@ -1371,7 +1375,9 @@ bool AArch64CallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
13711375
Mask = getMaskForArgs(OutArgs, Info, *TRI, MF);
13721376

13731377
if (Opc == AArch64::BLRA || Opc == AArch64::BLRA_RVMARKER) {
1374-
assert(Info.PAI->Key == 0 || Info.PAI->Key == 1 && "invalid key");
1378+
assert((Info.PAI->Key == AArch64PACKey::IA ||
1379+
Info.PAI->Key == AArch64PACKey::IB) &&
1380+
"Invalid auth call key");
13751381
MIB.addImm(Info.PAI->Key);
13761382

13771383
Register AddrDisc = 0;

llvm/test/CodeGen/AArch64/GlobalISel/ptrauth-invoke.ll

Lines changed: 0 additions & 183 deletions
This file was deleted.

0 commit comments

Comments
 (0)