File: willreturn.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (164 lines) | stat: -rw-r--r-- 3,816 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
; RUN: opt -function-attrs -S %s | FileCheck %s

define void @mustprogress_readnone() mustprogress {
; CHECK:      Function Attrs: {{.*}} noreturn {{.*}} readnone willreturn
; CHECK-NEXT: define void @mustprogress_readnone()
;
entry:
  br label %while.body

while.body:
  br label %while.body
}

define i32 @mustprogress_load(i32* %ptr) mustprogress {
; CHECK:      Function Attrs: {{.*}} readonly willreturn
; CHECK-NEXT: define i32 @mustprogress_load(
;
entry:
  br label %while.body

while.body:
  %r = load i32, i32* %ptr
  br label %while.body
}

define void @mustprogress_store(i32* %ptr) mustprogress {
; CHECK-NOT: Function Attrs: {{.*}} willreturn
; CHECK: define void @mustprogress_store(
;
entry:
  br label %while.body

while.body:
  store i32 0, i32* %ptr
  br label %while.body
}

declare void @unknown_fn()

define void @mustprogress_call_unknown_fn() mustprogress {
; CHECK-NOT: Function Attrs: {{.*}} willreturn
; CHECK:     define void @mustprogress_call_unknown_fn(
;
  call void @unknown_fn()
  ret void
}

define i32 @mustprogress_call_known_functions(i32* %ptr) mustprogress {
; CHECK:      Function Attrs: {{.*}} readonly willreturn
; CHECK-NEXT: define i32 @mustprogress_call_known_functions(
;
  call void @mustprogress_readnone()
  %r = call i32 @mustprogress_load(i32* %ptr)
  ret i32 %r
}

declare i32 @__gxx_personality_v0(...)

define i64 @mustprogress_mayunwind() mustprogress personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK:      Function Attrs: {{.*}} readnone willreturn
; CHECK-NEXT: define i64 @mustprogress_mayunwind(
;
  %a = invoke i64 @fn_noread()
          to label %A unwind label %B
A:
  ret i64 10

B:
  %val = landingpad { i8*, i32 }
           catch i8* null
  ret i64 0
}

; Function without loops or non-willreturn calls will return.
define void @willreturn_no_loop(i1 %c, i32* %p) {
; CHECK: Function Attrs: mustprogress willreturn
; CHECK-NEXT: define void @willreturn_no_loop(
;
  br i1 %c, label %if, label %else

if:
  load atomic i32, i32* %p seq_cst, align 4
  call void @fn_willreturn()
  br label %end

else:
  store atomic i32 0, i32* %p seq_cst, align 4
  br label %end

end:
  ret void
}

; Calls a function that is not guaranteed to return, not willreturn.
define void @willreturn_non_returning_function(i1 %c, i32* %p) {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define void @willreturn_non_returning_function(
;
  call void @unknown_fn()
  ret void
}

; Infinite loop without mustprogress, will not return.
define void @willreturn_loop() {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define void @willreturn_loop(
;
  br label %loop

loop:
  br label %loop
}

; Finite loop. Could be willreturn but not detected.
; FIXME
define void @willreturn_finite_loop() {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define void @willreturn_finite_loop(
;
entry:
  br label %loop

loop:
  %i = phi i32 [ 0, %entry], [ %i.inc, %loop ]
  %i.inc = add nuw i32 %i, 1
  %c = icmp ne i32 %i.inc, 100
  br i1 %c, label %loop, label %end

end:
  ret void
}

; Infinite recursion without mustprogress, will not return.
define void @willreturn_recursion() {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define void @willreturn_recursion(
;
  tail call void @willreturn_recursion()
  ret void
}

; Irreducible infinite loop, will not return.
define void @willreturn_irreducible(i1 %c) {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define void @willreturn_irreducible(
;
  br i1 %c, label %bb1, label %bb2

bb1:
  br label %bb2

bb2:
  br label %bb1
}

define linkonce i32 @square(i32) {
; CHECK-NOT: Function Attrs: {{.*}}willreturn
; CHECK: define linkonce i32 @square(
    %2 = mul nsw i32 %0, %0
    ret i32 %2
}

declare i64 @fn_noread() readnone
declare void @fn_willreturn() willreturn