PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / pr36533.c
blob8d71ece199d1fef1112e4b1a911ec29f4ab2588c
1 /* PR target/36533 */
2 /* { dg-do run { target { mmap && ilp32 } } } */
3 /* { dg-options "-Os" } */
4 #include <string.h>
5 #include <sys/mman.h>
6 #ifndef MAP_ANONYMOUS
7 #define MAP_ANONYMOUS MAP_ANON
8 #endif
10 typedef struct S1
12 unsigned long s1;
13 struct S1 *s2;
14 char *s3;
15 } S1;
17 typedef struct
19 unsigned int s4;
20 unsigned int s5;
21 int s6;
22 unsigned int *s7;
23 } S2;
25 typedef struct
27 unsigned int s8;
28 unsigned short s9;
29 unsigned char s10;
30 unsigned char s11;
31 char s12[255];
32 } S3;
34 typedef struct
36 unsigned int s4;
37 unsigned short s13;
38 unsigned short s14;
39 } S4;
41 typedef struct
43 char s15[16];
44 unsigned long s16;
45 } S5;
47 typedef struct
49 char s15[48];
50 S5 *s17;
51 } S6;
53 typedef struct
55 S1 *s18;
56 } S7;
58 __attribute__((regparm (3), noinline)) int
59 fn1 (const char *x, void *y, S1 *z)
61 asm volatile ("" : : : "memory");
62 return *x + (y != 0);
65 __attribute__((regparm (3), noinline)) int
66 fn2 (const char *x, int y, S2 *z)
68 asm volatile ("" : : : "memory");
69 return 0;
72 static inline __attribute__ ((always_inline)) unsigned int
73 fn4 (unsigned short x)
75 unsigned len = x;
76 if (len == ((1 << 16) - 1))
77 return 1 << 16;
78 return len;
81 static inline __attribute__ ((always_inline)) S3 *
82 fn3 (S3 *p)
84 return (S3 *) ((char *) p + fn4 (p->s9));
87 __attribute__((regparm (3), noinline)) int
88 fn5 (void)
90 asm volatile ("" : : : "memory");
91 return 0;
94 static inline __attribute__ ((always_inline)) int
95 fn6 (S3 *w, int x, S2 *y, S4 *z)
97 int a = 2;
98 char *b = (char *) w;
99 S2 c = *y;
101 while ((char *) w < b + x - 2 * sizeof (S4))
103 if (w->s10 && w->s8)
105 fn2 (w->s12, w->s10, &c);
106 z--;
107 z->s4 = c.s4;
108 z->s13 = (unsigned short) ((char *) w - b);
109 z->s14 = w->s9;
110 a++;
111 fn5 ();
114 w = fn3 (w);
116 return a;
119 __attribute__((regparm (3), noinline)) unsigned int
120 test (void *u, S6 *v, S1 **w, S7 *x, S2 *y, S1 *z)
122 unsigned b = v->s17->s16;
123 unsigned a;
124 S4 *c;
125 unsigned d, e, f, i;
127 fn1 (__func__, u, x->s18);
128 c = (S4 *) (z->s3 + b);
129 a = fn6 ((S3 *) (*w)->s3, b, y, c);
130 c -= a;
131 f = 0;
132 e = 2;
133 for (i = a - 1; ; i--)
135 if (f + (unsigned short) (c[i].s14 / 2) > b / 2)
136 break;
137 f += c[i].s14;
138 e++;
140 d = a - e;
141 return c[d].s4;
144 int main (void)
146 char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
147 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
148 S1 wb, z, *w;
149 S6 v;
150 S7 x;
151 S2 y;
152 S5 vb;
153 S4 s4;
154 if (p == MAP_FAILED)
155 return 0;
156 if (munmap (p + 65536, 65536) < 0)
157 return 0;
158 memset (&wb, 0, sizeof (wb));
159 memset (&z, 0, sizeof (z));
160 memset (&v, 0, sizeof (v));
161 memset (&x, 0, sizeof (x));
162 memset (&y, 0, sizeof (y));
163 memset (&vb, 0, sizeof (vb));
164 memset (&s4, 0, sizeof (s4));
165 s4.s14 = 254;
166 z.s3 = p + 65536 - 2 * sizeof (S4);
167 w = &wb;
168 v.s17 = &vb;
169 vb.s16 = 2 * sizeof (S4);
170 memcpy (z.s3, &s4, sizeof (s4));
171 memcpy (z.s3 + sizeof (s4), &s4, sizeof (s4));
172 test ((void *) 0, &v, &w, &x, &y, &z);
173 return 0;