llvm.org GIT mirror llvm / 405cc64
Re-land r235154-r235156 under the existing -sehprepare flag Keep the old SEH fan-in lowering on by default for now, since projects rely on it. This will make it easy to test this change with a simple flag flip. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235399 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
13 changed file(s) with 422 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
220220 int getArgumentFrameIndex(const Argument *A);
221221
222222 private:
223 void addSEHHandlersForLPads();
224
223225 /// LiveOutRegInfo - Information about live out vregs.
224226 IndexedMap LiveOutRegInfo;
225227 };
5050 // Forward declarations.
5151 class Constant;
5252 class GlobalVariable;
53 class BlockAddress;
5354 class MDNode;
5455 class MMIAddrLabelMap;
5556 class MachineBasicBlock;
5960 class StructType;
6061 struct WinEHFuncInfo;
6162
63 struct SEHHandler {
64 // Filter or finally function. Null indicates a catch-all.
65 const Function *FilterOrFinally;
66
67 // Address of block to recover at. Null for a finally handler.
68 const BlockAddress *RecoverBA;
69 };
70
6271 //===----------------------------------------------------------------------===//
6372 /// LandingPadInfo - This structure is used to retain landing pad info for
6473 /// the current function.
6877 SmallVector BeginLabels; // Labels prior to invoke.
6978 SmallVector EndLabels; // Labels after invoke.
7079 SmallVector ClauseLabels; // Labels for each clause.
80 SmallVector SEHHandlers; // SEH handlers active at this lpad.
7181 MCSymbol *LandingPadLabel; // Label at beginning of landing pad.
7282 const Function *Personality; // Personality function.
7383 std::vector TypeIds; // List of type ids (filters negative).
355365 /// each clause gets its own basic block.
356366 MCSymbol *addClauseForLandingPad(MachineBasicBlock *LandingPad);
357367
368 void addSEHCatchHandler(MachineBasicBlock *LandingPad, const Function *Filter,
369 const BlockAddress *RecoverLabel);
370
371 void addSEHCleanupHandler(MachineBasicBlock *LandingPad,
372 const Function *Cleanup);
373
358374 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
359375 /// function wide.
360376 unsigned getTypeIDFor(const GlobalValue *TI);
259259 SDNode *MorphNode(SDNode *Node, unsigned TargetOpc, SDVTList VTs,
260260 ArrayRef Ops, unsigned EmitNodeInfo);
261261
262 void PrepareEHLandingPad();
262 /// Prepares the landing pad to take incoming values or do other EH
263 /// personality specific tasks. Returns true if the block should be
264 /// instruction selected, false if no code should be emitted for it.
265 bool PrepareEHLandingPad();
263266
264267 /// \brief Perform instruction selection on all basic blocks in the function.
265268 void SelectAllBasicBlocks(const Function &Fn);
211211 if (isCatchEHSelector(Selector))
212212 ++NumEntries;
213213 }
214 NumEntries += CSE.LPad->SEHHandlers.size();
214215 }
215216 Asm->OutStreamer.EmitIntValue(NumEntries, 4);
217
218 // If there are no actions, we don't need to iterate again.
219 if (NumEntries == 0)
220 return;
216221
217222 // Emit the four-label records for each call site entry. The table has to be
218223 // sorted in layout order, and the call sites should already be sorted.
238243 } else {
239244 End = createImageRel32(EHFuncEndSym);
240245 }
246
247 // Emit an entry for each action.
248 for (SEHHandler Handler : LPad->SEHHandlers) {
249 Asm->OutStreamer.EmitValue(Begin, 4);
250 Asm->OutStreamer.EmitValue(End, 4);
251
252 // Emit the filter or finally function pointer, if present. Otherwise,
253 // emit '1' to indicate a catch-all.
254 const Function *F = Handler.FilterOrFinally;
255 if (F)
256 Asm->OutStreamer.EmitValue(createImageRel32(Asm->getSymbol(F)), 4);
257 else
258 Asm->OutStreamer.EmitIntValue(1, 4);
259
260 // Emit the recovery address, if present. Otherwise, this must be a
261 // finally.
262 const BlockAddress *BA = Handler.RecoverBA;
263 if (BA)
264 Asm->OutStreamer.EmitValue(
265 createImageRel32(Asm->GetBlockAddressSymbol(BA)), 4);
266 else
267 Asm->OutStreamer.EmitIntValue(0, 4);
268 }
269 if (!LPad->SEHHandlers.empty())
270 continue;
241271
242272 // These aren't really type info globals, they are actually pointers to
243273 // filter functions ordered by selector. The zero selector is used for
468468 return ClauseLabel;
469469 }
470470
471 void MachineModuleInfo::addSEHCatchHandler(MachineBasicBlock *LandingPad,
472 const Function *Filter,
473 const BlockAddress *RecoverBA) {
474 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
475 SEHHandler Handler;
476 Handler.FilterOrFinally = Filter;
477 Handler.RecoverBA = RecoverBA;
478 LP.SEHHandlers.push_back(Handler);
479 }
480
481 void MachineModuleInfo::addSEHCleanupHandler(MachineBasicBlock *LandingPad,
482 const Function *Cleanup) {
483 LandingPadInfo &LP = getOrCreateLandingPadInfo(LandingPad);
484 SEHHandler Handler;
485 Handler.FilterOrFinally = Cleanup;
486 Handler.RecoverBA = nullptr;
487 LP.SEHHandlers.push_back(Handler);
488 }
489
471490 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
472491 /// pads.
473492 void MachineModuleInfo::TidyLandingPads(DenseMap *LPMap) {
269269 }
270270
271271 // Mark landing pad blocks.
272 for (BB = Fn->begin(); BB != EB; ++BB)
272 const LandingPadInst *LP = nullptr;
273 for (BB = Fn->begin(); BB != EB; ++BB) {
273274 if (const auto *Invoke = dyn_cast(BB->getTerminator()))
274275 MBBMap[Invoke->getSuccessor(1)]->setIsLandingPad();
275
276 // Calculate EH numbers for WinEH.
277 if (fn.hasFnAttribute("wineh-parent")) {
276 if (BB->isLandingPad())
277 LP = BB->getLandingPadInst();
278 }
279
280 // Calculate EH numbers for MSVC C++ EH and save SEH handlers if necessary.
281 EHPersonality Personality = EHPersonality::Unknown;
282 if (LP)
283 Personality = classifyEHPersonality(LP->getPersonalityFn());
284 if (Personality == EHPersonality::MSVC_Win64SEH) {
285 addSEHHandlersForLPads();
286 } else if (Personality == EHPersonality::MSVC_CXX) {
278287 const Function *WinEHParentFn = MMI.getWinEHParent(&fn);
279288 WinEHFuncInfo &FI = MMI.getWinEHFuncInfo(WinEHParentFn);
280289 if (FI.LandingPadStateMap.empty()) {
283292 // Pop everything on the handler stack.
284293 Num.processCallSite(None, ImmutableCallSite());
285294 }
295 }
296 }
297
298 void FunctionLoweringInfo::addSEHHandlersForLPads() {
299 MachineModuleInfo &MMI = MF->getMMI();
300
301 // Iterate over all landing pads with llvm.eh.actions calls.
302 for (const BasicBlock &BB : *Fn) {
303 const LandingPadInst *LP = BB.getLandingPadInst();
304 if (!LP)
305 continue;
306 const IntrinsicInst *ActionsCall =
307 dyn_cast(LP->getNextNode());
308 if (!ActionsCall ||
309 ActionsCall->getIntrinsicID() != Intrinsic::eh_actions)
310 continue;
311
312 // Parse the llvm.eh.actions call we found.
313 MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()];
314 SmallVector Actions;
315 parseEHActions(ActionsCall, Actions);
316
317 // Iterate EH actions from most to least precedence, which means
318 // iterating in reverse.
319 for (auto I = Actions.rbegin(), E = Actions.rend(); I != E; ++I) {
320 ActionHandler *Action = *I;
321 if (auto *CH = dyn_cast(Action)) {
322 const auto *Filter =
323 dyn_cast(CH->getSelector()->stripPointerCasts());
324 assert((Filter || CH->getSelector()->isNullValue()) &&
325 "expected function or catch-all");
326 const auto *RecoverBA =
327 cast(CH->getHandlerBlockOrFunc());
328 MMI.addSEHCatchHandler(LPadMBB, Filter, RecoverBA);
329 } else {
330 assert(isa(Action));
331 const auto *Fini = cast(Action->getHandlerBlockOrFunc());
332 MMI.addSEHCleanupHandler(LPadMBB, Fini);
333 }
334 }
335 DeleteContainerPointers(Actions);
286336 }
287337 }
288338
910910
911911 /// PrepareEHLandingPad - Emit an EH_LABEL, set up live-in registers, and
912912 /// do other setup for EH landing-pad blocks.
913 void SelectionDAGISel::PrepareEHLandingPad() {
913 bool SelectionDAGISel::PrepareEHLandingPad() {
914914 MachineBasicBlock *MBB = FuncInfo->MBB;
915915
916916 const TargetRegisterClass *PtrRC = TLI->getRegClassFor(TLI->getPointerTy());
936936
937937 if (isMSVCEHPersonality(Personality)) {
938938 SmallVector ClauseBBs;
939 const IntrinsicInst *Actions =
939 const IntrinsicInst *ActionsCall =
940940 dyn_cast(LLVMBB->getFirstInsertionPt());
941941 // Get all invoke BBs that unwind to this landingpad.
942942 SmallVector InvokeBBs(MBB->pred_begin(),
943943 MBB->pred_end());
944 if (Actions && Actions->getIntrinsicID() == Intrinsic::eh_actions) {
944 if (ActionsCall && ActionsCall->getIntrinsicID() == Intrinsic::eh_actions) {
945945 // If this is a call to llvm.eh.actions followed by indirectbr, then we've
946946 // run WinEHPrepare, and we should remove this block from the machine CFG.
947947 // Mark the targets of the indirectbr as landingpads instead.
950950 // Add the edge from the invoke to the clause.
951951 for (MachineBasicBlock *InvokeBB : InvokeBBs)
952952 InvokeBB->addSuccessor(ClauseBB);
953
954 // Mark the clause as a landing pad or MI passes will delete it.
955 ClauseBB->setIsLandingPad();
953956 }
954957 } else {
955958 // Otherwise, we haven't done the preparation, and we need to invent some
956959 // clause basic blocks that branch into the landingpad.
957960 // FIXME: Remove this code once SEH preparation works.
961 ActionsCall = nullptr;
958962
959963 // Make virtual registers and a series of labels that fill in values for
960964 // the clauses.
10161020 WinEHFuncInfo &FI = MF->getMMI().getWinEHFuncInfo(MF->getFunction());
10171021 MF->getMMI().addWinEHState(MBB, FI.LandingPadStateMap[LPadInst]);
10181022 }
1019 return;
1023
1024 // Select instructions for the landingpad if there was no llvm.eh.actions
1025 // call.
1026 return ActionsCall == nullptr;
10201027 }
10211028
10221029 // Mark exception register as live in.
10261033 // Mark exception selector register as live in.
10271034 if (unsigned Reg = TLI->getExceptionSelectorRegister())
10281035 FuncInfo->ExceptionSelectorVirtReg = MBB->addLiveIn(Reg, PtrRC);
1036
1037 return true;
10291038 }
10301039
10311040 /// isFoldedOrDeadInstruction - Return true if the specified instruction is
11961205 FuncInfo->ExceptionPointerVirtReg = 0;
11971206 FuncInfo->ExceptionSelectorVirtReg = 0;
11981207 if (LLVMBB->isLandingPad())
1199 PrepareEHLandingPad();
1208 if (!PrepareEHLandingPad())
1209 continue;
12001210
12011211 // Before doing SelectionDAG ISel, see if FastISel has been requested.
12021212 if (FastIS) {
0 ; RUN: llc -sehprepare < %s | FileCheck %s
1
2 ; Test case based on this code:
3 ; extern "C" unsigned long _exception_code();
4 ; extern "C" int filt(unsigned long);
5 ; extern "C" void g();
6 ; extern "C" void do_except() {
7 ; __try {
8 ; g();
9 ; } __except(filt(_exception_code())) {
10 ; }
11 ; }
12
13 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
14 target triple = "x86_64-pc-windows-msvc"
15
16 ; Function Attrs: uwtable
17 define void @do_except() #0 {
18 entry:
19 call void (...) @llvm.frameescape()
20 invoke void @g() #5
21 to label %__try.cont unwind label %lpad1
22
23 lpad1: ; preds = %entry
24 %ehvals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
25 catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@do_except@@" to i8*)
26 %recover = call i8* (...) @llvm.eh.actions(i32 1, i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@do_except@@" to i8*), i32 -1, i8* blockaddress(@do_except, %__try.cont))
27 indirectbr i8* %recover, [label %__try.cont]
28
29 __try.cont: ; preds = %lpad1, %entry
30 ret void
31 }
32
33 ; CHECK-LABEL: do_except:
34 ; CHECK: .seh_handler __C_specific_handler
35 ; CHECK-NOT: jmpq *
36 ; CHECK: .seh_handlerdata
37 ; CHECK-NEXT: .long 1
38 ; CHECK-NEXT: .long .Ltmp{{.*}}
39 ; CHECK-NEXT: .long .Ltmp{{.*}}
40 ; CHECK-NEXT: .long "?filt$0@0@do_except@@"@IMGREL
41 ; CHECK-NEXT: .long .Ltmp{{.*}}@IMGREL
42
43 ; Function Attrs: noinline nounwind
44 define internal i32 @"\01?filt$0@0@do_except@@"(i8* nocapture readonly %exception_pointers, i8* nocapture readnone %frame_pointer) #1 {
45 entry:
46 %0 = bitcast i8* %exception_pointers to i32**
47 %1 = load i32*, i32** %0, align 8
48 %2 = load i32, i32* %1, align 4
49 %call = tail call i32 @filt(i32 %2) #4
50 ret i32 %call
51 }
52
53 declare i32 @filt(i32) #2
54
55 declare void @g() #2
56
57 declare i32 @__C_specific_handler(...)
58
59 ; Function Attrs: nounwind readnone
60 declare i32 @llvm.eh.typeid.for(i8*) #3
61
62 ; Function Attrs: nounwind
63 declare i8* @llvm.eh.actions(...) #4
64
65 ; Function Attrs: nounwind
66 declare void @llvm.frameescape(...) #4
67
68 ; Function Attrs: nounwind readnone
69 declare i8* @llvm.framerecover(i8*, i8*, i32) #3
70
71 attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" "wineh-parent"="do_except" }
72 attributes #1 = { noinline nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
73 attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
74 attributes #3 = { nounwind readnone }
75 attributes #4 = { nounwind }
76 attributes #5 = { noinline }
77
78 !llvm.module.flags = !{!0}
79 !llvm.ident = !{!1}
80
81 !0 = !{i32 1, !"PIC Level", i32 2}
82 !1 = !{!"clang version 3.7.0 "}
0 ; RUN: llc -sehprepare -mtriple=x86_64-windows-msvc < %s | FileCheck %s
1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
12
23 @str = internal unnamed_addr constant [10 x i8] c"recovered\00", align 1
0 ; RUN: llc -sehprepare < %s | FileCheck %s
1
2 ; Test case based on this source:
3 ; int puts(const char*);
4 ; __declspec(noinline) void crash() {
5 ; *(volatile int*)0 = 42;
6 ; }
7 ; int filt();
8 ; void use_both() {
9 ; __try {
10 ; __try {
11 ; crash();
12 ; } __finally {
13 ; puts("__finally");
14 ; }
15 ; } __except (filt()) {
16 ; puts("__except");
17 ; }
18 ; }
19
20 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
21 target triple = "x86_64-pc-windows-msvc"
22
23 $"\01??_C@_09KJEHOMHG@__finally?$AA@" = comdat any
24
25 $"\01??_C@_08MLCMLGHM@__except?$AA@" = comdat any
26
27 @"\01??_C@_09KJEHOMHG@__finally?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"__finally\00", comdat, align 1
28 @"\01??_C@_08MLCMLGHM@__except?$AA@" = linkonce_odr unnamed_addr constant [9 x i8] c"__except\00", comdat, align 1
29
30 declare void @crash()
31
32 declare i32 @filt()
33
34 ; Function Attrs: nounwind uwtable
35 define void @use_both() #1 {
36 entry:
37 %exn.slot = alloca i8*
38 %ehselector.slot = alloca i32
39 invoke void @crash() #5
40 to label %invoke.cont unwind label %lpad
41
42 invoke.cont: ; preds = %entry
43 %0 = call i8* @llvm.frameaddress(i32 0)
44 invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext false, i8* %0) #5
45 to label %invoke.cont2 unwind label %lpad1
46
47 invoke.cont2: ; preds = %invoke.cont
48 br label %__try.cont
49
50 lpad: ; preds = %entry
51 %1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
52 cleanup
53 catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_both@@" to i8*)
54 %2 = extractvalue { i8*, i32 } %1, 0
55 store i8* %2, i8** %exn.slot
56 %3 = extractvalue { i8*, i32 } %1, 1
57 store i32 %3, i32* %ehselector.slot
58 %4 = call i8* @llvm.frameaddress(i32 0)
59 invoke void @"\01?fin$0@0@use_both@@"(i1 zeroext true, i8* %4) #5
60 to label %invoke.cont3 unwind label %lpad1
61
62 lpad1: ; preds = %lpad, %invoke.cont
63 %5 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*)
64 catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_both@@" to i8*)
65 %6 = extractvalue { i8*, i32 } %5, 0
66 store i8* %6, i8** %exn.slot
67 %7 = extractvalue { i8*, i32 } %5, 1
68 store i32 %7, i32* %ehselector.slot
69 br label %catch.dispatch
70
71 invoke.cont3: ; preds = %lpad
72 br label %catch.dispatch
73
74 catch.dispatch: ; preds = %invoke.cont3, %lpad1
75 %sel = load i32, i32* %ehselector.slot
76 %8 = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@use_both@@" to i8*)) #6
77 %matches = icmp eq i32 %sel, %8
78 br i1 %matches, label %__except, label %eh.resume
79
80 __except: ; preds = %catch.dispatch
81 %call = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @"\01??_C@_08MLCMLGHM@__except?$AA@", i32 0, i32 0))
82 br label %__try.cont
83
84 __try.cont: ; preds = %__except, %invoke.cont2
85 ret void
86
87 eh.resume: ; preds = %catch.dispatch
88 %exn = load i8*, i8** %exn.slot
89 %sel4 = load i32, i32* %ehselector.slot
90 %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
91 %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel4, 1
92 resume { i8*, i32 } %lpad.val5
93 }
94
95 ; CHECK-LABEL: use_both:
96 ; CHECK: .Ltmp0
97 ; CHECK: callq crash
98 ; CHECK: .Ltmp1
99 ; CHECK: .Ltmp3
100 ; CHECK: callq "?fin$0@0@use_both@@"
101 ; CHECK: .Ltmp4
102 ; CHECK: retq
103 ;
104 ; CHECK: .seh_handlerdata
105 ; CHECK-NEXT: .long 3
106 ; CHECK-NEXT: .long .Ltmp0@IMGREL
107 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
108 ; CHECK-NEXT: .long "?fin$0@0@use_both@@"@IMGREL
109 ; CHECK-NEXT: .long 0
110 ; CHECK-NEXT: .long .Ltmp0@IMGREL
111 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
112 ; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
113 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
114 ; CHECK-NEXT: .long .Ltmp3@IMGREL
115 ; CHECK-NEXT: .long .Ltmp4@IMGREL+1
116 ; CHECK-NEXT: .long "?filt$0@0@use_both@@"@IMGREL
117 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}@IMGREL
118
119 ; Function Attrs: noinline nounwind
120 define internal i32 @"\01?filt$0@0@use_both@@"(i8* %exception_pointers, i8* %frame_pointer) #2 {
121 entry:
122 %frame_pointer.addr = alloca i8*, align 8
123 %exception_pointers.addr = alloca i8*, align 8
124 %exn.slot = alloca i8*
125 store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
126 store i8* %exception_pointers, i8** %exception_pointers.addr, align 8
127 %0 = load i8*, i8** %exception_pointers.addr
128 %1 = bitcast i8* %0 to { i32*, i8* }*
129 %2 = getelementptr inbounds { i32*, i8* }, { i32*, i8* }* %1, i32 0, i32 0
130 %3 = load i32*, i32** %2
131 %4 = load i32, i32* %3
132 %5 = zext i32 %4 to i64
133 %6 = inttoptr i64 %5 to i8*
134 store i8* %6, i8** %exn.slot
135 %call = call i32 @filt()
136 ret i32 %call
137 }
138
139 define internal void @"\01?fin$0@0@use_both@@"(i1 zeroext %abnormal_termination, i8* %frame_pointer) #3 {
140 entry:
141 %frame_pointer.addr = alloca i8*, align 8
142 %abnormal_termination.addr = alloca i8, align 1
143 store i8* %frame_pointer, i8** %frame_pointer.addr, align 8
144 %frombool = zext i1 %abnormal_termination to i8
145 store i8 %frombool, i8* %abnormal_termination.addr, align 1
146 %call = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09KJEHOMHG@__finally?$AA@", i32 0, i32 0))
147 ret void
148 }
149
150 declare i32 @puts(i8*) #3
151
152 declare i32 @__C_specific_handler(...)
153
154 ; Function Attrs: nounwind readnone
155 declare i8* @llvm.frameaddress(i32) #4
156
157 ; Function Attrs: nounwind readnone
158 declare i32 @llvm.eh.typeid.for(i8*) #4
159
160 attributes #0 = { noinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
161 attributes #1 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
162 attributes #2 = { noinline nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
163 attributes #3 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "unsafe-fp-math"="false" "use-soft-float"="false" }
164 attributes #4 = { nounwind readnone }
165 attributes #5 = { noinline }
166 attributes #6 = { nounwind }
None ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
0 ; RUN: llc -sehprepare -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
3131 unreachable
3232 }
3333
34 ; CHECK: main:
34 ; CHECK-LABEL: main:
35 ; CHECK: .seh_handlerdata
36 ; CHECK-NEXT: .long 1
37 ; CHECK-NEXT: .long .Ltmp0@IMGREL
38 ; CHECK-NEXT: .long .Ltmp1@IMGREL
39 ; CHECK-NEXT: .long main.cleanup@IMGREL
40 ; CHECK-NEXT: .long 0
3541
36 ; FIXME: No handlers yet!
37 ; CHECK: .seh_handlerdata
38 ; CHECK-NEXT: .long 0
42 ; CHECK-LABEL: main.cleanup:
43 ; CHECK: callq puts
44 ; CHECK: retq
3945
4046 declare i32 @__C_specific_handler(...)
4147
None ; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
0 ; RUN: llc -sehprepare -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.
7070 ; CHECK: leaq [[rloc:.*\(%rsp\)]], %rcx
7171 ; CHECK: callq try_body
7272 ; CHECK-NEXT: .Ltmp1
73 ; CHECK: .LBB0_7:
73 ; CHECK: [[cont_bb:\.LBB0_[0-9]+]]:
7474 ; CHECK: movl [[rloc]], %eax
7575 ; CHECK: retq
7676
7777 ; Landing pad code
7878
79 ; CHECK: .Ltmp3:
80 ; CHECK: movl $1, %[[sel:[a-z]+]]
81 ; CHECK: .Ltmp4
82 ; CHECK: movl $2, %[[sel]]
83 ; CHECK: .L{{.*}}:
84 ; CHECK: cmpl $1, %[[sel]]
85
79 ; CHECK: [[handler0:\.Ltmp[0-9]+]]: # Block address taken
8680 ; CHECK: # %handler0
8781 ; CHECK: callq puts
8882 ; CHECK: movl $-1, [[rloc]]
89 ; CHECK: jmp .LBB0_7
83 ; CHECK: jmp [[cont_bb]]
9084
91 ; CHECK: cmpl $2, %[[sel]]
92
85 ; CHECK: [[handler1:\.Ltmp[0-9]+]]: # Block address taken
9386 ; CHECK: # %handler1
9487 ; CHECK: callq puts
9588 ; CHECK: movl $-2, [[rloc]]
96 ; CHECK: jmp .LBB0_7
97
98 ; FIXME: EH preparation should eliminate the 'resume' instr and we should not do
99 ; the previous 'cmp;jeq'.
100 ; CHECK-NOT: _Unwind_Resume
101 ; CHECK: ud2
89 ; CHECK: jmp [[cont_bb]]
10290
10391 ; CHECK: .seh_handlerdata
104 ; CHECK: .long 2
105 ; CHECK: .long .Ltmp0@IMGREL
106 ; CHECK: .long .Ltmp1@IMGREL+1
107 ; CHECK: .long safe_div_filt0@IMGREL
108 ; CHECK: .long .Ltmp3@IMGREL
109 ; CHECK: .long .Ltmp0@IMGREL
110 ; CHECK: .long .Ltmp1@IMGREL+1
111 ; CHECK: .long safe_div_filt1@IMGREL
112 ; CHECK: .long .Ltmp4@IMGREL
92 ; CHECK-NEXT: .long 2
93 ; CHECK-NEXT: .long .Ltmp0@IMGREL
94 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
95 ; CHECK-NEXT: .long safe_div_filt0@IMGREL
96 ; CHECK-NEXT: .long [[handler0]]@IMGREL
97 ; CHECK-NEXT: .long .Ltmp0@IMGREL
98 ; CHECK-NEXT: .long .Ltmp1@IMGREL+1
99 ; CHECK-NEXT: .long safe_div_filt1@IMGREL
100 ; CHECK-NEXT: .long [[handler1]]@IMGREL
113101 ; CHECK: .text
114102 ; CHECK: .seh_endproc
115103
184172 ret i32 0
185173 }
186174
187 define void @_Unwind_Resume() {
188 call void @abort()
189 unreachable
190 }
191
192175 declare i32 @__C_specific_handler(...)
193176 declare i32 @llvm.eh.typeid.for(i8*) readnone nounwind
194177 declare void @puts(i8*)
None ; RUN: opt -S -winehprepare -dwarfehprepare -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
0 ; RUN: opt -S -winehprepare -sehprepare -dwarfehprepare -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s
11
22 ; FIXME: Add and test outlining here.
33
4242 ; CHECK-LABEL: define i32 @use_seh()
4343 ; CHECK: invoke void @maybe_throw()
4444 ; CHECK-NEXT: to label %cont unwind label %lpad
45 ; CHECK: eh.resume:
46 ; CHECK-NEXT: unreachable
45 ; CHECK: landingpad
46 ; CHECK-NEXT: cleanup
47 ; CHECK-NEXT: catch
48 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions({{.*}})
4749
4850
4951 ; A MinGW64-ish EH style. It could happen if a binary uses both MSVC CRT and