2008-11-15 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / builtins / memchr.c
blob88e731128f6ac77037bbb18a2b39d5e8185dc55b
1 /* Copyright (C) 2007 Free Software Foundation.
3 Ensure all expected transformations of builtin memchr occur
4 and perform correctly.
6 Written by Paolo Carlini, 10/5/2007. */
8 extern void abort (void);
9 typedef __SIZE_TYPE__ size_t;
10 extern void *memchr (const void *, int, size_t);
12 void
13 main_test (void)
15 const char* const foo1 = "hello world";
17 if (memchr (foo1, 'x', 11))
18 abort ();
19 if (memchr (foo1, 'o', 11) != foo1 + 4)
20 abort ();
21 if (memchr (foo1, 'w', 2))
22 abort ();
23 if (memchr (foo1 + 5, 'o', 6) != foo1 + 7)
24 abort ();
25 if (memchr (foo1, 'd', 11) != foo1 + 10)
26 abort ();
27 if (memchr (foo1, 'd', 10))
28 abort ();
29 if (memchr (foo1, '\0', 11))
30 abort ();
31 if (memchr (foo1, '\0', 12) != foo1 + 11)
32 abort ();
34 /* Test at least one instance of the __builtin_ style. We do this
35 to ensure that it works and that the prototype is correct. */
36 if (__builtin_memchr (foo1, 'r', 11) != foo1 + 8)
37 abort ();