1; RUN: opt -mtriple=i386-pc-linux-gnu -inferattrs -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 %s | FileCheck %s
2
3; CHECK-LABEL: Function: test_memcmp_const_size
4; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
5; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
6; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
7; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
8; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
9; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
10define i32 @test_memcmp_const_size(i8* noalias %a, i8* noalias %b) {
11entry:
12  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 4)
13  %a.gep.1 = getelementptr i8, i8* %a, i32 1
14  store i8 0, i8* %a.gep.1
15  %a.gep.5 = getelementptr i8, i8* %a, i32 5
16  store i8 1, i8* %a.gep.5
17  %b.gep.1 = getelementptr i8, i8* %b, i32 1
18  store i8 2, i8* %b.gep.1
19  %b.gep.5 = getelementptr i8, i8* %b, i32 5
20  store i8 3, i8* %b.gep.5
21  ret i32 %res
22}
23
24; CHECK-LABEL: Function: test_memcmp_variable_size
25; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
26; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
27; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
28; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
29; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
30; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
31define i32 @test_memcmp_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
32entry:
33  %res = tail call i32 @memcmp(i8* %a, i8* %b, i64 %n)
34  %a.gep.1 = getelementptr i8, i8* %a, i32 1
35  store i8 0, i8* %a.gep.1
36  %a.gep.5 = getelementptr i8, i8* %a, i32 5
37  store i8 1, i8* %a.gep.5
38  %b.gep.1 = getelementptr i8, i8* %b, i32 1
39  store i8 2, i8* %b.gep.1
40  %b.gep.5 = getelementptr i8, i8* %b, i32 5
41  store i8 3, i8* %b.gep.5
42  ret i32 %res
43}
44
45declare i32 @memcmp(i8*, i8*, i64)
46declare i32 @bcmp(i8*, i8*, i64)
47
48; CHECK-LABEL: Function: test_bcmp_const_size
49; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
50; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
51; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
52; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
53; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
54; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
55define i32 @test_bcmp_const_size(i8* noalias %a, i8* noalias %b) {
56entry:
57  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 4)
58  %a.gep.1 = getelementptr i8, i8* %a, i32 1
59  store i8 0, i8* %a.gep.1
60  %a.gep.5 = getelementptr i8, i8* %a, i32 5
61  store i8 1, i8* %a.gep.5
62  %b.gep.1 = getelementptr i8, i8* %b, i32 1
63  store i8 2, i8* %b.gep.1
64  %b.gep.5 = getelementptr i8, i8* %b, i32 5
65  store i8 3, i8* %b.gep.5
66  ret i32 %res
67}
68
69; CHECK-LABEL: Function: test_bcmp_variable_size
70; CHECK:      Just Ref:  Ptr: i8* %a	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
71; CHECK-NEXT: Just Ref:  Ptr: i8* %b	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
72; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
73; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
74; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
75; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
76define i32 @test_bcmp_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
77entry:
78  %res = tail call i32 @bcmp(i8* %a, i8* %b, i64 %n)
79  %a.gep.1 = getelementptr i8, i8* %a, i32 1
80  store i8 0, i8* %a.gep.1
81  %a.gep.5 = getelementptr i8, i8* %a, i32 5
82  store i8 1, i8* %a.gep.5
83  %b.gep.1 = getelementptr i8, i8* %b, i32 1
84  store i8 2, i8* %b.gep.1
85  %b.gep.5 = getelementptr i8, i8* %b, i32 5
86  store i8 3, i8* %b.gep.5
87  ret i32 %res
88}
89
90declare i8* @memchr(i8*, i32, i64)
91
92; CHECK-LABEL: Function: test_memchr_const_size
93; CHECK: Just Ref:  Ptr: i8* %res      <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
94; CHECK-NEXT: Just Ref:  Ptr: i8* %a.gep.1  <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
95; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5  <->  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
96define i8* @test_memchr_const_size(i8* noalias %a) {
97entry:
98  %res = call i8* @memchr(i8* %a, i32 42, i64 4)
99  %a.gep.1 = getelementptr i8, i8* %a, i32 1
100  store i8 0, i8* %a.gep.1
101  %a.gep.5 = getelementptr i8, i8* %a, i32 5
102  store i8 1, i8* %a.gep.5
103  ret i8* %res
104}
105
106declare i8* @memccpy(i8*, i8*, i32, i64)
107
108; CHECK-LABEL: Function: test_memccpy_const_size
109; CHECK:      Just Mod:  Ptr: i8* %a        <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
110; CHECK-NEXT: Just Ref:  Ptr: i8* %b        <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
111; CHECK-NEXT: Just Mod:  Ptr: i8* %res      <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
112; CHECK-NEXT: Just Mod:  Ptr: i8* %a.gep.1  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
113; CHECK-NEXT: NoModRef:  Ptr: i8* %a.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
114; CHECK-NEXT: Just Ref:  Ptr: i8* %b.gep.1  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
115; CHECK-NEXT: NoModRef:  Ptr: i8* %b.gep.5  <->  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
116
117define i8* @test_memccpy_const_size(i8* noalias %a, i8* noalias %b) {
118entry:
119  %res = call i8* @memccpy(i8* %a, i8* %b, i32 42, i64 4)
120  %a.gep.1 = getelementptr i8, i8* %a, i32 1
121  store i8 0, i8* %a.gep.1
122  %a.gep.5 = getelementptr i8, i8* %a, i32 5
123  store i8 1, i8* %a.gep.5
124  %b.gep.1 = getelementptr i8, i8* %b, i32 1
125  store i8 2, i8* %b.gep.1
126  %b.gep.5 = getelementptr i8, i8* %b, i32 5
127  store i8 3, i8* %b.gep.5
128  ret i8* %res
129}
130
131declare i8* @strcat(i8*, i8*)
132
133define i8* @test_strcat_read_write_after(i8* noalias %a, i8* noalias %b) {
134; CHECK-LABEL: Function: test_strcat_read_write_after
135; CHECK:       NoModRef:  Ptr: i8* %a	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
136; CHECK-NEXT:  NoModRef:  Ptr: i8* %b	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
137; CHECK-NEXT:  Both ModRef:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
138; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
139; CHECK-NEXT:  Both ModRef:  Ptr: i8* %res	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
140; CHECK-NEXT:  Both ModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
141; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
142;
143entry:
144  store i8 0, i8* %a
145  store i8 2, i8* %b
146  %a.gep.1 = getelementptr i8, i8* %a, i32 1
147  %b.gep.1 = getelementptr i8, i8* %b, i32 1
148  %res = tail call i8* @strcat(i8* %a.gep.1, i8* %b.gep.1)
149  %a.gep.5 = getelementptr i8, i8* %a, i32 5
150  store i8 1, i8* %a.gep.5
151  %b.gep.5 = getelementptr i8, i8* %b, i32 5
152  store i8 3, i8* %b.gep.5
153  ret i8* %res
154}
155
156declare i8* @strncat(i8*, i8*, i64)
157
158define i8* @test_strncat_read_write_after(i8* noalias %a, i8* noalias %b, i64 %n) {
159; CHECK-LABEL: Function: test_strncat_read_write_after
160; CHECK:       NoModRef:  Ptr: i8* %a	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
161; CHECK-NEXT:  NoModRef:  Ptr: i8* %b	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
162; CHECK-NEXT:  Both ModRef:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
163; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
164; CHECK-NEXT:  Both ModRef:  Ptr: i8* %res	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
165; CHECK-NEXT:  Both ModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
166; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
167;
168entry:
169  store i8 0, i8* %a
170  store i8 2, i8* %b
171  %a.gep.1 = getelementptr i8, i8* %a, i32 1
172  %b.gep.1 = getelementptr i8, i8* %b, i32 1
173  %res = tail call i8* @strncat(i8* %a.gep.1, i8* %b.gep.1, i64 %n)
174  %a.gep.5 = getelementptr i8, i8* %a, i32 5
175  store i8 1, i8* %a.gep.5
176  %b.gep.5 = getelementptr i8, i8* %b, i32 5
177  store i8 3, i8* %b.gep.5
178  ret i8* %res
179}
180
181declare i8* @strcpy(i8*, i8*)
182
183define i8* @test_strcpy_read_write_after(i8* noalias %a, i8* noalias %b) {
184; CHECK-LABEL: Function: test_strcpy_read_write_after
185; CHECK:       NoModRef:  Ptr: i8* %a	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
186; CHECK-NEXT:  NoModRef:  Ptr: i8* %b	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
187; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
188; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
189; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
190; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
191; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
192;
193entry:
194  store i8 0, i8* %a
195  store i8 2, i8* %b
196  %a.gep.1 = getelementptr i8, i8* %a, i32 1
197  %b.gep.1 = getelementptr i8, i8* %b, i32 1
198  %res = tail call i8* @strcpy(i8* %a.gep.1, i8* %b.gep.1)
199  %a.gep.5 = getelementptr i8, i8* %a, i32 5
200  store i8 1, i8* %a.gep.5
201  %b.gep.5 = getelementptr i8, i8* %b, i32 5
202  store i8 3, i8* %b.gep.5
203  ret i8* %res
204}
205
206declare i8* @strncpy(i8*, i8*, i64)
207
208define i8* @test_strncpy_const_size(i8* noalias %a, i8* noalias %b) {
209; CHECK-LABEL: Function: test_strncpy_const_size
210; CHECK:       Just Mod:  Ptr: i8* %a	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
211; CHECK-NEXT:  Just Ref:  Ptr: i8* %b	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
212; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
213; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
214; CHECK-NEXT:  NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
215; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
216; CHECK-NEXT:  NoModRef:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
217;
218entry:
219  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 4)
220  %a.gep.1 = getelementptr i8, i8* %a, i32 1
221  store i8 0, i8* %a.gep.1
222  %a.gep.5 = getelementptr i8, i8* %a, i32 5
223  store i8 1, i8* %a.gep.5
224  %b.gep.1 = getelementptr i8, i8* %b, i32 1
225  store i8 2, i8* %b.gep.1
226  %b.gep.5 = getelementptr i8, i8* %b, i32 5
227  store i8 3, i8* %b.gep.5
228  ret i8* %res
229}
230
231define i8* @test_strncpy_variable_size(i8* noalias %a, i8* noalias %b, i64 %n) {
232; CHECK-LABEL: Function: test_strncpy_variable_size
233; CHECK:       Just Mod:  Ptr: i8* %a	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
234; CHECK-NEXT:  Just Ref:  Ptr: i8* %b	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
235; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
236; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
237; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
238; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.1	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
239; CHECK-NEXT:  Just Ref:  Ptr: i8* %b.gep.5	<->  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
240;
241entry:
242  %res = tail call i8* @strncpy(i8* %a, i8* %b, i64 %n)
243  %a.gep.1 = getelementptr i8, i8* %a, i32 1
244  store i8 0, i8* %a.gep.1
245  %a.gep.5 = getelementptr i8, i8* %a, i32 5
246  store i8 1, i8* %a.gep.5
247  %b.gep.1 = getelementptr i8, i8* %b, i32 1
248  store i8 2, i8* %b.gep.1
249  %b.gep.5 = getelementptr i8, i8* %b, i32 5
250  store i8 3, i8* %b.gep.5
251  ret i8* %res
252}
253
254declare i8* @__memset_chk(i8* writeonly, i32, i64, i64)
255
256; CHECK-LABEL: Function: test_memset_chk_const_size
257define i8* @test_memset_chk_const_size(i8* noalias %a, i64 %n) {
258; CHECK:       Just Mod (MustAlias):  Ptr: i8* %a	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
259; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
260; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
261; CHECK-NEXT:  NoModRef:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
262;
263entry:
264  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 4, i64 %n)
265  %a.gep.1 = getelementptr i8, i8* %a, i32 1
266  store i8 0, i8* %a.gep.1
267  %a.gep.5 = getelementptr i8, i8* %a, i32 5
268  store i8 1, i8* %a.gep.5
269  ret i8* %res
270}
271
272define i8* @test_memset_chk_variable_size(i8* noalias %a, i64 %n.1, i64 %n.2) {
273; CHECK-LABEL: Function: test_memset_chk_variable_size
274; CHECK:       Just Mod (MustAlias):  Ptr: i8* %a	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
275; CHECK-NEXT:  Just Mod:  Ptr: i8* %res	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
276; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.1	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
277; CHECK-NEXT:  Just Mod:  Ptr: i8* %a.gep.5	<->  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
278;
279entry:
280  %res = tail call i8* @__memset_chk(i8* %a, i32 0, i64 %n.1, i64 %n.2)
281  %a.gep.1 = getelementptr i8, i8* %a, i32 1
282  store i8 0, i8* %a.gep.1
283  %a.gep.5 = getelementptr i8, i8* %a, i32 5
284  store i8 1, i8* %a.gep.5
285  ret i8* %res
286}
287