1; RUN: opt < %s -passes=sroa -S | FileCheck %s
2
3target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4target triple = "wasm32-unknown-unknown"
5
6%struct.foo = type { i32 }
7declare i32 @__gxx_wasm_personality_v0(...)
8declare void @foo()
9
10; Tests if the SROA pass correctly bails out on rewriting PHIs in a catchswitch
11; BB.
12; CHECK-LABEL: @test_phi_catchswitch
13define void @test_phi_catchswitch() personality ptr @__gxx_wasm_personality_v0 {
14entry:
15  ; CHECK: alloca
16  %tmp = alloca %struct.foo, align 4
17  invoke void @foo()
18          to label %bb3 unwind label %bb10
19
20bb3:                                              ; preds = %entry
21  invoke void @foo()
22          to label %bb9 unwind label %catch.dispatch
23
24catch.dispatch:                                   ; preds = %bb3
25  ; While rewriting the alloca in the entry BB, the SROA pass tries to insert a
26  ; non-PHI instruction in this BB by calling getFirstInsertionPt(), which is
27  ; not possible in a catchswitch BB. This test checks if we correctly bail out
28  ; on these cases.
29  %tmp5 = phi ptr [ %tmp, %bb3 ]
30  %tmp6 = catchswitch within none [label %catch.start] unwind label %bb10
31
32catch.start:                                      ; preds = %catch.dispatch
33  %tmp8 = catchpad within %tmp6 [ptr null]
34  unreachable
35
36bb9:                                              ; preds = %bb3
37  unreachable
38
39bb10:                                             ; preds = %catch.dispatch, %entry
40  %tmp11 = phi ptr [ %tmp, %entry ], [ %tmp5, %catch.dispatch ]
41  %tmp12 = cleanuppad within none []
42  store i32 0, ptr %tmp11, align 4
43  unreachable
44}
45