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