Debian Codegraph @

gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-22.c

raw
1 /* PR tree-optimization/91567 - Spurious -Wformat-overflow warnings building
2 glibc (32-bit only)
3 { dg-do compile }
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
5
6 typedef __SIZE_TYPE__ size_t;
7
8 extern int sprintf (char*, const char*, ...);
9 extern size_t strlen (const char*);
10
11 void f (char *);
12
13 void g (char *s1, char *s2)
14 {
15 char b[1025];
16 size_t n = __builtin_strlen (s1), d = __builtin_strlen (s2);
17 if (n + d + 1 >= 1025)
18 return;
19
20 /* Ranger can find ranges here:
21 [1] n_6: size_t [0, 1023]
22 [2] d_8: size_t [0, 1023]
23
24 Whereas evrp can't really:
25 [1] n_6: size_t [0, 9223372036854775805]
26 [2] d_8: size_t [0, 9223372036854775805]
27
28 This is causing the sprintf warning pass to issue a false
29 positive here. */
30
31 sprintf (b, "%s.%s", s1, s2); // { dg-bogus "\\\[-Wformat-overflow" "" { xfail *-*-* } }
32
33 f (b);
34 }
35
36 /* Extracted from gcc/c-cppbuiltin.c. */
37
38 void cpp_define (char*);
39
40 static void
41 builtin_define_type_minmax (const char *min_macro, const char *max_macro,
42 void *type)
43 {
44 extern const char *suffix;
45 char *buf;
46
47 if (type)
48 {
49 buf = (char *) __builtin_alloca (__builtin_strlen (min_macro) + 2
50 + __builtin_strlen (suffix) + 1);
51 sprintf (buf, "%s=0%s", min_macro, suffix); // { dg-bogus "\\\[-Wformat-overflow" }
52 }
53 else
54 {
55 buf = (char *) __builtin_alloca (__builtin_strlen (min_macro) + 3
56 + __builtin_strlen (max_macro) + 6);
57 sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro); // { dg-bogus "\\\[-Wformat-overflow" }
58 }
59
60 cpp_define (buf);
61 }
62
63 void
64 c_cpp_builtins (void *type)
65 {
66
67 builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__", type);
68 builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", type);
69 }