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 13extern void *memset (void *, int, __SIZE_TYPE__); 14extern void abort (void); 15extern 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 31static union { 32 char buf[MAX_LENGTH]; 33 long long align_int; 34 long double align_fp; 35} u; 36 37char A = 'A'; 38 39main () 40{ 41 int off, len, i; 42 char *p, *q; 43 44 for (off = 0; off < MAX_OFFSET; off++) 45 for (len = 1; len < MAX_COPY; len++) 46 { 47 for (i = 0; i < MAX_LENGTH; i++) 48 u.buf[i] = 'a'; 49 50 p = memset (u.buf + off, '\0', len); 51 if (p != u.buf + off) 52 abort (); 53 54 q = u.buf; 55 for (i = 0; i < off; i++, q++) 56 if (*q != 'a') 57 abort (); 58 59 for (i = 0; i < len; i++, q++) 60 if (*q != '\0') 61 abort (); 62 63 for (i = 0; i < MAX_EXTRA; i++, q++) 64 if (*q != 'a') 65 abort (); 66 67 p = memset (u.buf + off, A, len); 68 if (p != u.buf + off) 69 abort (); 70 71 q = u.buf; 72 for (i = 0; i < off; i++, q++) 73 if (*q != 'a') 74 abort (); 75 76 for (i = 0; i < len; i++, q++) 77 if (*q != 'A') 78 abort (); 79 80 for (i = 0; i < MAX_EXTRA; i++, q++) 81 if (*q != 'a') 82 abort (); 83 84 p = memset (u.buf + off, 'B', len); 85 if (p != u.buf + off) 86 abort (); 87 88 q = u.buf; 89 for (i = 0; i < off; i++, q++) 90 if (*q != 'a') 91 abort (); 92 93 for (i = 0; i < len; i++, q++) 94 if (*q != 'B') 95 abort (); 96 97 for (i = 0; i < MAX_EXTRA; i++, q++) 98 if (*q != 'a') 99 abort (); 100 } 101 102 exit(0); 103} 104 105