| 1 |
/* Verify that memchr calls with the address of a constant character |
| 2 |
are folded as expected even at -O0. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O0 -Wall -fdump-tree-gimple" } */ |
| 5 |
|
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
typedef __WCHAR_TYPE__ wchar_t; |
| 8 |
|
| 9 |
extern void* memchr (const void*, int, size_t); |
| 10 |
extern int printf (const char*, ...); |
| 11 |
extern void abort (void); |
| 12 |
|
| 13 |
#define A(expr) \ |
| 14 |
((expr) \ |
| 15 |
? (void)0 \ |
| 16 |
: (printf ("assertion failed on line %i: %s\n", \ |
| 17 |
__LINE__, #expr), \ |
| 18 |
abort ())) |
| 19 |
|
| 20 |
const char nul = 0; |
| 21 |
const char cha = 'a'; |
| 22 |
|
| 23 |
const struct |
| 24 |
{ |
| 25 |
char c; |
| 26 |
} snul = { 0 }, |
| 27 |
schb = { 'b' }, |
| 28 |
sarr[] = { |
| 29 |
{ 0 }, |
| 30 |
{ 'c' } |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
void test_memchr_cst_char (void) |
| 35 |
{ |
| 36 |
A (&nul == memchr (&nul, 0, 1)); |
| 37 |
A (!memchr (&nul, 'a', 1)); |
| 38 |
|
| 39 |
A (&cha == memchr (&cha, 'a', 1)); |
| 40 |
A (!memchr (&cha, 0, 1)); |
| 41 |
|
| 42 |
A (&snul.c == memchr (&snul.c, 0, 1)); |
| 43 |
A (!memchr (&snul.c, 'a', 1)); |
| 44 |
|
| 45 |
A (&schb.c == memchr (&schb.c, 'b', 1)); |
| 46 |
A (!memchr (&schb.c, 0, 1)); |
| 47 |
|
| 48 |
A (&sarr[0].c == memchr (&sarr[0].c, 0, 1)); |
| 49 |
A (!memchr (&sarr[0].c, 'a', 1)); |
| 50 |
|
| 51 |
A (&sarr[1].c == memchr (&sarr[1].c, 'c', 1)); |
| 52 |
A (!memchr (&sarr[1].c, 0, 1)); |
| 53 |
} |
| 54 |
|
| 55 |
/* { dg-final { scan-tree-dump-not "abort" "gimple" } } */ |