llvm.org GIT mirror llvm / 66ef931
[WinEH] Pull Adjectives and CatchObj out of the catchpad arg list Clang now passes the adjectives as an argument to catchpad. Getting the CatchObj working is simply a matter of threading another static alloca through codegen, first as an alloca, then as a frame index, and finally as a frame offset. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247844 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
10 changed file(s) with 82 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
138138
139139 struct WinEHHandlerType {
140140 int Adjectives;
141 int CatchObjRecoverIdx;
142 /// The CatchObj starts out life as an LLVM alloca, is turned into a frame
143 /// index, and after PEI, becomes a raw offset.
144 union {
145 const AllocaInst *Alloca;
146 int FrameOffset;
147 int FrameIndex;
148 } CatchObj = {};
141149 GlobalVariable *TypeDescriptor;
142 int CatchObjRecoverIdx;
143150 ValueOrMBB Handler;
144151 };
145152
175182 int EHRegNodeEscapeIndex = INT_MAX;
176183 const AllocaInst *EHRegNode = nullptr;
177184 int EHRegNodeFrameIndex = INT_MAX;
185 int EHRegNodeEndOffset = INT_MAX;
178186
179187 WinEHFuncInfo() {}
180188 };
474474 HT.CatchObjRecoverIdx);
475475 FrameAllocOffsetRef = MCSymbolRefExpr::create(
476476 FrameAllocOffset, MCSymbolRefExpr::VK_None, Asm->OutContext);
477 } else if (HT.CatchObj.FrameOffset != INT_MAX) {
478 int Offset = HT.CatchObj.FrameOffset;
479 // For 32-bit, the catch object offset is relative to the end of the
480 // EH registration node. For 64-bit, it's relative to SP at the end of
481 // the prologue.
482 if (!shouldEmitPersonality) {
483 assert(FuncInfo.EHRegNodeEndOffset != INT_MAX);
484 Offset += FuncInfo.EHRegNodeEndOffset;
485 }
486 FrameAllocOffsetRef = MCConstantExpr::create(Offset, Asm->OutContext);
477487 } else {
478488 FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext);
479489 }
818818 if (FuncInfo.UnwindHelpFrameIdx != INT_MAX)
819819 FuncInfo.UnwindHelpFrameOffset = TFI.getFrameIndexReferenceFromSP(
820820 Fn, FuncInfo.UnwindHelpFrameIdx, FrameReg);
821 for (WinEHTryBlockMapEntry &TBME : FuncInfo.TryBlockMap) {
822 for (WinEHHandlerType &H : TBME.HandlerArray) {
823 unsigned UnusedReg;
824 if (H.CatchObj.FrameIndex == INT_MAX)
825 H.CatchObj.FrameOffset = INT_MAX;
826 else
827 H.CatchObj.FrameOffset =
828 TFI.getFrameIndexReference(Fn, H.CatchObj.FrameIndex, UnusedReg);
829 }
830 }
821831 } else if (MMI.hasWinEHFuncInfo(F)) {
822832 WinEHFuncInfo &FuncInfo = MMI.getWinEHFuncInfo(Fn.getFunction());
823833 auto I = FuncInfo.CatchHandlerParentFrameObjIdx.find(F);
293293 calculateSEHStateNumbers(WinEHParentFn, EHInfo);
294294
295295 // Map all BB references in the WinEH data to MBBs.
296 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap)
297 for (WinEHHandlerType &H : TBME.HandlerArray)
298 if (const auto *BB =
299 dyn_cast(H.Handler.get()))
296 for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
297 for (WinEHHandlerType &H : TBME.HandlerArray) {
298 if (H.CatchObjRecoverIdx == -2 && H.CatchObj.Alloca) {
299 assert(StaticAllocaMap.count(H.CatchObj.Alloca));
300 H.CatchObj.FrameIndex = StaticAllocaMap[H.CatchObj.Alloca];
301 } else {
302 H.CatchObj.FrameIndex = INT_MAX;
303 }
304 if (const auto *BB = dyn_cast(H.Handler.get()))
300305 H.Handler = MBBMap[BB];
306 }
307 }
301308 for (WinEHUnwindMapEntry &UME : EHInfo.UnwindMap)
302309 if (UME.Cleanup)
303310 if (const auto *BB = dyn_cast(UME.Cleanup.get()))
26212621 for (const CatchPadInst *CPI : Handlers) {
26222622 WinEHHandlerType HT;
26232623 Constant *TypeInfo = cast(CPI->getArgOperand(0));
2624 if (TypeInfo->isNullValue()) {
2625 HT.Adjectives = 0x40;
2624 if (TypeInfo->isNullValue())
26262625 HT.TypeDescriptor = nullptr;
2627 } else {
2628 auto *GV = cast(TypeInfo->stripPointerCasts());
2629 // Selectors are always pointers to GlobalVariables with 'struct' type.
2630 // The struct has two fields, adjectives and a type descriptor.
2631 auto *CS = cast(GV->getInitializer());
2632 HT.Adjectives =
2633 cast(CS->getAggregateElement(0U))->getZExtValue();
2634 HT.TypeDescriptor =
2635 cast(CS->getAggregateElement(1)->stripPointerCasts());
2636 }
2626 else
2627 HT.TypeDescriptor = cast(TypeInfo->stripPointerCasts());
2628 HT.Adjectives = cast(CPI->getArgOperand(1))->getZExtValue();
26372629 HT.Handler = CPI->getNormalDest();
2638 // FIXME: Pass CPI->getArgOperand(1).
2639 HT.CatchObjRecoverIdx = -1;
2630 HT.CatchObjRecoverIdx = -2;
2631 if (isa(CPI->getArgOperand(2)))
2632 HT.CatchObj.Alloca = nullptr;
2633 else
2634 HT.CatchObj.Alloca = cast(CPI->getArgOperand(2));
26402635 TBME.HandlerArray.push_back(HT);
26412636 }
26422637 FuncInfo.TryBlockMap.push_back(TBME);
27122707 }
27132708 HT.Handler = cast(CH->getHandlerBlockOrFunc());
27142709 HT.CatchObjRecoverIdx = CH->getExceptionVarIndex();
2710 HT.CatchObj.Alloca = nullptr;
27152711 TBME.HandlerArray.push_back(HT);
27162712 }
27172713 FuncInfo.TryBlockMap.push_back(TBME);
20902090 int EHRegOffset = getFrameIndexReference(MF, FI, UsedReg);
20912091 int EHRegSize = MFI->getObjectSize(FI);
20922092 int EndOffset = -EHRegOffset - EHRegSize;
2093 FuncInfo.EHRegNodeEndOffset = EndOffset;
20932094 assert(EndOffset >= 0 &&
20942095 "end of registration object above normal EBP position!");
20952096 if (UsedReg == FramePtr) {
3636 to label %unreachable.for.entry unwind label %catch.dispatch
3737
3838 catch.dispatch: ; preds = %entry
39 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
39 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
4040
4141 catch: ; preds = %catch.dispatch
4242 ; CHECK: catch:
4646 to label %unreachable unwind label %catch.dispatch.1
4747
4848 catch.dispatch.1: ; preds = %catch
49 %2 = catchpad [i8* null, i8* null] to label %catch.3 unwind label %catchendblock.2
49 %2 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch.3 unwind label %catchendblock.2
5050
5151 catch.3: ; preds = %catch.dispatch.1
5252 ; CHECK: catch.3:
44 %eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
55 %eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
66 %eh.ThrowInfo = type { i32, i8*, i8*, i8* }
7 %eh.CatchHandlerType = type { i32, i8* }
87
98 $"\01??_R0H@8" = comdat any
109
1110 @"\01??_7type_info@@6B@" = external constant i8*
1211 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
13
14 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
15 @llvm.eh.handlertype.H.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
1612
1713 declare i32 @getint()
1814 declare void @useints(...)
3026 to label %try.cont unwind label %catch.dispatch
3127
3228 catch.dispatch: ; preds = %entry
33 %0 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
29 %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i8* null]
3430 to label %catch unwind label %catchendblock
3531
3632 catch:
55 ; int main() {
66 ; try {
77 ; f(1);
8 ; } catch (int) {
9 ; f(2);
8 ; } catch (int e) {
9 ; f(e);
1010 ; } catch (...) {
1111 ; f(3);
1212 ; }
1616 %eh.CatchableType = type { i32, i8*, i32, i32, i32, i32, i8* }
1717 %eh.CatchableTypeArray.1 = type { i32, [1 x %eh.CatchableType*] }
1818 %eh.ThrowInfo = type { i32, i8*, i8*, i8* }
19 %eh.CatchHandlerType = type { i32, i8* }
2019
2120 $"\01??_R0H@8" = comdat any
2221
2322 @"\01??_7type_info@@6B@" = external constant i8*
2423 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
2524
26 @llvm.eh.handlertype.H.0 = private unnamed_addr constant %eh.CatchHandlerType { i32 0, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
27 @llvm.eh.handlertype.H.1 = private unnamed_addr constant %eh.CatchHandlerType { i32 1, i8* bitcast (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i8*) }, section "llvm.metadata"
2825
2926 declare void @f(i32 %p, i32* %l)
3027 declare i32 @__CxxFrameHandler3(...)
3128
3229 define i32 @try_catch_catch() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
3330 entry:
31 %e.addr = alloca i32
3432 %local = alloca i32
3533 invoke void @f(i32 1, i32* %local)
3634 to label %try.cont unwind label %catch.dispatch
3735
3836 catch.dispatch: ; preds = %entry
39 %0 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
37 %0 = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e.addr]
4038 to label %catch unwind label %catch.dispatch.2
4139
4240 catch: ; preds = %catch.dispatch
43 invoke void @f(i32 2, i32* %local)
41 %e = load i32, i32* %e.addr
42 invoke void @f(i32 %e, i32* %local)
4443 to label %invoke.cont.2 unwind label %catchendblock
4544
4645 invoke.cont.2: ; preds = %catch
4746 catchret %0 to label %try.cont
4847
4948 catch.dispatch.2: ; preds = %catch.dispatch
50 %1 = catchpad [%eh.CatchHandlerType* @llvm.eh.handlertype.H.0, i8* null]
49 %1 = catchpad [i8* null, i32 u0x40, i8* null]
5150 to label %catch.2 unwind label %catchendblock
5251
5352 catch.2: ; preds = %catch.dispatch.2
7877 ; X86: pushl %ebp
7978 ; X86: addl $12, %ebp
8079 ; X86: subl $8, %esp
80 ; X86: movl -32(%ebp), %[[e_reg:[a-z]+]]
8181 ; X86: movl $1, -{{[0-9]+}}(%ebp)
8282 ; X86: leal -[[local_offs]](%ebp), %[[addr_reg:[a-z]+]]
8383 ; X86-DAG: movl %[[addr_reg]], 4(%esp)
84 ; X86-DAG: movl $2, (%esp)
84 ; X86-DAG: movl %[[e_reg]], (%esp)
8585 ; X86: calll _f
8686 ; X86: movl $[[contbb]], %eax
8787 ; X86-NEXT: addl $8, %esp
104104
105105 ; X86: L__ehtable$try_catch_catch:
106106 ; X86: $handlerMap$0$try_catch_catch:
107 ; X86: .long 0
108 ; X86: .long "??_R0H@8"
109 ; X86: .long 0
110 ; X86: .long [[catch1bb]]
111 ; X86: .long 0
112 ; X86: .long "??_R0H@8"
113 ; X86: .long 0
114 ; X86: .long [[catch2bb]]
107 ; X86-NEXT: .long 0
108 ; X86-NEXT: .long "??_R0H@8"
109 ; X86-NEXT: .long -20
110 ; X86-NEXT: .long [[catch1bb]]
111 ; X86-NEXT: .long 64
112 ; X86-NEXT: .long 0
113 ; X86-NEXT: .long 0
114 ; X86-NEXT: .long [[catch2bb]]
115115
116116 ; X64-LABEL: try_catch_catch:
117117 ; X64: pushq %rbp
134134 ; X64: movq %rdx, %rbp
135135 ; X64: subq $32, %rsp
136136 ; X64-DAG: leaq -[[local_offs]](%rbp), %rdx
137 ; X64-DAG: movl $2, %ecx
137 ; X64-DAG: movl [[e_addr:[-0-9]+]](%rbp), %ecx
138138 ; X64: callq f
139139 ; X64: leaq [[contbb]](%rip), %rax
140140 ; X64: addq $32, %rsp
157157 ; X64: $handlerMap$0$try_catch_catch:
158158 ; X64: .long 0
159159 ; X64: .long "??_R0H@8"@IMGREL
160 ; X64: .long 0
160 ; FIXME: This should probably be offset from rsp, not rbp.
161 ; X64: .long [[e_addr]]
161162 ; X64: .long [[catch1bb]]@IMGREL
162163 ; X64: .long 56
164 ; X64: .long 64
163165 ; X64: .long 0
164 ; X64: .long "??_R0H@8"@IMGREL
165166 ; X64: .long 0
166167 ; X64: .long [[catch2bb]]@IMGREL
167168 ; X64: .long 56
8585 cleanupret %0 unwind label %catch.dispatch
8686
8787 catch.dispatch: ; preds = %ehcleanup
88 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
88 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
8989
9090 catch: ; preds = %catch.dispatch
9191 catchret %1 to label %catchret.dest
125125 ; CHECK: invoke void @g()
126126 ; CHECK: to label %try.cont unwind label %catch.dispatch
127127 ; CHECK: catch.dispatch:
128 ; CHECK: catchpad [i8* null, i8* null]
128 ; CHECK: catchpad [i8* null, i32 64, i8* null]
129129 ; CHECK-NEXT: to label %catch unwind label %catchendblock
130130 ; CHECK: catch:
131131 ; CHECK: catchret
150150 cleanupret %0 unwind label %catch.dispatch
151151
152152 catch.dispatch: ; preds = %ehcleanup
153 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
153 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
154154
155155 catch: ; preds = %catch.dispatch
156156 catchret %1 to label %catchret.dest
213213 to label %try.cont unwind label %catch.dispatch
214214
215215 catch.dispatch: ; preds = %invoke.cont
216 %0 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
216 %0 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
217217
218218 catch: ; preds = %catch.dispatch
219219 catchret %0 to label %try.cont
328328 cleanupret %0 unwind label %catch.dispatch
329329
330330 catch.dispatch: ; preds = %ehcleanup
331 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
331 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
332332
333333 catch: ; preds = %catch.dispatch
334334 catchret %1 to label %return
394394
395395 catch.dispatch: ; preds = %ehcleanup, %entry
396396 %state.1 = phi i32 [ %state.0, %ehcleanup ], [ 1, %entry ]
397 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
397 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
398398
399399 catch: ; preds = %catch.dispatch
400400 catchret %1 to label %return
459459 cleanupret %0 unwind label %catch.dispatch
460460
461461 catch.dispatch: ; preds = %ehcleanup, %catch.cont
462 %1 = catchpad [i8* null, i8* null] to label %catch unwind label %catchendblock
462 %1 = catchpad [i8* null, i32 u0x40, i8* null] to label %catch unwind label %catchendblock
463463
464464 catch: ; preds = %catch.dispatch
465465 call void @use_x(i32 %x)