llvm.org GIT mirror llvm / 4caa75f
[WinEH] Prevent EH state numbering from skipping nested cleanup pads that never return Differential Revision: http://reviews.llvm.org/D17208 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260733 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Kaylor 4 years ago
2 changed file(s) with 94 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
256256 if (auto *InnerCatchSwitch = dyn_cast(UserI))
257257 if (InnerCatchSwitch->getUnwindDest() == CatchSwitch->getUnwindDest())
258258 calculateCXXStateNumbers(FuncInfo, UserI, CatchLow);
259 if (auto *InnerCleanupPad = dyn_cast(UserI))
260 if (getCleanupRetUnwindDest(InnerCleanupPad) ==
261 CatchSwitch->getUnwindDest())
259 if (auto *InnerCleanupPad = dyn_cast(UserI)) {
260 BasicBlock *UnwindDest = getCleanupRetUnwindDest(InnerCleanupPad);
261 // If a nested cleanup pad reports a null unwind destination and the
262 // enclosing catch pad doesn't it must be post-dominated by an
263 // unreachable instruction.
264 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
262265 calculateCXXStateNumbers(FuncInfo, UserI, CatchLow);
266 }
263267 }
264268 }
265269 int CatchHigh = FuncInfo.getLastStateNumber();
359363 if (auto *InnerCatchSwitch = dyn_cast(UserI))
360364 if (InnerCatchSwitch->getUnwindDest() == CatchSwitch->getUnwindDest())
361365 calculateSEHStateNumbers(FuncInfo, UserI, ParentState);
362 if (auto *InnerCleanupPad = dyn_cast(UserI))
363 if (getCleanupRetUnwindDest(InnerCleanupPad) ==
364 CatchSwitch->getUnwindDest())
366 if (auto *InnerCleanupPad = dyn_cast(UserI)) {
367 BasicBlock *UnwindDest = getCleanupRetUnwindDest(InnerCleanupPad);
368 // If a nested cleanup pad reports a null unwind destination and the
369 // enclosing catch pad doesn't it must be post-dominated by an
370 // unreachable instruction.
371 if (!UnwindDest || UnwindDest == CatchSwitch->getUnwindDest())
365372 calculateSEHStateNumbers(FuncInfo, UserI, ParentState);
373 }
366374 }
367375 } else {
368376 auto *CleanupPad = cast(FirstNonPHI);
0 ; RUN: sed -e s/.Cxx:// %s | llc -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefix=CXX
1 ; RUN: sed -e s/.Seh:// %s | llc -mtriple=x86_64-pc-windows-msvc | FileCheck %s --check-prefix=SEH
2
3 declare i32 @__CxxFrameHandler3(...)
4 declare i32 @__C_specific_handler(...)
5 declare void @dummy_filter()
6
7 declare void @f(i32)
8
9 ;Cxx: define void @test() personality i32 (...)* @__CxxFrameHandler3 {
10 ;Seh: define void @test() personality i32 (...)* @__C_specific_handler {
11 entry:
12 invoke void @f(i32 1)
13 to label %invoke.cont unwind label %catch.dispatch
14
15 catch.dispatch:
16 %cs1 = catchswitch within none [label %catch.body] unwind label %catch.dispatch.2
17
18 catch.body:
19 ;Cxx: %catch = catchpad within %cs1 [i8* null, i32 u0x40, i8* null]
20 ;Seh: %catch = catchpad within %cs1 [void ()* @dummy_filter]
21 invoke void @f(i32 2) [ "funclet"(token %catch) ]
22 to label %unreachable unwind label %terminate
23
24 terminate:
25 %cleanup = cleanuppad within %catch []
26 call void @f(i32 3) [ "funclet"(token %cleanup) ]
27 unreachable
28
29 unreachable:
30 unreachable
31
32 invoke.cont:
33 ret void
34
35 catch.dispatch.2:
36 %cs2 = catchswitch within none [label %catch.body.2] unwind to caller
37
38 catch.body.2:
39 ;Cxx: %catch2 = catchpad within %cs2 [i8* null, i32 u0x40, i8* null]
40 ;Seh: %catch2 = catchpad within %cs2 [void ()* @dummy_filter]
41 unreachable
42 }
43
44 ; CXX-LABEL: test:
45 ; CXX-LABEL: $ip2state$test:
46 ; CXX-NEXT: .long .Lfunc_begin0@IMGREL
47 ; CXX-NEXT: .long -1
48 ; CXX-NEXT: .long .Ltmp0@IMGREL+1
49 ; CXX-NEXT: .long 1
50 ; CXX-NEXT: .long .Ltmp1@IMGREL+1
51 ; CXX-NEXT: .long -1
52 ; CXX-NEXT: .long "?catch$3@?0?test@4HA"@IMGREL
53 ; CXX-NEXT: .long 2
54 ; CXX-NEXT: .long .Ltmp2@IMGREL+1
55 ; CXX-NEXT: .long 3
56 ; CXX-NEXT: .long .Ltmp3@IMGREL+1
57 ; CXX-NEXT: .long 2
58 ; CXX-NEXT: .long "?catch$5@?0?test@4HA"@IMGREL
59 ; CXX-NEXT: .long 4
60
61 ; SEH-LABEL: test:
62 ; SEH-LABEL: .Llsda_begin0:
63 ; SEH-NEXT: .long .Ltmp0@IMGREL+1
64 ; SEH-NEXT: .long .Ltmp1@IMGREL+1
65 ; SEH-NEXT: .long dummy_filter@IMGREL
66 ; SEH-NEXT: .long .LBB0_3@IMGREL
67 ; SEH-NEXT: .long .Ltmp0@IMGREL+1
68 ; SEH-NEXT: .long .Ltmp1@IMGREL+1
69 ; SEH-NEXT: .long dummy_filter@IMGREL
70 ; SEH-NEXT: .long .LBB0_5@IMGREL
71 ; SEH-NEXT: .long .Ltmp2@IMGREL+1
72 ; SEH-NEXT: .long .Ltmp3@IMGREL+1
73 ; SEH-NEXT: .long "?dtor$2@?0?test@4HA"@IMGREL
74 ; SEH-NEXT: .long 0
75 ; SEH-NEXT: .long .Ltmp2@IMGREL+1
76 ; SEH-NEXT: .long .Ltmp3@IMGREL+1
77 ; SEH-NEXT: .long dummy_filter@IMGREL
78 ; SEH-NEXT: .long .LBB0_5@IMGREL
79 ; SEH-NEXT: .Llsda_end0: