1 /* Copyright (C) 2002, 2005  Free Software Foundation.
2 
3    Test -minline-all-stringops memset with various combinations of pointer
4    alignments and lengths to make sure builtin optimizations are correct.
5    PR target/6456.
6 
7    Written by Michael Meissner, March 9, 2002.
8    Target by Roger Sayle, April 25, 2002.  */
9 
10 /* { dg-do run } */
11 /* { dg-options "-O2 -minline-all-stringops" } */
12 
13 extern void *memset (void *, int, __SIZE_TYPE__);
14 extern void abort (void);
15 extern void exit (int);
16 
17 #ifndef MAX_OFFSET
18 #define MAX_OFFSET (sizeof (long long))
19 #endif
20 
21 #ifndef MAX_COPY
22 #define MAX_COPY (8 * sizeof (long long))
23 #endif
24 
25 #ifndef MAX_EXTRA
26 #define MAX_EXTRA (sizeof (long long))
27 #endif
28 
29 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
30 
31 static union {
32   char buf[MAX_LENGTH];
33   long long align_int;
34   long double align_fp;
35 } u;
36 
37 char A = 'A';
38 
39 int
main()40 main ()
41 {
42   int off, len, i;
43   char *p, *q;
44 
45   for (off = 0; off < MAX_OFFSET; off++)
46     for (len = 1; len < MAX_COPY; len++)
47       {
48 	for (i = 0; i < MAX_LENGTH; i++)
49 	  u.buf[i] = 'a';
50 
51 	p = memset (u.buf + off, '\0', len);
52 	if (p != u.buf + off)
53 	  abort ();
54 
55 	q = u.buf;
56 	for (i = 0; i < off; i++, q++)
57 	  if (*q != 'a')
58 	    abort ();
59 
60 	for (i = 0; i < len; i++, q++)
61 	  if (*q != '\0')
62 	    abort ();
63 
64 	for (i = 0; i < MAX_EXTRA; i++, q++)
65 	  if (*q != 'a')
66 	    abort ();
67 
68 	p = memset (u.buf + off, A, len);
69 	if (p != u.buf + off)
70 	  abort ();
71 
72 	q = u.buf;
73 	for (i = 0; i < off; i++, q++)
74 	  if (*q != 'a')
75 	    abort ();
76 
77 	for (i = 0; i < len; i++, q++)
78 	  if (*q != 'A')
79 	    abort ();
80 
81 	for (i = 0; i < MAX_EXTRA; i++, q++)
82 	  if (*q != 'a')
83 	    abort ();
84 
85 	p = memset (u.buf + off, 'B', len);
86 	if (p != u.buf + off)
87 	  abort ();
88 
89 	q = u.buf;
90 	for (i = 0; i < off; i++, q++)
91 	  if (*q != 'a')
92 	    abort ();
93 
94 	for (i = 0; i < len; i++, q++)
95 	  if (*q != 'B')
96 	    abort ();
97 
98 	for (i = 0; i < MAX_EXTRA; i++, q++)
99 	  if (*q != 'a')
100 	    abort ();
101       }
102 
103   exit(0);
104 }
105 
106