2 memchr-1.c from the execute part of the gcc torture tests.
10 #pragma disable_warning 147
13 /* PR tree-optimization/86711 - wrong folding of memchr
15 Verify that memchr() of arrays initialized with string literals
16 where the nul doesn't fit in the array doesn't find the nul. */
18 extern void* memchr (const void*, int, size_t);
20 static const char c
= '1';
21 static const char s1
[1] = "1";
22 static const char s4
[4] = "1234";
24 static const char s4_2
[2][4] = { "1234", "5678" };
25 static const char s5_3
[3][5] = { "12345", "6789", "01234" };
33 void test_narrow (void)
42 ASSERT (memchr ("" + 1, 0, 0) == 0);
44 ASSERT (memchr (&c
, 0, sizeof c
) == 0);
45 ASSERT (memchr (&c
+ 1, 0, sizeof c
- 1) == 0);
46 ASSERT (memchr (&c
+ i1
, 0, sizeof c
- i1
) == 0);
47 ASSERT (memchr (&c
+ v1
, 0, sizeof c
- v1
) == 0);
49 ASSERT (memchr (s1
, 0, sizeof s1
) == 0);
50 ASSERT (memchr (s1
+ 1, 0, sizeof s1
- 1) == 0);
51 ASSERT (memchr (s1
+ i1
, 0, sizeof s1
- i1
) == 0);
52 ASSERT (memchr (s1
+ v1
, 0, sizeof s1
- v1
) == 0);
54 ASSERT (memchr (&s1
, 0, sizeof s1
) == 0);
55 ASSERT (memchr (&s1
+ 1, 0, sizeof s1
- 1) == 0);
56 ASSERT (memchr (&s1
+ i1
, 0, sizeof s1
- i1
) == 0);
57 ASSERT (memchr (&s1
+ v1
, 0, sizeof s1
- v1
) == 0);
58 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
59 ASSERT (memchr (&s1
[0], 0, sizeof s1
) == 0);
60 ASSERT (memchr (&s1
[0] + 1, 0, sizeof s1
- 1) == 0);
61 ASSERT (memchr (&s1
[0] + i1
, 0, sizeof s1
- i1
) == 0);
62 ASSERT (memchr (&s1
[0] + v1
, 0, sizeof s1
- v1
) == 0);
64 ASSERT (memchr (&s1
[i0
], 0, sizeof s1
) == 0);
65 ASSERT (memchr (&s1
[i0
] + 1, 0, sizeof s1
- 1) == 0);
66 ASSERT (memchr (&s1
[i0
] + i1
, 0, sizeof s1
- i1
) == 0);
67 ASSERT (memchr (&s1
[i0
] + v1
, 0, sizeof s1
- v1
) == 0);
69 ASSERT (memchr (&s1
[v0
], 0, sizeof s1
) == 0);
70 ASSERT (memchr (&s1
[v0
] + 1, 0, sizeof s1
- 1) == 0);
71 ASSERT (memchr (&s1
[v0
] + i1
, 0, sizeof s1
- i1
) == 0);
72 ASSERT (memchr (&s1
[v0
] + v1
, 0, sizeof s1
- v1
) == 0);
75 ASSERT (memchr (s4
+ i0
, 0, sizeof s4
- i0
) == 0);
76 ASSERT (memchr (s4
+ i1
, 0, sizeof s4
- i1
) == 0);
77 ASSERT (memchr (s4
+ i2
, 0, sizeof s4
- i2
) == 0);
78 ASSERT (memchr (s4
+ i3
, 0, sizeof s4
- i3
) == 0);
79 ASSERT (memchr (s4
+ i4
, 0, sizeof s4
- i4
) == 0);
81 ASSERT (memchr (s4
+ v0
, 0, sizeof s4
- v0
) == 0);
82 ASSERT (memchr (s4
+ v1
, 0, sizeof s4
- v1
) == 0);
83 ASSERT (memchr (s4
+ v2
, 0, sizeof s4
- v2
) == 0);
84 ASSERT (memchr (s4
+ v3
, 0, sizeof s4
- v3
) == 0);
85 ASSERT (memchr (s4
+ v4
, 0, sizeof s4
- v4
) == 0);
87 ASSERT (memchr (s4_2
, 0, sizeof s4_2
) == 0);
89 ASSERT (memchr (s4_2
[0], 0, sizeof s4_2
[0]) == 0);
90 ASSERT (memchr (s4_2
[1], 0, sizeof s4_2
[1]) == 0);
92 ASSERT (memchr (s4_2
[0] + 1, 0, sizeof s4_2
[0] - 1) == 0);
93 ASSERT (memchr (s4_2
[1] + 2, 0, sizeof s4_2
[1] - 2) == 0);
94 ASSERT (memchr (s4_2
[1] + 3, 0, sizeof s4_2
[1] - 3) == 0);
96 ASSERT (memchr (s4_2
[v0
], 0, sizeof s4_2
[v0
]) == 0);
97 ASSERT (memchr (s4_2
[v0
] + 1, 0, sizeof s4_2
[v0
] - 1) == 0);
100 /* The following calls must find the nul. */
101 ASSERT (memchr ("", 0, 1) != 0);
102 ASSERT (memchr (s5_3
, 0, sizeof s5_3
) == &s5_3
[1][4]);
104 ASSERT (memchr (&s5_3
[0][0] + i0
, 0, sizeof s5_3
- i0
) == &s5_3
[1][4]);
105 ASSERT (memchr (&s5_3
[0][0] + i1
, 0, sizeof s5_3
- i1
) == &s5_3
[1][4]);
106 ASSERT (memchr (&s5_3
[0][0] + i2
, 0, sizeof s5_3
- i2
) == &s5_3
[1][4]);
107 ASSERT (memchr (&s5_3
[0][0] + i4
, 0, sizeof s5_3
- i4
) == &s5_3
[1][4]);
109 ASSERT (memchr (&s5_3
[1][i0
], 0, sizeof s5_3
[1] - i0
) == &s5_3
[1][4]);
113 void test_wide (void) { }
116 testTortureExecute (void)