| 1 |
/* PR tree-optimization/71625 - conversion of braced initializers to strings |
| 2 |
Verify that array elements have the expected values regardless of sign |
| 3 |
and non-ASCII execution character set. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-require-iconv "IBM1047" } |
| 6 |
{ dg-options "-O -Wall -fexec-charset=IBM1047 -fdump-tree-gimple -fdump-tree-optimized" } */ |
| 7 |
|
| 8 |
#include "strlenopt.h" |
| 9 |
|
| 10 |
const char a[] = { 'a', 129, 0 }; |
| 11 |
const signed char b[] = { 'b', 130, 0 }; |
| 12 |
const unsigned char c[] = { 'c', 131, 0 }; |
| 13 |
|
| 14 |
const char s[] = "a\201"; |
| 15 |
const signed char ss[] = "b\202"; |
| 16 |
const unsigned char us[] = "c\203"; |
| 17 |
|
| 18 |
|
| 19 |
#define A(expr) ((expr) ? (void)0 : __builtin_abort ()) |
| 20 |
|
| 21 |
void test_values (void) |
| 22 |
{ |
| 23 |
A (a[0] == a[1]); |
| 24 |
A (a[1] == 'a'); |
| 25 |
|
| 26 |
A (b[0] == b[1]); |
| 27 |
A (b[1] == (signed char)'b'); |
| 28 |
|
| 29 |
A (c[0] == c[1]); |
| 30 |
A (c[1] == (unsigned char)'c'); |
| 31 |
} |
| 32 |
|
| 33 |
void test_lengths (void) |
| 34 |
{ |
| 35 |
A (2 == strlen (a)); |
| 36 |
A (2 == strlen ((const char*)b)); |
| 37 |
A (2 == strlen ((const char*)c)); |
| 38 |
} |
| 39 |
|
| 40 |
void test_contents (void) |
| 41 |
{ |
| 42 |
A (0 == strcmp (a, s)); |
| 43 |
A (0 == strcmp ((const char*)b, (const char*)ss)); |
| 44 |
A (0 == strcmp ((const char*)c, (const char*)us)); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/* { dg-final { scan-tree-dump-times "strlen1" 0 "gimple" } } |
| 49 |
{ dg-final { scan-tree-dump-times "strcmp" 0 "gimple" } } |
| 50 |
{ dg-final { scan-tree-dump-times "abort" 0 "optimized" } } */ |