gcc/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-sprintf-11.c
blobe1effe6834167fc59f4e4d2b063b2232e7c14549
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" } */
8 typedef __WCHAR_TYPE__ wchar_t;
10 /* Exercise wide character constants. */
12 void test_lc_cst (void)
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;
19 int n = __builtin_snprintf (0, 0, "%lc", wc);
20 if (n < 0)
21 __builtin_abort ();
24 void test_C_cst (void)
26 /* Same as above but for %C and 0x31 which maps to 0x95. */
27 wchar_t wc = 0x31;
29 int n = __builtin_snprintf (0, 0, "%C", wc);
30 if (n < 0)
31 __builtin_abort ();
34 /* Exercise wide character values in known ranges. */
36 void test_lc_range (wchar_t wc)
38 if (wc < 0x40 || 0x49 < wc)
39 wc = 0x40;
41 int n = __builtin_snprintf (0, 0, "%lc", wc);
42 if (n < 0)
43 __builtin_abort ();
46 void test_C_range (wchar_t wc)
48 if (wc < 0x41 || 0x48 < wc)
49 wc = 0x41;
51 int n = __builtin_snprintf (0, 0, "%C", wc);
52 if (n < 0)
53 __builtin_abort ();
56 /* Exercise unknown wide character values. */
58 void test_var (wchar_t wc)
60 int n = __builtin_snprintf (0, 0, "%lc", wc);
61 if (n < 0)
62 __builtin_abort ();
65 /* { dg-final { scan-tree-dump-times "abort" 5 "optimized" } } */