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 
test_string(char * d,const char * s)18 void test_string (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   if (n == INT_MAX) string_eq_max_fail ();
27 
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 ();
34 }
35 
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" } } */
41