PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-sprintf-3.c
blobfae2a1b73ead288cc2dcb1eb759cfcfa13f0d35b
1 /* PR bootstrap/77676 - powerpc64 and powerpc64le stage2 bootstrap fail
2 Test case derived from the one submitted in the bug. It verifies
3 that the sprintf return value (or value range) optimization is not
4 performed for an unknown string. */
5 /* { dg-do compile } */
6 /* { dg-options "-O2 -Wall -Werror -fdump-tree-optimized -fprintf-return-value" } */
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-INT_MAX - 1)
11 extern void string_eq_min_fail ();
12 extern void string_eq_max_fail ();
14 extern void string_lt_0_fail ();
15 extern void string_eq_0_fail ();
16 extern void string_gt_0_fail ();
18 void test_string (char *d, const char *s)
20 int n = __builtin_sprintf (d, "%-s", s);
22 /* Verify that the return value is NOT assumed NOT to be INT_MIN
23 or INT_MAX. (This is a white box test based on knowing that
24 the optimization computes its own values of the two constants.) */
25 if (n == INT_MIN) string_eq_min_fail ();
26 if (n == INT_MAX) string_eq_max_fail ();
28 /* The return value could be negative when strlen(s) is in excess
29 of 4095 (the maximum number of bytes a single directive is required
30 to handle). */
31 if (n < 0) string_lt_0_fail ();
32 if (n == 0) string_eq_0_fail ();
33 if (n > 0) string_gt_0_fail ();
36 /* { dg-final { scan-tree-dump-times "string_eq_min_fail" 1 "optimized" } } */
37 /* { dg-final { scan-tree-dump-times "string_eq_max_fail" 1 "optimized" } } */
38 /* { dg-final { scan-tree-dump-times "string_lt_0_fail" 1 "optimized" } } */
39 /* { dg-final { scan-tree-dump-times "string_eq_0_fail" 1 "optimized" } } */
40 /* { dg-final { scan-tree-dump-times "string_gt_0_fail" 1 "optimized" } } */