1 /* PR middle-end/78461 - [7 Regression] ICE: in operator+=, at
2 gimple-ssa-sprintf.c:214
3 Disable warnings to exercise code paths through the pass that may
4 not be exercised when the -Wformat-overflow option is in effect. */
5 /* { dg-do compile }
6 { dg-options "-O2 -fdump-tree-optimized -w" } */
7
8
9 #define CAT(s, n) s ## n
10 #define FAIL(line) CAT (failure_on_line_, line)
11
12 /* Emit a call to a function named failure_on_line_NNN when EXPR is false. */
13 #define ASSERT(expr) \
14 do { \
15 extern void FAIL (__LINE__)(void); \
16 if (!(expr)) FAIL (__LINE__)(); \
17 } while (0)
18
19 #define KEEP(line) CAT (keep_call_on_line_, line)
20
21 /* Emit a call to a function named keep_call_on_line_NNN when EXPR is true.
22 Used to verify that the expression need not be the only one that holds. */
23 #define ASSERT_MAYBE(expr) \
24 do { \
25 extern void KEEP (__LINE__)(void); \
26 if (expr) KEEP (__LINE__)(); \
27 } while (0)
28
f0(const char * s)29 int f0 (const char *s)
30 {
31 int n = __builtin_snprintf (0, 0, "%.*s%08x", 1, s, 1);
32
33 ASSERT (7 < n && n < 10);
34
35 ASSERT_MAYBE (8 == n);
36 ASSERT_MAYBE (9 == n);
37
38 return n;
39 }
40
41 char buf[64];
42
f1(const char * s)43 int f1 (const char *s)
44 {
45 int n = __builtin_snprintf (buf, 64, "%.*s%08x", 1, s, 1);
46
47 ASSERT (7 < n && n < 10);
48
49 ASSERT_MAYBE (8 == n);
50 ASSERT_MAYBE (9 == n);
51
52 return n;
53 }
54
f2(const char * s)55 int f2 (const char *s)
56 {
57 int n = __builtin_snprintf (0, 0, "%.*s", 2, s);
58
59 ASSERT (0 <= n && n <= 2);
60
61 ASSERT_MAYBE (0 == n);
62 ASSERT_MAYBE (1 == n);
63 ASSERT_MAYBE (2 == n);
64
65 return n;
66 }
67
68 /* { dg-final { scan-tree-dump-not "failure_on_line" "optimized"} }
69 { dg-final { scan-tree-dump-times "keep_call_on_line" 7 "optimized"} } */
70