modernc.org/ccgo/v3@v3.16.14/lib/testdata/gcc-9.1.0/gcc/testsuite/gcc.c-torture/execute/builtins/pr23484-chk.c (about) 1 /* PR middle-end/23484 */ 2 3 extern void abort (void); 4 typedef __SIZE_TYPE__ size_t; 5 extern size_t strlen (const char *); 6 extern void *memcpy (void *, const void *, size_t); 7 extern void *mempcpy (void *, const void *, size_t); 8 extern void *memmove (void *, const void *, size_t); 9 extern int snprintf (char *, size_t, const char *, ...); 10 extern int memcmp (const void *, const void *, size_t); 11 12 #include "chk.h" 13 14 static char data[8] = "ABCDEFG"; 15 16 int l1; 17 18 void 19 __attribute__((noinline)) 20 test1 (void) 21 { 22 char buf[8]; 23 24 /* All the checking calls in this routine have a maximum length, so 25 object size checking should be done at compile time if optimizing. */ 26 chk_calls = 0; 27 28 memset (buf, 'I', sizeof (buf)); 29 if (memcpy (buf, data, l1 ? sizeof (buf) : 4) != buf 30 || memcmp (buf, "ABCDIIII", 8)) 31 abort (); 32 33 memset (buf, 'J', sizeof (buf)); 34 if (mempcpy (buf, data, l1 ? sizeof (buf) : 4) != buf + 4 35 || memcmp (buf, "ABCDJJJJ", 8)) 36 abort (); 37 38 memset (buf, 'K', sizeof (buf)); 39 if (memmove (buf, data, l1 ? sizeof (buf) : 4) != buf 40 || memcmp (buf, "ABCDKKKK", 8)) 41 abort (); 42 43 memset (buf, 'L', sizeof (buf)); 44 #if(__SIZEOF_INT__ >= 4) 45 if (snprintf (buf, l1 ? sizeof (buf) : 4, "%d", l1 + 65536) != 5 46 || memcmp (buf, "655\0LLLL", 8)) 47 abort (); 48 #else 49 if (snprintf (buf, l1 ? sizeof (buf) : 4, "%d", l1 + 32700) != 5 50 || memcmp (buf, "327\0LLLL", 8)) 51 abort (); 52 #endif 53 54 if (chk_calls) 55 abort (); 56 } 57 58 void 59 main_test (void) 60 { 61 #ifndef __OPTIMIZE__ 62 /* Object size checking is only intended for -O[s123]. */ 63 return; 64 #endif 65 __asm ("" : "=r" (l1) : "0" (l1)); 66 test1 (); 67 }