| 1 |
/* PR tree-optimization/86853 - sprintf optimization for wide strings |
| 2 |
doesn't account for conversion failure​ |
| 3 |
Exercise wide character handling in an EBCDIC execution charset. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-require-iconv "IBM1047" } |
| 6 |
{ dg-options "-O2 -Wall -Wno-format -Wformat-overflow -fexec-charset=IBM1047 -fdump-tree-optimized" } */ |
| 7 |
|
| 8 |
typedef __WCHAR_TYPE__ wchar_t; |
| 9 |
|
| 10 |
/* Exercise wide character constants. */ |
| 11 |
|
| 12 |
void test_lc_cst (void) |
| 13 |
{ |
| 14 |
/* IBM1047 0x30 maps to ASCII 0x94 which neeed not be representable |
| 15 |
in the current locale (and the snprintf() call may fail). Verify |
| 16 |
that snprintf() doesn't assume it is. */ |
| 17 |
wchar_t wc = 0x30; |
| 18 |
|
| 19 |
int n = __builtin_snprintf (0, 0, "%lc", wc); |
| 20 |
if (n < 0) |
| 21 |
__builtin_abort (); |
| 22 |
} |
| 23 |
|
| 24 |
void test_C_cst (void) |
| 25 |
{ |
| 26 |
/* Same as above but for %C and 0x31 which maps to 0x95. */ |
| 27 |
wchar_t wc = 0x31; |
| 28 |
|
| 29 |
int n = __builtin_snprintf (0, 0, "%C", wc); |
| 30 |
if (n < 0) |
| 31 |
__builtin_abort (); |
| 32 |
} |
| 33 |
|
| 34 |
/* Exercise wide character values in known ranges. */ |
| 35 |
|
| 36 |
void test_lc_range (wchar_t wc) |
| 37 |
{ |
| 38 |
if (wc < 0x40 || 0x49 < wc) |
| 39 |
wc = 0x40; |
| 40 |
|
| 41 |
int n = __builtin_snprintf (0, 0, "%lc", wc); |
| 42 |
if (n < 0) |
| 43 |
__builtin_abort (); |
| 44 |
} |
| 45 |
|
| 46 |
void test_C_range (wchar_t wc) |
| 47 |
{ |
| 48 |
if (wc < 0x41 || 0x48 < wc) |
| 49 |
wc = 0x41; |
| 50 |
|
| 51 |
int n = __builtin_snprintf (0, 0, "%C", wc); |
| 52 |
if (n < 0) |
| 53 |
__builtin_abort (); |
| 54 |
} |
| 55 |
|
| 56 |
/* Exercise unknown wide character values. */ |
| 57 |
|
| 58 |
void test_var (wchar_t wc) |
| 59 |
{ |
| 60 |
int n = __builtin_snprintf (0, 0, "%lc", wc); |
| 61 |
if (n < 0) |
| 62 |
__builtin_abort (); |
| 63 |
} |
| 64 |
|
| 65 |
/* { dg-final { scan-tree-dump-times "abort" 5 "optimized" } } */ |