[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / SystemZ / zos-mixed-ptr-sizes.c
blob6194c9b1804fb0b4888744664259515e60f6a402
1 // RUN: %clang_cc1 -triple s390x-ibm-zos -emit-llvm -O2 < %s | FileCheck %s --check-prefix=X64
3 #define PSA_PTR 0x00
4 #define PSAAOLD 0x224
6 struct Foo {
7 int * __ptr32 p32;
8 int *p64;
9 char *cp64;
12 void use_foo(struct Foo *f);
14 void ptr32_to_ptr(struct Foo *f, int * __ptr32 i) {
15 // X64-LABEL: define void @ptr32_to_ptr(ptr noundef %f, ptr addrspace(1) noundef %i)
16 // X64: %{{.+}} = addrspacecast ptr addrspace(1) %i to ptr
17 f->p64= i;
18 use_foo(f);
21 void ptr_to_ptr32(struct Foo *f, int *i) {
22 // X64-LABEL: define void @ptr_to_ptr32(ptr noundef %f, ptr noundef %i)
23 // X64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(1)
24 f->p32 = i;
25 use_foo(f);
28 void ptr32_to_ptr32(struct Foo *f, int * __ptr32 i) {
29 // X64-LABEL: define void @ptr32_to_ptr32(ptr noundef %f, ptr addrspace(1) noundef %i)
30 // X64-NOT: addrspacecast
31 f->p32 = i;
32 use_foo(f);
35 void ptr_to_ptr32_explicit_cast(struct Foo *f, int *i) {
36 // X64-LABEL: define void @ptr_to_ptr32_explicit_cast(ptr noundef %f, ptr noundef %i)
37 // X64: %{{.+}} = addrspacecast ptr %i to ptr addrspace(1)
38 f->p32 = (int * __ptr32)i;
39 use_foo(f);
42 void test_indexing(struct Foo *f) {
43 // X64-LABEL: define void @test_indexing(ptr noundef %f)
44 // X64: addrspacecast ptr addrspace(1) {{%[0-9]}} to ptr
45 f->cp64 = ((char * __ptr32 *)1028)[1];
46 use_foo(f);
49 void test_indexing_2(struct Foo *f) {
50 // X64-LABEL: define void @test_indexing_2(ptr noundef %f)
51 // X64: getelementptr inbounds i8, ptr addrspace(1) {{%[0-9]}}, i32 16
52 // X64: getelementptr inbounds i8, ptr {{%[0-9]}}, i64 24
53 f->cp64 = ((char *** __ptr32 *)1028)[1][2][3];
54 use_foo(f);
57 unsigned long* test_misc() {
58 // X64-LABEL: define ptr @test_misc()
59 // X64: %arrayidx = getelementptr inbounds i8, ptr addrspace(1) %0, i32 88
60 // X64-NEXT: %1 = load ptr, ptr addrspace(1) %arrayidx
61 // X64-NEXT: %arrayidx1 = getelementptr inbounds i8, ptr %1, i64 8
62 // X64-NEXT: %2 = load ptr, ptr %arrayidx1
63 // X64-NEXT: %arrayidx2 = getelementptr inbounds i8, ptr %2, i64 904
64 // X64-NEXT: %3 = load ptr, ptr %arrayidx2
65 // X64-NEXT: %arrayidx3 = getelementptr inbounds i8, ptr %3, i64 1192
66 unsigned long* x = (unsigned long*)((char***** __ptr32*)1208)[0][11][1][113][149];
67 return x;
70 char* __ptr32* __ptr32 test_misc_2() {
71 // X64-LABEL: define ptr addrspace(1) @test_misc_2()
72 // X64: br i1 %cmp, label %if.then, label %if.end
73 // X64: %1 = load ptr addrspace(1), ptr inttoptr (i64 16 to ptr)
74 // X64-NEXT: %arrayidx = getelementptr inbounds i8, ptr addrspace(1) %1, i32 544
75 // X64-NEXT: %2 = load ptr addrspace(1), ptr addrspace(1) %arrayidx
76 // X64-NEXT: %arrayidx1 = getelementptr inbounds i8, ptr addrspace(1) %2, i32 24
77 // X64-NEXT: %3 = load ptr addrspace(1), ptr addrspace(1) %arrayidx1
78 // X64-NEXT: store ptr addrspace(1) %3, ptr @test_misc_2.res
79 // X64: ret ptr addrspace(1)
80 static char* __ptr32* __ptr32 res = 0;
81 if (res == 0) {
82 res = ((char* __ptr32* __ptr32* __ptr32* __ptr32*)0)[4][136][6];
84 return res;
87 unsigned short test_misc_3() {
88 // X64-LABEL: define zeroext i16 @test_misc_3()
89 // X64: %0 = load ptr addrspace(1), ptr inttoptr (i64 548 to ptr)
90 // X64-NEXT: %1 = addrspacecast ptr addrspace(1) %0 to ptr
91 // X64-NEXT: %arrayidx = getelementptr inbounds i8, ptr %1, i64 36
92 // X64-NEXT: %2 = load i16, ptr %arrayidx, align 2
93 // X64-NEXT: ret i16 %2
94 unsigned short this_asid = ((unsigned short*)(*(char* __ptr32*)(0x224)))[18];
95 return this_asid;
98 int test_misc_4() {
99 // X64-LABEL: define signext range(i32 0, 2) i32 @test_misc_4()
100 // X64: getelementptr inbounds i8, ptr addrspace(1) {{%[0-9]}}, i32 88
101 // X64: getelementptr inbounds i8, ptr {{%[0-9]}}, i64 8
102 // X64: getelementptr inbounds i8, ptr {{%[0-9]}}, i64 984
103 // X64: getelementptr inbounds i8, ptr %3, i64 80
104 // X64: icmp sgt i32 {{.*[0-9]}}, 67240703
105 // X64: ret i32
106 int a = (*(int*)(80 + ((char**** __ptr32*)1208)[0][11][1][123]) > 0x040202FF);
107 return a;
110 void test_misc_5(struct Foo *f) {
111 // X64-LABEL: define void @test_misc_5(ptr noundef %f)
112 // X64: addrspacecast ptr addrspace(1) %0 to ptr
113 f->cp64 = *(char* __ptr32 *)(PSA_PTR + PSAAOLD);
114 use_foo(f);
117 int test_misc_6() {
118 // X64-LABEL: define {{.*}} i32 @test_misc_6()
119 // X64: ret i32 8
120 int * __ptr32 ip32;
121 int *ip64;
122 ip64 = ip32;
123 return sizeof(ip64);
126 int test_misc_7() {
127 // X64-LABEL: define {{.*}} i32 @test_misc_7()
128 // X64: ret i32 12
129 int foo = 12;
131 int *ip64;
132 int * __ptr32 ip32;
134 ip64 = &foo;
135 ip32 = (int * __ptr32) ip64;
137 return *ip32;
140 int test_misc_8() {
141 // X64-LABEL: define {{.*}} i32 @test_misc_8()
142 // X64: ret i32 97
143 char foo = 'a';
145 char *cp64;
146 char * __ptr32 cp32;
148 cp64 = &foo;
149 cp32 = (char * __ptr32) cp64;
151 return *cp32;
154 int test_misc_9() {
155 // X64-LABEL: define {{.*}} i32 @test_misc_9()
156 // X64: ret i32 15
157 int foo = 15;
159 int *ip64;
160 int * __ptr32 ip32;
162 ip32 = &foo;
163 ip64 = (int *)ip32;
165 return *ip64;
168 int test_misc_10() {
169 // X64-LABEL: define {{.*}} i32 @test_misc_10()
170 // X64: ret i32 97
171 char foo = 'a';
173 char *cp64;
174 char * __ptr32 cp32;
176 cp32 = &foo;
177 cp64= (char *)cp32;
179 return *cp64;
182 int test_function_ptr32_is_32bit() {
183 // X64-LABEL: define {{.*}} i32 @test_function_ptr32_is_32bit()
184 // X64: ret i32 4
185 int (* __ptr32 a)(int a);
186 return sizeof(a);
189 int get_processor_count() {
190 // X64-LABEL: define signext range(i32 -128, 128) i32 @get_processor_count()
191 // X64: load ptr addrspace(1), ptr inttoptr (i64 16 to ptr)
192 // X64-NEXT: [[ARR_IDX1:%[a-z].*]] = getelementptr inbounds i8, ptr addrspace(1) %0, i32 660
193 // X64: load ptr addrspace(1), ptr addrspace(1) [[ARR_IDX1]]
194 // X64: load i8, ptr addrspace(1) {{%[a-z].*}}
195 // X64: sext i8 {{%[0-9]}} to i32
196 // X64-NEXT: ret i32
197 return ((char * __ptr32 * __ptr32 *)0)[4][165][53];
200 int get_sizes_ptr32() {
201 // X64-LABEL: define {{.*}} i32 @get_sizes_ptr32()
202 // X64: ret i32 72
203 char * __ptr32 a;
204 signed char * __ptr32 b;
205 unsigned char *__ptr32 c;
206 int * __ptr32 d;
207 signed int * __ptr32 e;
208 unsigned int *__ptr32 f;
209 short * __ptr32 g;
210 signed short * __ptr32 h;
211 unsigned short * __ptr32 i;
212 long * __ptr32 j;
213 signed * __ptr32 k;
214 unsigned * __ptr32 l;
215 long long * __ptr32 m;
216 signed long long * __ptr32 n;
217 unsigned long long * __ptr32 o;
218 float * __ptr32 p;
219 double * __ptr32 q;
220 long double * __ptr32 r;
222 int sum = 0;
223 sum += sizeof(a);
224 sum += sizeof(b);
225 sum += sizeof(c);
226 sum += sizeof(d);
227 sum += sizeof(e);
228 sum += sizeof(f);
229 sum += sizeof(g);
230 sum += sizeof(h);
231 sum += sizeof(i);
232 sum += sizeof(j);
233 sum += sizeof(k);
234 sum += sizeof(l);
235 sum += sizeof(m);
236 sum += sizeof(n);
237 sum += sizeof(o);
238 sum += sizeof(p);
239 sum += sizeof(q);
240 sum += sizeof(r);
242 return sum;
245 int get_sizes_p64() {
246 // X64-LABEL: define {{.*}} i32 @get_sizes_p64()
247 // X64: ret i32 144
248 char *a;
249 signed char *b;
250 unsigned char *c;
251 int *d;
252 signed int *e;
253 unsigned int *f;
254 short *g;
255 signed short *h;
256 unsigned short *i;
257 long *j;
258 signed *k;
259 unsigned *l;
260 long long *m;
261 signed long long *n;
262 unsigned long long *o;
263 float *p;
264 double *q;
265 long double *r;
267 int sum = 0;
268 sum += sizeof(a);
269 sum += sizeof(b);
270 sum += sizeof(c);
271 sum += sizeof(d);
272 sum += sizeof(e);
273 sum += sizeof(f);
274 sum += sizeof(g);
275 sum += sizeof(h);
276 sum += sizeof(i);
277 sum += sizeof(j);
278 sum += sizeof(k);
279 sum += sizeof(l);
280 sum += sizeof(m);
281 sum += sizeof(n);
282 sum += sizeof(o);
283 sum += sizeof(p);
284 sum += sizeof(q);
285 sum += sizeof(r);
287 return sum;
291 int host_cpu() {
292 char *__ptr32 CVT = *(char * __ptr32 *__ptr32) 16;
293 unsigned short Id = *(unsigned short *)&CVT[-6];
294 Id = ((((Id >> 12) & 0x0f) * 10 + ((Id >> 8) & 0x0f)) * 10 + ((Id >> 4) & 0x0f)) * 10 + (Id & 0x0f);
295 int HaveVectorSupport = CVT[244] & 0x80;
296 int z13 = (Id >= 2964 && HaveVectorSupport);
297 return z13;