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