1 /* { dg-do run } */
2 /* { dg-require-effective-target mempcpy } */
3 /* PR fortran/45636 */
4 
5 typedef __SIZE_TYPE__ size_t;
6 void *memcpy (void *__restrict__, const void *__restrict__, size_t);
7 void *mempcpy (void *__restrict__, const void *__restrict__, size_t);
8 void *memset (void *, int, size_t);
9 int memcmp (const void *, const void *, size_t);
10 extern void abort (void);
11 
12 struct A { int i; char c[32]; } a[2];
13 
14 __attribute__((noinline, noclone)) int
f1(char * p,int q,int z)15 f1 (char *p, int q, int z)
16 {
17   memcpy (p, "abcd", 4);
18   if (q)
19     z = z + 123;
20   else
21     z *= 114;
22   memset (p + 4, ' ', 2);
23   return z;
24 }
25 
26 __attribute__((noinline, noclone)) void
f2(void)27 f2 (void)
28 {
29   char *p = mempcpy (&a[0].c[13], "123456", 4);
30   memset (p, '7', 3);
31 }
32 
33 __attribute__((noinline, noclone)) void
f3(struct A * p)34 f3 (struct A *p)
35 {
36   p++;
37   char *q = &p->c[10];
38   memcpy (q + 4, "__1234567" + 2, 7);
39   memset (&p->c[21], '9', 3);
40 }
41 
42 __attribute__((noinline, noclone)) void
f4(void)43 f4 (void)
44 {
45   memcpy (&a[0].c[10], "0123456789", 10);
46   memset (&a[0].c[13], ' ', 3);
47 }
48 
49 __attribute__((noinline, noclone)) void
check(const char * p,const char * str,size_t size)50 check (const char *p, const char *str, size_t size)
51 {
52   const char *q;
53   for (q = (const char *) &a; q < p; q++)
54     if (*q)
55       abort ();
56   if (memcmp (p, str, size) != 0)
57     abort ();
58   for (q = p + size; q < (const char *) (&a[0] + 2); q++)
59     if (*q)
60       abort ();
61   memset (&a, '\0', sizeof a);
62 }
63 
64 int
main(void)65 main (void)
66 {
67   if (f1 (&a[0].c[7], 1, 2) != 125)
68     abort ();
69   check (&a[0].c[7], "abcd  ", 6);
70   f2 ();
71   check (&a[0].c[13], "1234777", 7);
72   f3 (&a[0]);
73   check (&a[1].c[14], "1234567999", 10);
74   f4 ();
75   check (&a[0].c[10], "012   6789", 10);
76   return 0;
77 }
78