Update concepts branch to revision 131834
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtins / pr23484-chk.c
blob446fb6c2f057bc5a480fbffe146341c253085639
1 /* PR middle-end/23484 */
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);
12 #include "chk.h"
14 static char data[8] = "ABCDEFG";
16 int l1;
18 void
19 __attribute__((noinline))
20 test1 (void)
22 char buf[8];
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;
28 memset (buf, 'I', sizeof (buf));
29 if (memcpy (buf, data, l1 ? sizeof (buf) : 4) != buf
30 || memcmp (buf, "ABCDIIII", 8))
31 abort ();
33 memset (buf, 'J', sizeof (buf));
34 if (mempcpy (buf, data, l1 ? sizeof (buf) : 4) != buf + 4
35 || memcmp (buf, "ABCDJJJJ", 8))
36 abort ();
38 memset (buf, 'K', sizeof (buf));
39 if (memmove (buf, data, l1 ? sizeof (buf) : 4) != buf
40 || memcmp (buf, "ABCDKKKK", 8))
41 abort ();
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
54 if (chk_calls)
55 abort ();
58 void
59 main_test (void)
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 ();