1 /* Copyright (C) 2002 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 { target "i?86-*-*" } } */ 11 /* { dg-options "-O2 -minline-all-stringops" } */ 12 13 #ifndef MAX_OFFSET 14 #define MAX_OFFSET (sizeof (long long)) 15 #endif 16 17 #ifndef MAX_COPY 18 #define MAX_COPY (8 * sizeof (long long)) 19 #endif 20 21 #ifndef MAX_EXTRA 22 #define MAX_EXTRA (sizeof (long long)) 23 #endif 24 25 #define MAX_LENGTH (MAX_OFFSET + MAX_COPY + MAX_EXTRA) 26 27 static union { 28 char buf[MAX_LENGTH]; 29 long long align_int; 30 long double align_fp; 31 } u; 32 33 char A = 'A'; 34 35 main () 36 { 37 int off, len, i; 38 char *p, *q; 39 40 for (off = 0; off < MAX_OFFSET; off++) 41 for (len = 1; len < MAX_COPY; len++) 42 { 43 for (i = 0; i < MAX_LENGTH; i++) 44 u.buf[i] = 'a'; 45 46 p = memset (u.buf + off, '\0', len); 47 if (p != u.buf + off) 48 abort (); 49 50 q = u.buf; 51 for (i = 0; i < off; i++, q++) 52 if (*q != 'a') 53 abort (); 54 55 for (i = 0; i < len; i++, q++) 56 if (*q != '\0') 57 abort (); 58 59 for (i = 0; i < MAX_EXTRA; i++, q++) 60 if (*q != 'a') 61 abort (); 62 63 p = memset (u.buf + off, A, len); 64 if (p != u.buf + off) 65 abort (); 66 67 q = u.buf; 68 for (i = 0; i < off; i++, q++) 69 if (*q != 'a') 70 abort (); 71 72 for (i = 0; i < len; i++, q++) 73 if (*q != 'A') 74 abort (); 75 76 for (i = 0; i < MAX_EXTRA; i++, q++) 77 if (*q != 'a') 78 abort (); 79 80 p = memset (u.buf + off, 'B', len); 81 if (p != u.buf + off) 82 abort (); 83 84 q = u.buf; 85 for (i = 0; i < off; i++, q++) 86 if (*q != 'a') 87 abort (); 88 89 for (i = 0; i < len; i++, q++) 90 if (*q != 'B') 91 abort (); 92 93 for (i = 0; i < MAX_EXTRA; i++, q++) 94 if (*q != 'a') 95 abort (); 96 } 97 98 exit(0); 99 } 100 101