xref: /llvm-project/llvm/test/Transforms/Inline/invoke_test-2.ll (revision 151602c7a9935558ca671b35359989b261045db0)
1; Test that if an invoked function is inlined, and if that function cannot
2; throw, that the dead handler is now unreachable.
3
4; RUN: opt < %s  -passes=inline,simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
5
6declare void @might_throw()
7
8define internal i32 @callee() personality ptr @__gxx_personality_v0 {
9enrty:
10  invoke void @might_throw()
11      to label %cont unwind label %exc
12
13cont:
14  ret i32 0
15
16exc:
17  %exn = landingpad {ptr, i32}
18         cleanup
19  ret i32 1
20}
21
22; caller returns true if might_throw throws an exception... callee cannot throw.
23define i32 @caller() personality ptr @__gxx_personality_v0 {
24; CHECK-LABEL: define i32 @caller() personality ptr @__gxx_personality_v0
25enrty:
26  %X = invoke i32 @callee()
27           to label %cont unwind label %UnreachableExceptionHandler
28; CHECK-NOT: @callee
29; CHECK: invoke void @might_throw()
30; CHECK:     to label %[[C:.*]] unwind label %[[E:.*]]
31
32; CHECK: [[E]]:
33; CHECK:   landingpad
34; CHECK:      cleanup
35; CHECK:   br label %[[C]]
36
37cont:
38; CHECK: [[C]]:
39  ret i32 %X
40; CHECK:   %[[PHI:.*]] = phi i32
41; CHECK:   ret i32 %[[PHI]]
42
43UnreachableExceptionHandler:
44; CHECK-NOT: UnreachableExceptionHandler:
45  %exn = landingpad {ptr, i32}
46         cleanup
47  ret i32 -1
48; CHECK-NOT: ret i32 -1
49}
50; CHECK: }
51
52declare i32 @__gxx_personality_v0(...)
53