File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -127,11 +127,18 @@ bool X86IndirectBranchTrackingPass::runOnMachineFunction(MachineFunction &MF) {
127127 if (MBB.hasAddressTaken ())
128128 Changed |= addENDBR (MBB, MBB.begin ());
129129
130+ // Exception handle may indirectly jump to catch pad, So we should add
131+ // ENDBR before catch pad instructions.
132+ bool EHPadIBTNeeded = MBB.isEHPad ();
133+
130134 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I) {
131- if (!I->isCall ())
132- continue ;
133- if (IsCallReturnTwice (I->getOperand (0 )))
135+ if (I->isCall () && IsCallReturnTwice (I->getOperand (0 )))
134136 Changed |= addENDBR (MBB, std::next (I));
137+
138+ if (EHPadIBTNeeded && I->isEHLabel ()) {
139+ Changed |= addENDBR (MBB, std::next (I));
140+ EHPadIBTNeeded = false ;
141+ }
135142 }
136143 }
137144 return Changed;
Original file line number Diff line number Diff line change 1+ ; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
2+ ; RUN: llc -mtriple=i386-unknown-unknown < %s | FileCheck %s
3+
4+ ;There should be 2 endbr* instruction at entry and catch pad.
5+ ;CHECK-COUNT-2: endbr
6+
7+ declare void @_Z20function_that_throwsv ()
8+ declare i32 @__gxx_personality_sj0 (...)
9+ declare i8* @__cxa_begin_catch (i8* )
10+ declare void @__cxa_end_catch ()
11+
12+ define void @test8 () personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8* ) {
13+ entry:
14+ invoke void @_Z20function_that_throwsv ()
15+ to label %try.cont unwind label %lpad
16+
17+ lpad:
18+ %0 = landingpad { i8* , i32 }
19+ catch i8* null
20+ %1 = extractvalue { i8* , i32 } %0 , 0
21+ %2 = tail call i8* @__cxa_begin_catch (i8* %1 )
22+ tail call void @__cxa_end_catch ()
23+ br label %try.cont
24+
25+ try.cont:
26+ ret void
27+ }
28+
29+ !llvm.module.flags = !{!0 }
30+
31+ !0 = !{i32 4 , !"cf-protection-branch" , i32 1 }
You can’t perform that action at this time.
0 commit comments