libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-sprintf-warn-22.c
blob82eb5851c59b0bb6776de4a67a474cb8805adab0
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 { dg-require-effective-target alloca } */
7 typedef __SIZE_TYPE__ size_t;
9 extern int sprintf (char*, const char*, ...);
10 extern size_t strlen (const char*);
12 void f (char *);
14 void g (char *s1, char *s2)
16 char b[1025];
17 size_t n = __builtin_strlen (s1), d = __builtin_strlen (s2);
18 if (n + d + 1 >= 1025)
19 return;
21 /* Ranger can find ranges here:
22 [1] n_6: size_t [0, 1023]
23 [2] d_8: size_t [0, 1023]
25 Whereas evrp can't really:
26 [1] n_6: size_t [0, 9223372036854775805]
27 [2] d_8: size_t [0, 9223372036854775805]
29 This is causing the sprintf warning pass to issue a false
30 positive here. */
32 sprintf (b, "%s.%s", s1, s2); // { dg-bogus "\\\[-Wformat-overflow" "" { xfail *-*-* } }
34 f (b);
37 /* Extracted from gcc/c-cppbuiltin.c. */
39 void cpp_define (char*);
41 static void
42 builtin_define_type_minmax (const char *min_macro, const char *max_macro,
43 void *type)
45 extern const char *suffix;
46 char *buf;
48 if (type)
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" }
54 else
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" }
61 cpp_define (buf);
64 void
65 c_cpp_builtins (void *type)
68 builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__", type);
69 builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", type);