diff --git a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp index 3436dc9ef4521..e980447129a2b 100644 --- a/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp +++ b/llvm/lib/Target/AArch64/AArch64BranchTargets.cpp @@ -57,7 +57,6 @@ void AArch64BranchTargets::getAnalysisUsage(AnalysisUsage &AU) const { FunctionPass *llvm::createAArch64BranchTargetsPass() { return new AArch64BranchTargets(); } - bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { if (!MF.getInfo()->branchTargetEnforcement()) return false; @@ -100,7 +99,7 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) { // If the block itself is address-taken, it could be indirectly branched // to, but not called. if (MBB.isMachineBlockAddressTaken() || MBB.isIRBlockAddressTaken() || - JumpTableTargets.count(&MBB)) + JumpTableTargets.count(&MBB) || MBB.isEHPad()) CouldJump = true; if (CouldCall || CouldJump) { @@ -147,7 +146,15 @@ void AArch64BranchTargets::addBTI(MachineBasicBlock &MBB, bool CouldCall, BuildMI(MBB, MBB.begin(), MBB.findDebugLoc(MBB.begin()), TII->get(AArch64::SEH_Nop)); } - BuildMI(MBB, MBB.begin(), MBB.findDebugLoc(MBB.begin()), + + MBBI = MBB.begin(); + if (MBB.isEHPad()) { + while (MBBI != MBB.end() && + MBBI->getOpcode() == TargetOpcode::EH_LABEL) + ++MBBI; + } + + BuildMI(MBB, MBBI, MBB.findDebugLoc(MBBI), TII->get(AArch64::HINT)) .addImm(HintNum); } diff --git a/llvm/test/CodeGen/AArch64/bti-ehpad.ll b/llvm/test/CodeGen/AArch64/bti-ehpad.ll new file mode 100644 index 0000000000000..70e43ff5c5d5d --- /dev/null +++ b/llvm/test/CodeGen/AArch64/bti-ehpad.ll @@ -0,0 +1,26 @@ +; llvm/test/CodeGen/AArch64/bti-ehpad.ll +; REQUIRES: aarch64-registered-target +; RUN: llc -mtriple=aarch64-none-linux-gnu %s -o - | FileCheck %s + +declare i32 @__gxx_personality_v0(...) + +define void @test() #0 personality ptr @__gxx_personality_v0 { +entry: + invoke void @may_throw() + to label %ret unwind label %lpad +lpad: ; catch.dispatch + landingpad { ptr, i32 } + cleanup + ret void +ret: + ret void +} + +declare void @may_throw() + +attributes #0 = { "branch-target-enforcement"="true" } + +; Function needs both the architectural feature *and* the enforcement request. +attributes #0 = { "branch-target-enforcement"="true" "target-features"="+bti" } + +; CHECK: bti