Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-strlen-1.c
blobbb971dd11ad3dfefa9dcd6a39aa580117a8b8577
1 /*
2 strlen-1.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 /* Copyright (C) 2002 Free Software Foundation.
9 Test strlen with various combinations of pointer alignments and lengths to
10 make sure any optimizations in the library are correct.
12 Written by Michael Meissner, March 9, 2002. */
14 #include <string.h>
15 #include <stddef.h>
17 #if !defined(__SDCC_pdk14) // Lack of memory
18 #ifndef MAX_OFFSET
19 #define MAX_OFFSET (sizeof (long long))
20 #endif
22 #ifndef MAX_TEST
23 #define MAX_TEST (8 * sizeof (long long))
24 #endif
26 #ifndef MAX_EXTRA
27 #define MAX_EXTRA (sizeof (long long))
28 #endif
30 #define MAX_LENGTH (MAX_OFFSET + MAX_TEST + MAX_EXTRA + 1)
32 static union {
33 char buf[MAX_LENGTH];
34 long long align_int;
35 #if 0 // TODO: enable when SDCC supports long double!
36 long double align_fp;
37 #endif
38 } u;
39 #endif
41 void
42 testTortureExecute (void)
44 #if !defined(__SDCC_pdk14) // Lack of memory
45 size_t off, len, len2, i;
46 char *p;
48 for (off = 0; off < MAX_OFFSET; off++)
49 for (len = 0; len < MAX_TEST; len++)
51 p = u.buf;
52 for (i = 0; i < off; i++)
53 *p++ = '\0';
55 for (i = 0; i < len; i++)
56 *p++ = 'a';
58 *p++ = '\0';
59 for (i = 0; i < MAX_EXTRA; i++)
60 *p++ = 'b';
62 p = u.buf + off;
63 len2 = strlen (p);
64 if (len != len2)
65 ASSERT (0);
68 return;
69 #endif