diff --git a/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp b/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp --- a/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp +++ b/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp @@ -137,8 +137,10 @@ Changed |= addENDBR(MBB, MBB.begin()); for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) { - if (I->isCall() && IsCallReturnTwice(I->getOperand(0))) + if (I->isCall() && I->getNumOperands() > 0 && + IsCallReturnTwice(I->getOperand(0))) { Changed |= addENDBR(MBB, std::next(I)); + } } // Exception handle may indirectly jump to catch pad, So we should add diff --git a/llvm/test/CodeGen/X86/fentry-ibt.ll b/llvm/test/CodeGen/X86/fentry-ibt.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/fentry-ibt.ll @@ -0,0 +1,17 @@ +; RUN: llc %s -o - -verify-machineinstrs | FileCheck %s + +define void @test1() #0 { +entry: + ret void + +; CHECK-LABEL: @test1 +; CHECK: endbr64 +; CHECK: callq __fentry__ +; CHECK-NOT: mcount +; CHECK: retq +} + +!llvm.module.flags = !{!0} + +attributes #0 = { "fentry-call"="true" } +!0 = !{i32 4, !"cf-protection-branch", i32 1}