[WinEH] Update LCSSA to handle catchswitch with handlers inside and outside a loop
[oota-llvm.git] / test / Transforms / LCSSA / mixed-catch.ll
1 ; RUN: opt -lcssa -S < %s | FileCheck %s
2
3 ; This test is based on the following C++ code:
4 ;
5 ; void f()
6 ; {
7 ;   for (int i=0; i<12; i++) {
8 ;     try {
9 ;       if (i==3)
10 ;         throw i;
11 ;     } catch (int) {
12 ;       continue;
13 ;     } catch (...) { }
14 ;     if (i==3) break;
15 ;   }
16 ; }
17 ;
18 ; The loop info analysis identifies the catch pad for the second catch as being
19 ; outside the loop (because it returns to %for.end) but the associated
20 ; catchswitch block is identified as being inside the loop.  Because of this
21 ; analysis, the LCSSA pass wants to create a PHI node in the catchpad block
22 ; for the catchswitch value, but this is a token, so it can't.
23
24 define void @f() personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
25 entry:
26   %tmp = alloca i32, align 4
27   %i7 = alloca i32, align 4
28   br label %for.cond
29
30 for.cond:                                         ; preds = %for.inc, %entry
31   %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
32   %cmp = icmp slt i32 %i.0, 12
33   br i1 %cmp, label %for.body, label %for.end
34
35 for.body:                                         ; preds = %for.cond
36   %cond = icmp eq i32 %i.0, 3
37   br i1 %cond, label %if.then, label %for.inc
38
39 if.then:                                          ; preds = %for.body
40   store i32 %i.0, i32* %tmp, align 4
41   %tmp1 = bitcast i32* %tmp to i8*
42   invoke void @_CxxThrowException(i8* %tmp1, %eh.ThrowInfo* nonnull @_TI1H) #1
43           to label %unreachable unwind label %catch.dispatch
44
45 catch.dispatch:                                   ; preds = %if.then
46   %tmp2 = catchswitch within none [label %catch, label %catch2] unwind to caller
47
48 catch:                                            ; preds = %catch.dispatch
49   %tmp3 = catchpad within %tmp2 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %i7]
50   catchret from %tmp3 to label %for.inc
51
52 catch2:                                           ; preds = %catch.dispatch
53   %tmp4 = catchpad within %tmp2 [i8* null, i32 64, i8* null]
54   catchret from %tmp4 to label %for.end
55
56 for.inc:                                          ; preds = %catch, %for.body
57   %inc = add nsw i32 %i.0, 1
58   br label %for.cond
59
60 for.end:                                          ; preds = %catch2, %for.cond
61   ret void
62
63 unreachable:                                      ; preds = %if.then
64   unreachable
65 }
66
67 ; CHECK-LABEL: define void @f()
68 ; CHECK: catch2:
69 ; CHECK-NOT: phi
70 ; CHECK:   %tmp4 = catchpad within %tmp2
71 ; CHECK:   catchret from %tmp4 to label %for.end
72
73 %rtti.TypeDescriptor2 = type { i8**, i8*, [3 x i8] }
74 %eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
75 %eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
76 %eh.ThrowInfo = type { i32, i32, i32, i32 }
77
78 $"\01??_R0H@8" = comdat any
79
80 $"_CT??_R0H@84" = comdat any
81
82 $_CTA1H = comdat any
83
84 $_TI1H = comdat any
85
86 @"\01??_7type_info@@6B@" = external constant i8*
87 @"\01??_R0H@8" = linkonce_odr global %rtti.TypeDescriptor2 { i8** @"\01??_7type_info@@6B@", i8* null, [3 x i8] c".H\00" }, comdat
88 @__ImageBase = external constant i8
89 @"_CT??_R0H@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 1, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%rtti.TypeDescriptor2* @"\01??_R0H@8" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
90 @_CTA1H = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableType* @"_CT??_R0H@84" to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
91 @_TI1H = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 0, i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (%eh.CatchableTypeArray.1* @_CTA1H to i64), i64 ptrtoint (i8* @__ImageBase to i64)) to i32) }, section ".xdata", comdat
92
93 declare void @_CxxThrowException(i8*, %eh.ThrowInfo*)
94
95 declare i32 @__CxxFrameHandler3(...)