llvm.org GIT mirror llvm / d9b72fe
[SEH] Remove the old __C_specific_handler code now that WinEHPrepare works This removes the -sehprepare flag and makes __C_specific_handler functions always to use WinEHPrepare. This was tested by building all of chromium_builder_tests and running a few tests that use SEH, but if something breaks, we can revert this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235557 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
16 changed file(s) with 11 addition(s) and 312 deletion(s). Raw diff Collapse all Expand all
7676 MachineBasicBlock *LandingPadBlock; // Landing pad block.
7777 SmallVector BeginLabels; // Labels prior to invoke.
7878 SmallVector EndLabels; // Labels after invoke.
79 SmallVector ClauseLabels; // Labels for each clause.
8079 SmallVector SEHHandlers; // SEH handlers active at this lpad.
8180 MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
8281 const Function *Personality; // Personality function.
360359 ///
361360 void addCleanup(MachineBasicBlock *LandingPad);
362361
363 /// Add a clause for a landing pad. Returns a new label for the clause. This
364 /// is used by EH schemes that have more than one landing pad. In this case,
365 /// each clause gets its own basic block.
366 MCSymbol *addClauseForLandingPad(MachineBasicBlock *LandingPad);
367
368362 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
369363 const BlockAddress *RecoverLabel);
370364
205205 for (const CallSiteEntry &CSE : CallSites) {
206206 if (!CSE.LPad)
207207 continue; // Ignore gaps.
208 for (int Selector : CSE.LPad->TypeIds) {
209 // Ignore C++ filter clauses in SEH.
210 // FIXME: Implement cleanup clauses.
211 if (isCatchEHSelector(Selector))
212 ++NumEntries;
213 }
214208 NumEntries += CSE.LPad->SEHHandlers.size();
215209 }
216210 Asm->OutStreamer.EmitIntValue(NumEntries, 4);
265259 createImageRel32(Asm->GetBlockAddressSymbol(BA)), 4);
266260 else
267261 Asm->OutStreamer.EmitIntValue(0, 4);
268 }
269 if (!LPad->SEHHandlers.empty())
270 continue;
271
272 // These aren't really type info globals, they are actually pointers to
273 // filter functions ordered by selector. The zero selector is used for
274 // cleanups, so slot zero corresponds to selector 1.
275 const std::vector &SelectorToFilter = MMI->getTypeInfos();
276
277 // Do a parallel iteration across typeids and clause labels, skipping filter
278 // clauses.
279 size_t NextClauseLabel = 0;
280 for (size_t I = 0, E = LPad->TypeIds.size(); I < E; ++I) {
281 // AddLandingPadInfo stores the clauses in reverse, but there is a FIXME
282 // to change that.
283 int Selector = LPad->TypeIds[E - I - 1];
284
285 // Ignore C++ filter clauses in SEH.
286 // FIXME: Implement cleanup clauses.
287 if (!isCatchEHSelector(Selector))
288 continue;
289
290 Asm->OutStreamer.EmitValue(Begin, 4);
291 Asm->OutStreamer.EmitValue(End, 4);
292 if (isCatchEHSelector(Selector)) {
293 assert(unsigned(Selector - 1) < SelectorToFilter.size());
294 const GlobalValue *TI = SelectorToFilter[Selector - 1];
295 if (TI) // Emit the filter function pointer.
296 Asm->OutStreamer.EmitValue(createImageRel32(Asm->getSymbol(TI)), 4);
297 else // Otherwise, this is a "catch i8* null", or catch all.
298 Asm->OutStreamer.EmitIntValue(1, 4);
299 }
300 MCSymbol *ClauseLabel = LPad->ClauseLabels[NextClauseLabel++];
301 Asm->OutStreamer.EmitValue(createImageRel32(ClauseLabel), 4);
302262 }
303263 }
304264 }
460460 LP.TypeIds.push_back(0);
461461 }
462462
463 MCSymbol *
464 MachineModuleInfo::addClauseForLandingPad(MachineBasicBlock *LandingPad) {
465 MCSymbol *ClauseLabel = Context.CreateTempSymbol();
466 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
467 LP.ClauseLabels.push_back(ClauseLabel);
468 return ClauseLabel;
469 }
470
471463 void MachineModuleInfo::addSEHCatchHandler(MachineBasicBlock *LandingPad,
472464 const Function *Filter,
473465 const BlockAddress *RecoverBA) {
954954 // Mark the clause as a landing pad or MI passes will delete it.
955955 ClauseBB->setIsLandingPad();
956956 }
957 } else {
958 // Otherwise, we haven't done the preparation, and we need to invent some
959 // clause basic blocks that branch into the landingpad.
960 // FIXME: Remove this code once SEH preparation works.
961 ActionsCall = nullptr;
962
963 // Make virtual registers and a series of labels that fill in values for
964 // the clauses.
965 auto &RI = MF->getRegInfo();
966 FuncInfo->ExceptionSelectorVirtReg = RI.createVirtualRegister(PtrRC);
967
968 // Emit separate machine basic blocks with separate labels for each clause
969 // before the main landing pad block.
970 MachineInstrBuilder SelectorPHI = BuildMI(
971 *MBB, MBB->begin(), SDB->getCurDebugLoc(),
972 TII->get(TargetOpcode::PHI), FuncInfo->ExceptionSelectorVirtReg);
973 for (unsigned I = 0, E = LPadInst->getNumClauses(); I != E; ++I) {
974 // Skip filter clauses, we can't implement them.
975 if (LPadInst->isFilter(I))
976 continue;
977
978 MachineBasicBlock *ClauseBB = MF->CreateMachineBasicBlock(LLVMBB);
979 MF->insert(MBB, ClauseBB);
980
981 // Add the edge from the invoke to the clause.
982 for (MachineBasicBlock *InvokeBB : InvokeBBs)
983 InvokeBB->addSuccessor(ClauseBB);
984
985 // Mark the clause as a landing pad or MI passes will delete it.
986 ClauseBB->setIsLandingPad();
987
988 GlobalValue *ClauseGV = ExtractTypeInfo(LPadInst->getClause(I));
989
990 // Start the BB with a label.
991 MCSymbol *ClauseLabel = MF->getMMI().addClauseForLandingPad(MBB);
992 BuildMI(*ClauseBB, ClauseBB->begin(), SDB->getCurDebugLoc(), II)
993 .addSym(ClauseLabel);
994
995 // Construct a simple BB that defines a register with the typeid
996 // constant.
997 FuncInfo->MBB = ClauseBB;
998 FuncInfo->InsertPt = ClauseBB->end();
999 unsigned VReg = SDB->visitLandingPadClauseBB(ClauseGV, MBB);
1000 CurDAG->setRoot(SDB->getRoot());
1001 SDB->clear();
1002 CodeGenAndEmitDAG();
1003
1004 // Add the typeid virtual register to the phi in the main landing pad.
1005 SelectorPHI.addReg(VReg).addMBB(ClauseBB);
1006 }
1007957 }
1008958
1009959 // Remove the edge from the invoke to the lpad.
1010960 for (MachineBasicBlock *InvokeBB : InvokeBBs)
1011961 InvokeBB->removeSuccessor(MBB);
1012
1013 // Restore FuncInfo back to its previous state and select the main landing
1014 // pad block.
1015 FuncInfo->MBB = MBB;
1016 FuncInfo->InsertPt = MBB->end();
1017962
1018963 // Transfer EH state number assigned to the IR block to the MBB.
1019964 if (Personality == EHPersonality::MSVC_CXX) {
1021966 MF->getMMI().addWinEHState(MBB, FI.LandingPadStateMap[LPadInst]);
1022967 }
1023968
1024 // Select instructions for the landingpad if there was no llvm.eh.actions
1025 // call.
1026 return ActionsCall == nullptr;
969 // Don't select instructions for the landingpad.
970 return false;
1027971 }
1028972
1029973 // Mark exception register as live in.
322322 return new WinEHPrepare(TM);
323323 }
324324
325 // FIXME: Remove this once the backend can handle the prepared IR.
326 static cl::opt
327 SEHPrepare("sehprepare", cl::Hidden,
328 cl::desc("Prepare functions with SEH personalities"));
329
330325 bool WinEHPrepare::runOnFunction(Function &Fn) {
331326 // No need to prepare outlined handlers.
332327 if (Fn.hasFnAttribute("wineh-parent"))
353348 return false;
354349
355350 DT = &getAnalysis().getDomTree();
356
357 if (isAsynchronousEHPersonality(Personality) && !SEHPrepare) {
358 // Replace all resume instructions with unreachable.
359 // FIXME: Remove this once the backend can handle the prepared IR.
360 for (ResumeInst *Resume : Resumes) {
361 IRBuilder<>(Resume).CreateUnreachable();
362 Resume->eraseFromParent();
363 }
364 return true;
365 }
366351
367352 // If there were any landing pads, prepareExceptionHandlers will make changes.
368353 prepareExceptionHandlers(Fn, LPads);
None ; RUN: opt -S -winehprepare -sehprepare < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare < %s | FileCheck %s
11
22 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-pc-windows-msvc"
None ; RUN: opt -S -winehprepare -sehprepare < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare < %s | FileCheck %s
11
22 ; Check that things work when the mid-level optimizer inlines the finally
33 ; block.
None ; RUN: opt -S -winehprepare -sehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
11
22 ; Test case based on this code:
33 ;
None ; RUN: llc -sehprepare < %s | FileCheck %s
0 ; RUN: llc < %s | FileCheck %s
11
22 ; Test case based on this code:
33 ; extern "C" unsigned long _exception_code();
None ; RUN: opt -S -winehprepare -sehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
11
22 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
33 target triple = "x86_64-pc-windows-msvc"
+0
-175
test/CodeGen/X86/seh-basic.ll less more
None ; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
1
2 define void @two_invoke_merged() {
3 entry:
4 invoke void @try_body()
5 to label %again unwind label %lpad
6
7 again:
8 invoke void @try_body()
9 to label %done unwind label %lpad
10
11 done:
12 ret void
13
14 lpad:
15 %vals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
16 catch i8* bitcast (i32 (i8*, i8*)* @filt0 to i8*)
17 catch i8* bitcast (i32 (i8*, i8*)* @filt1 to i8*)
18 %sel = extractvalue { i8*, i32 } %vals, 1
19 call void @use_selector(i32 %sel)
20 ret void
21 }
22
23 ; Normal path code
24
25 ; CHECK-LABEL: {{^}}two_invoke_merged:
26 ; CHECK: .seh_proc two_invoke_merged
27 ; CHECK: .seh_handler __C_specific_handler, @unwind, @except
28 ; CHECK: .Ltmp0:
29 ; CHECK: callq try_body
30 ; CHECK-NEXT: .Ltmp1:
31 ; CHECK: .Ltmp2:
32 ; CHECK: callq try_body
33 ; CHECK-NEXT: .Ltmp3:
34 ; CHECK: retq
35
36 ; Landing pad code
37
38 ; CHECK: .Ltmp5:
39 ; CHECK: movl $1, %ecx
40 ; CHECK: jmp
41 ; CHECK: .Ltmp6:
42 ; CHECK: movl $2, %ecx
43 ; CHECK: callq use_selector
44
45 ; CHECK: .seh_handlerdata
46 ; CHECK-NEXT: .long 2
47 ; CHECK-NEXT: .long .Ltmp0@IMGREL
48 ; CHECK-NEXT: .long .Ltmp3@IMGREL+1
49 ; CHECK-NEXT: .long filt0@IMGREL
50 ; CHECK-NEXT: .long .Ltmp5@IMGREL
51 ; CHECK-NEXT: .long .Ltmp0@IMGREL
52 ; CHECK-NEXT: .long .Ltmp3@IMGREL+1
53 ; CHECK-NEXT: .long filt1@IMGREL
54 ; CHECK-NEXT: .long .Ltmp6@IMGREL
55 ; CHECK: .text
56 ; CHECK: .seh_endproc
57
58 define void @two_invoke_gap() {
59 entry:
60 invoke void @try_body()
61 to label %again unwind label %lpad
62
63 again:
64 call void @do_nothing_on_unwind()
65 invoke void @try_body()
66 to label %done unwind label %lpad
67
68 done:
69 ret void
70
71 lpad:
72 %vals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
73 catch i8* bitcast (i32 (i8*, i8*)* @filt0 to i8*)
74 %sel = extractvalue { i8*, i32 } %vals, 1
75 call void @use_selector(i32 %sel)
76 ret void
77 }
78
79 ; Normal path code
80
81 ; CHECK-LABEL: {{^}}two_invoke_gap:
82 ; CHECK: .seh_proc two_invoke_gap
83 ; CHECK: .seh_handler __C_specific_handler, @unwind, @except
84 ; CHECK: .Ltmp11:
85 ; CHECK: callq try_body
86 ; CHECK-NEXT: .Ltmp12:
87 ; CHECK: callq do_nothing_on_unwind
88 ; CHECK: .Ltmp13:
89 ; CHECK: callq try_body
90 ; CHECK-NEXT: .Ltmp14:
91 ; CHECK: retq
92
93 ; Landing pad code
94
95 ; CHECK: .Ltmp16:
96 ; CHECK: movl $1, %ecx
97 ; CHECK: callq use_selector
98
99 ; CHECK: .seh_handlerdata
100 ; CHECK-NEXT: .long 2
101 ; CHECK-NEXT: .long .Ltmp11@IMGREL
102 ; CHECK-NEXT: .long .Ltmp12@IMGREL+1
103 ; CHECK-NEXT: .long filt0@IMGREL
104 ; CHECK-NEXT: .long .Ltmp16@IMGREL
105 ; CHECK-NEXT: .long .Ltmp13@IMGREL
106 ; CHECK-NEXT: .long .Ltmp14@IMGREL+1
107 ; CHECK-NEXT: .long filt0@IMGREL
108 ; CHECK-NEXT: .long .Ltmp16@IMGREL
109 ; CHECK: .text
110 ; CHECK: .seh_endproc
111
112 define void @two_invoke_nounwind_gap() {
113 entry:
114 invoke void @try_body()
115 to label %again unwind label %lpad
116
117 again:
118 call void @cannot_unwind()
119 invoke void @try_body()
120 to label %done unwind label %lpad
121
122 done:
123 ret void
124
125 lpad:
126 %vals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
127 catch i8* bitcast (i32 (i8*, i8*)* @filt0 to i8*)
128 %sel = extractvalue { i8*, i32 } %vals, 1
129 call void @use_selector(i32 %sel)
130 ret void
131 }
132
133 ; Normal path code
134
135 ; CHECK-LABEL: {{^}}two_invoke_nounwind_gap:
136 ; CHECK: .seh_proc two_invoke_nounwind_gap
137 ; CHECK: .seh_handler __C_specific_handler, @unwind, @except
138 ; CHECK: .Ltmp21:
139 ; CHECK: callq try_body
140 ; CHECK-NEXT: .Ltmp22:
141 ; CHECK: callq cannot_unwind
142 ; CHECK: .Ltmp23:
143 ; CHECK: callq try_body
144 ; CHECK-NEXT: .Ltmp24:
145 ; CHECK: retq
146
147 ; Landing pad code
148
149 ; CHECK: .Ltmp26:
150 ; CHECK: movl $1, %ecx
151 ; CHECK: callq use_selector
152
153 ; CHECK: .seh_handlerdata
154 ; CHECK-NEXT: .long 1
155 ; CHECK-NEXT: .long .Ltmp21@IMGREL
156 ; CHECK-NEXT: .long .Ltmp24@IMGREL+1
157 ; CHECK-NEXT: .long filt0@IMGREL
158 ; CHECK-NEXT: .long .Ltmp26@IMGREL
159 ; CHECK: .text
160 ; CHECK: .seh_endproc
161
162 declare void @try_body()
163 declare void @do_nothing_on_unwind()
164 declare void @cannot_unwind() nounwind
165 declare void @use_selector(i32)
166
167 declare i32 @filt0(i8* %eh_info, i8* %rsp)
168 declare i32 @filt1(i8* %eh_info, i8* %rsp)
169
170 declare void @handler0()
171 declare void @handler1()
172
173 declare i32 @__C_specific_handler(...)
174 declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
None ; RUN: llc -sehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
21
32 @str = internal unnamed_addr constant [10 x i8] c"recovered\00", align 1
None ; RUN: llc -sehprepare < %s | FileCheck %s
0 ; RUN: llc < %s | FileCheck %s
11
22 ; Test case based on this source:
33 ; int puts(const char*);
None ; RUN: llc -sehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
0 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
11
22 @str_recovered = internal unnamed_addr constant [10 x i8] c"recovered\00", align 1
33
None ; RUN: llc -sehprepare -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
0 ; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
11
22 ; This test case is also intended to be run manually as a complete functional
33 ; test. It should link, print something, and exit zero rather than crashing.
None ; RUN: opt -S -winehprepare -sehprepare -dwarfehprepare -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare -dwarfehprepare -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
11
22 ; FIXME: Add and test outlining here.
33