Skip to content

Commit

Permalink
[SimplifyCFG] Add test for invoke of nounwind non-willreturn function…
Browse files Browse the repository at this point in the history
… (NFC)

Test both the case with and without willreturn attribute.

(cherry picked from commit 1f1de06)
  • Loading branch information
nikic authored and tstellar committed Jun 3, 2022
1 parent 2f0a69c commit 885724c
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions llvm/test/Transforms/SimplifyCFG/invoke.ll
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3

declare i32 @__gxx_personality_v0(...)
declare void @__cxa_call_unexpected(i8*)
declare void @purefn() nounwind readnone
declare i32 @read_only() nounwind readonly
declare void @purefn() nounwind readnone willreturn
declare i32 @readonly() nounwind readonly
declare i32 @readonly_willreturn() nounwind readonly willreturn
declare i32 @nounwind_fn() nounwind
declare i32 @fn()

Expand Down Expand Up @@ -61,7 +62,7 @@ define i8* @f2_no_null_opt() nounwind uwtable ssp #0 personality i8* bitcast (i3
; CHECK-NEXT: [[TMP0:%.*]] = landingpad { i8*, i32 }
; CHECK-NEXT: filter [0 x i8*] zeroinitializer
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue { i8*, i32 } [[TMP0]], 0
; CHECK-NEXT: tail call void @__cxa_call_unexpected(i8* [[TMP1]]) #[[ATTR5:[0-9]+]]
; CHECK-NEXT: tail call void @__cxa_call_unexpected(i8* [[TMP1]]) #[[ATTR6:[0-9]+]]
; CHECK-NEXT: unreachable
;
entry:
Expand All @@ -79,13 +80,13 @@ lpad:
unreachable
}

define i32 @f3() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @f3(
define i32 @invoke_readonly_may_not_return() nounwind personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @invoke_readonly_may_not_return(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i32 3
;
entry:
%call = invoke i32 @read_only()
%call = invoke i32 @readonly()
to label %invoke.cont unwind label %lpad

invoke.cont:
Expand All @@ -99,14 +100,34 @@ lpad:
unreachable
}

define i32 @f4() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @f4(
define i32 @invoke_readonly_willreturn() nounwind personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @invoke_readonly_willreturn(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL:%.*]] = call i32 @read_only()
; CHECK-NEXT: ret i32 3
;
entry:
%call = invoke i32 @readonly_willreturn()
to label %invoke.cont unwind label %lpad

invoke.cont:
ret i32 3

lpad:
%0 = landingpad { i8*, i32 }
filter [0 x i8*] zeroinitializer
%1 = extractvalue { i8*, i32 } %0, 0
tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind
unreachable
}

define i32 @invoke_readonly_willreturn_with_used_retval() nounwind personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @invoke_readonly_willreturn_with_used_retval(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CALL:%.*]] = call i32 @readonly_willreturn()
; CHECK-NEXT: ret i32 [[CALL]]
;
entry:
%call = invoke i32 @read_only()
%call = invoke i32 @readonly_willreturn()
to label %invoke.cont unwind label %lpad

invoke.cont:
Expand Down Expand Up @@ -136,7 +157,7 @@ define i32 @f5(i1 %cond, i8* %a, i8* %b) personality i8* bitcast (i32 (...)* @__
; CHECK: lpad:
; CHECK-NEXT: [[TMP0:%.*]] = landingpad { i8*, i32 }
; CHECK-NEXT: filter [0 x i8*] zeroinitializer
; CHECK-NEXT: tail call void @__cxa_call_unexpected(i8* [[A:%.*]]) #[[ATTR5]]
; CHECK-NEXT: tail call void @__cxa_call_unexpected(i8* [[A:%.*]]) #[[ATTR6]]
; CHECK-NEXT: unreachable
;
entry:
Expand Down

0 comments on commit 885724c

Please sign in to comment.