1 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
2 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
4 declare i32 @__gxx_personality_v0(...)
5 declare void @__cxa_call_unexpected(i8*)
6 declare void @purefn() nounwind readnone
7 declare i32 @read_only() nounwind readonly
8 declare i32 @nounwind_fn() nounwind
13 define i8* @f1() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
15 ; CHECK: call void @llvm.trap()
17 %call = invoke noalias i8* undef()
18 to label %invoke.cont unwind label %lpad
24 %0 = landingpad { i8*, i32 }
25 filter [0 x i8*] zeroinitializer
26 %1 = extractvalue { i8*, i32 } %0, 0
27 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
32 define i8* @f2() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
34 ; CHECK: call void @llvm.trap()
36 %call = invoke noalias i8* null()
37 to label %invoke.cont unwind label %lpad
43 %0 = landingpad { i8*, i32 }
44 filter [0 x i8*] zeroinitializer
45 %1 = extractvalue { i8*, i32 } %0, 0
46 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
50 ; CHECK-LABEL: @f2_no_null_opt(
51 define i8* @f2_no_null_opt() nounwind uwtable ssp #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
53 ; CHECK: invoke noalias i8* null()
54 %call = invoke noalias i8* null()
55 to label %invoke.cont unwind label %lpad
58 ; CHECK: ret i8* %call
63 %0 = landingpad { i8*, i32 }
64 filter [0 x i8*] zeroinitializer
65 %1 = extractvalue { i8*, i32 } %0, 0
66 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
72 define i32 @f3() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
75 ; CHECK-NEXT: ret i32 3
76 %call = invoke i32 @read_only()
77 to label %invoke.cont unwind label %lpad
83 %0 = landingpad { i8*, i32 }
84 filter [0 x i8*] zeroinitializer
85 %1 = extractvalue { i8*, i32 } %0, 0
86 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
91 define i32 @f4() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
94 ; CHECK-NEXT: call i32 @read_only()
95 %call = invoke i32 @read_only()
96 to label %invoke.cont unwind label %lpad
99 ; CHECK-NEXT: ret i32 %call
103 %0 = landingpad { i8*, i32 }
104 filter [0 x i8*] zeroinitializer
105 %1 = extractvalue { i8*, i32 } %0, 0
106 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
111 define i32 @f5(i1 %cond, i8* %a, i8* %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
113 br i1 %cond, label %x, label %y
116 ; CHECK: invoke i32 @fn()
117 %call = invoke i32 @fn()
118 to label %cont unwind label %lpad
121 ; CHECK: call i32 @nounwind_fn()
122 %call2 = invoke i32 @nounwind_fn()
123 to label %cont unwind label %lpad
127 ; CHECK: ret i32 %phi
128 %phi = phi i32 [%call, %x], [%call2, %y]
133 %phi2 = phi i8* [%a, %x], [%b, %y]
134 %0 = landingpad { i8*, i32 }
135 filter [0 x i8*] zeroinitializer
136 ; CHECK: __cxa_call_unexpected(i8* %a)
137 tail call void @__cxa_call_unexpected(i8* %phi2) noreturn nounwind
142 define void @f6() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
144 invoke void @purefn()
145 to label %invoke.cont1 unwind label %lpad
148 %foo = invoke i32 @fn()
149 to label %invoke.cont2 unwind label %lpad
156 %tmp = phi i8* [ null, %invoke.cont1 ], [ null, %entry ]
157 landingpad { i8*, i32 }
162 attributes #0 = { "null-pointer-is-valid"="true" }