2018-05-17 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / memset-1.c
blob5e0f0b15340ab2fcf50819f7d12b424b95a6962c
1 /* Copyright (C) 2002, 2005 Free Software Foundation.
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.
7 Written by Michael Meissner, March 9, 2002.
8 Target by Roger Sayle, April 25, 2002. */
10 /* { dg-do run } */
11 /* { dg-options "-O2 -minline-all-stringops" } */
13 extern void *memset (void *, int, __SIZE_TYPE__);
14 extern void abort (void);
15 extern void exit (int);
17 #ifndef MAX_OFFSET
18 #define MAX_OFFSET (sizeof (long long))
19 #endif
21 #ifndef MAX_COPY
22 #define MAX_COPY (8 * sizeof (long long))
23 #endif
25 #ifndef MAX_EXTRA
26 #define MAX_EXTRA (sizeof (long long))
27 #endif
29 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA)
31 static union {
32 char buf[MAX_LENGTH];
33 long long align_int;
34 long double align_fp;
35 } u;
37 char A = 'A';
39 int
40 main ()
42 int off, len, i;
43 char *p, *q;
45 for (off = 0; off < MAX_OFFSET; off++)
46 for (len = 1; len < MAX_COPY; len++)
48 for (i = 0; i < MAX_LENGTH; i++)
49 u.buf[i] = 'a';
51 p = memset (u.buf + off, '\0', len);
52 if (p != u.buf + off)
53 abort ();
55 q = u.buf;
56 for (i = 0; i < off; i++, q++)
57 if (*q != 'a')
58 abort ();
60 for (i = 0; i < len; i++, q++)
61 if (*q != '\0')
62 abort ();
64 for (i = 0; i < MAX_EXTRA; i++, q++)
65 if (*q != 'a')
66 abort ();
68 p = memset (u.buf + off, A, len);
69 if (p != u.buf + off)
70 abort ();
72 q = u.buf;
73 for (i = 0; i < off; i++, q++)
74 if (*q != 'a')
75 abort ();
77 for (i = 0; i < len; i++, q++)
78 if (*q != 'A')
79 abort ();
81 for (i = 0; i < MAX_EXTRA; i++, q++)
82 if (*q != 'a')
83 abort ();
85 p = memset (u.buf + off, 'B', len);
86 if (p != u.buf + off)
87 abort ();
89 q = u.buf;
90 for (i = 0; i < off; i++, q++)
91 if (*q != 'a')
92 abort ();
94 for (i = 0; i < len; i++, q++)
95 if (*q != 'B')
96 abort ();
98 for (i = 0; i < MAX_EXTRA; i++, q++)
99 if (*q != 'a')
100 abort ();
103 exit(0);