* g++.dg/pph/c1attr-warn-unused-result.cc: New.
[official-gcc.git] / gcc / testsuite / g++.dg / pph / c1pr36533.h
blob6c6a6ae6284188750e79fbe1afc5f906604110f6
1 #ifndef __PPH_GUARD_H
2 #define __PPH_GUARD_H
3 /* PR target/36533 */
4 /* { dg-options "-w -fpermissive" } */
5 #include <string.h>
6 #include <sys/mman.h>
7 #ifndef MAP_ANONYMOUS
8 #define MAP_ANONYMOUS MAP_ANON
9 #endif
11 typedef struct S1
13 unsigned long s1;
14 struct S1 *s2;
15 char *s3;
16 } S1;
18 typedef struct
20 unsigned int s4;
21 unsigned int s5;
22 int s6;
23 unsigned int *s7;
24 } S2;
26 typedef struct
28 unsigned int s8;
29 unsigned short s9;
30 unsigned char s10;
31 unsigned char s11;
32 char s12[255];
33 } S3;
35 typedef struct
37 unsigned int s4;
38 unsigned short s13;
39 unsigned short s14;
40 } S4;
42 typedef struct
44 char s15[16];
45 unsigned long s16;
46 } S5;
48 typedef struct
50 char s15[48];
51 S5 *s17;
52 } S6;
54 typedef struct
56 S1 *s18;
57 } S7;
59 __attribute__((regparm (3), noinline)) int
60 fn1 (const char *x, void *y, S1 *z)
62 asm volatile ("" : : : "memory");
63 return *x + (y != 0);
66 __attribute__((regparm (3), noinline)) int
67 fn2 (const char *x, int y, S2 *z)
69 asm volatile ("" : : : "memory");
70 return 0;
73 static inline __attribute__ ((always_inline)) unsigned int
74 fn4 (unsigned short x)
76 unsigned len = x;
77 if (len == ((1 << 16) - 1))
78 return 1 << 16;
79 return len;
82 static inline __attribute__ ((always_inline)) S3 *
83 fn3 (S3 *p)
85 return (S3 *) ((char *) p + fn4 (p->s9));
88 __attribute__((regparm (3), noinline)) int
89 fn5 (void)
91 asm volatile ("" : : : "memory");
92 return 0;
95 static inline __attribute__ ((always_inline)) int
96 fn6 (S3 *w, int x, S2 *y, S4 *z)
98 int a = 2;
99 char *b = (char *) w;
100 S2 c = *y;
102 while ((char *) w < b + x - 2 * sizeof (S4))
104 if (w->s10 && w->s8)
106 fn2 (w->s12, w->s10, &c);
107 z--;
108 z->s4 = c.s4;
109 z->s13 = (unsigned short) ((char *) w - b);
110 z->s14 = w->s9;
111 a++;
112 fn5 ();
115 w = fn3 (w);
117 return a;
120 __attribute__((regparm (3), noinline)) unsigned int
121 test (void *u, S6 *v, S1 **w, S7 *x, S2 *y, S1 *z)
123 unsigned b = v->s17->s16;
124 unsigned a;
125 S4 *c;
126 unsigned d, e, f, i;
128 fn1 (__func__, u, x->s18);
129 c = (S4 *) (z->s3 + b);
130 a = fn6 ((S3 *) (*w)->s3, b, y, c);
131 c -= a;
132 f = 0;
133 e = 2;
134 for (i = a - 1; ; i--)
136 if (f + (unsigned short) (c[i].s14 / 2) > b / 2)
137 break;
138 f += c[i].s14;
139 e++;
141 d = a - e;
142 return c[d].s4;
145 int main (void)
147 char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE,
148 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
149 S1 wb, z, *w;
150 S6 v;
151 S7 x;
152 S2 y;
153 S5 vb;
154 S4 s4;
155 if (p == MAP_FAILED)
156 return 0;
157 if (munmap (p + 65536, 65536) < 0)
158 return 0;
159 memset (&wb, 0, sizeof (wb));
160 memset (&z, 0, sizeof (z));
161 memset (&v, 0, sizeof (v));
162 memset (&x, 0, sizeof (x));
163 memset (&y, 0, sizeof (y));
164 memset (&vb, 0, sizeof (vb));
165 memset (&s4, 0, sizeof (s4));
166 s4.s14 = 254;
167 z.s3 = p + 65536 - 2 * sizeof (S4);
168 w = &wb;
169 v.s17 = &vb;
170 vb.s16 = 2 * sizeof (S4);
171 memcpy (z.s3, &s4, sizeof (s4));
172 memcpy (z.s3 + sizeof (s4), &s4, sizeof (s4));
173 test ((void *) 0, &v, &w, &x, &y, &z);
174 return 0;
176 #endif