Debian Codegraph @

gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-3.c

raw
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" } */
7
8 #define INT_MAX __INT_MAX__
9 #define INT_MIN (-INT_MAX - 1)
10
11 extern void string_eq_min_fail ();
12 extern void string_eq_max_fail ();
13
14 extern void string_lt_0_fail ();
15 extern void string_eq_0_fail ();
16 extern void string_gt_0_fail ();
17
18 void test_string_eq_min (char *d, const char *s)
19 {
20 int n = __builtin_sprintf (d, "%-s", s);
21
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 }
27
28 void test_string_eq_max (char *d, const char *s)
29 {
30 int n = __builtin_sprintf (d, "%-s", s);
31
32 if (n == INT_MAX) string_eq_max_fail ();
33 }
34
35 void test_string_lt_0 (char *d, const char *s)
36 {
37 int n = __builtin_sprintf (d, "%-s", s);
38
39 /* The return value could be negative when strlen(s) is in excess
40 of 4095 (the maximum number of bytes a single directive is required
41 to handle). */
42 if (n < 0) string_lt_0_fail ();
43 }
44
45 void test_string_eq_0 (char *d, const char *s)
46 {
47 int n = __builtin_sprintf (d, "%-s", s);
48
49 if (n == 0) string_eq_0_fail ();
50 }
51
52 void test_string_gt_0 (char *d, const char *s)
53 {
54 int n = __builtin_sprintf (d, "%-s", s);
55
56 if (n > 0) string_gt_0_fail ();
57 }
58
59 /* { dg-final { scan-tree-dump-times "string_eq_min_fail" 1 "optimized" } } */
60 /* { dg-final { scan-tree-dump-times "string_eq_max_fail" 1 "optimized" } } */
61 /* { dg-final { scan-tree-dump-times "string_lt_0_fail" 1 "optimized" } } */
62 /* { dg-final { scan-tree-dump-times "string_eq_0_fail" 1 "optimized" } } */
63 /* { dg-final { scan-tree-dump-times "string_gt_0_fail" 1 "optimized" } } */