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