d871e17b6b04959ad2331242edb458158d1d39b4
[oota-llvm.git] / test / Transforms / SimplifyCFG / wineh-unreachable.ll
1 ; RUN: opt -S -simplifycfg < %s | FileCheck %s
2
3 declare void @Personality()
4 declare void @f()
5
6 ; CHECK-LABEL: define void @test1()
7 define void @test1() personality i8* bitcast (void ()* @Personality to i8*) {
8 entry:
9   ; CHECK: call void @f()
10   invoke void @f()
11     to label %exit unwind label %unreachable.unwind
12 exit:
13   ret void
14 unreachable.unwind:
15   cleanuppad within none []
16   unreachable  
17 }
18
19 ; CHECK-LABEL: define void @test2()
20 define void @test2() personality i8* bitcast (void ()* @Personality to i8*) {
21 entry:
22   invoke void @f()
23     to label %exit unwind label %catch.pad
24 catch.pad:
25   %cs1 = catchswitch within none [label %catch.body] unwind label %unreachable.unwind
26   ; CHECK: catch.pad:
27   ; CHECK-NEXT: catchswitch within none [label %catch.body] unwind to caller
28 catch.body:
29   ; CHECK:      catch.body:
30   ; CHECK-NEXT:   catchpad within %cs1
31   ; CHECK-NEXT:   call void @f()
32   ; CHECK-NEXT:   unreachable
33   %catch = catchpad within %cs1 []
34   call void @f()
35   catchret from %catch to label %unreachable
36 exit:
37   ret void
38 unreachable.unwind:
39   cleanuppad within none []
40   unreachable
41 unreachable:
42   unreachable
43 }
44
45 ; CHECK-LABEL: define void @test3()
46 define void @test3() personality i8* bitcast (void ()* @Personality to i8*) {
47 entry:
48   invoke void @f()
49     to label %exit unwind label %cleanup.pad
50 cleanup.pad:
51   ; CHECK: %cleanup = cleanuppad within none []
52   ; CHECK-NEXT: call void @f()
53   ; CHECK-NEXT: unreachable
54   %cleanup = cleanuppad within none []
55   invoke void @f()
56     to label %cleanup.ret unwind label %unreachable.unwind
57 cleanup.ret:
58   ; This cleanupret should be rewritten to unreachable,
59   ; and merged into the pred block.
60   cleanupret from %cleanup unwind label %unreachable.unwind
61 exit:
62   ret void
63 unreachable.unwind:
64   cleanuppad within none []
65   unreachable
66 }
67
68 ; CHECK-LABEL: define void @test5()
69 define void @test5() personality i8* bitcast (void ()* @Personality to i8*) {
70 entry:
71   invoke void @f()
72           to label %exit unwind label %catch.pad
73
74 catch.pad:
75   %cs1 = catchswitch within none [label %catch.body] unwind to caller
76
77 catch.body:
78   %catch = catchpad within %cs1 []
79   catchret from %catch to label %exit
80
81 exit:
82   unreachable
83 }
84
85 ; CHECK-LABEL: define void @test6()
86 define void @test6() personality i8* bitcast (void ()* @Personality to i8*) {
87 entry:
88   invoke void @f()
89           to label %exit unwind label %catch.pad
90
91 catch.pad:
92   %cs1 = catchswitch within none [label %catch.body, label %catch.body] unwind to caller
93   ; CHECK: catchswitch within none [label %catch.body] unwind to caller
94
95 catch.body:
96   %catch = catchpad within %cs1 [i8* null, i32 0, i8* null]
97   catchret from %catch to label %exit
98
99 exit:
100   ret void
101 }