gcc/testsuite/ChangeLog:
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-sprintf-warn-19.c
blob1ab19e060ca8934c1ed03f4a29d8b13f6d4c81bb
1 /* PR tree-optimization/80397 - missing -Wformat-overflow with arguments
2 of enum types
3 { dg-do compile }
4 { dg-options "-O2 -Wall -Wformat-overflow=1 -ftrack-macro-expansion=0" }
5 { dg-require-effective-target int32plus } */
7 void sink (char*);
9 static long long integer_range (long long min, long long max)
11 extern long long integer_value (void);
12 long long n = integer_value ();
13 return n < min || max < n ? min : n;
16 typedef enum { i0, imax = __INT_MAX__ } Int;
17 typedef enum { ll0, llmax = __LONG_LONG_MAX__ } LLong;
19 #define R(T, min, max) (T)integer_range (min, max)
21 char buffer[1];
22 #define T(fmt, ...) \
23 __builtin_sprintf (buffer + 1, fmt, __VA_ARGS__), sink (buffer)
25 void test_bool (_Bool b)
27 T ("%hhi", b); // { dg-warning "writing 1 byte" }
28 T ( "%hi", b); // { dg-warning "writing 1 byte" }
29 T ( "%i", b); // { dg-warning "writing 1 byte" }
32 void test_enum (void)
34 T ("%hhi", R (Int, 1, 1)); // { dg-warning "writing 1 byte" }
35 T ("%hhi", R (Int, 1, 22)); // { dg-warning "between 1 and 2 bytes" }
37 T ( "%hi", R (Int, 1, 2)); // { dg-warning "writing 1 " }
38 T ( "%hi", R (Int, 1, 22)); // { dg-warning "between 1 and 2 " }
39 T ( "%hi", R (Int, 22, 333)); // { dg-warning "between 2 and 3 " }
40 T ( "%hi", R (Int, 333, 4444)); // { dg-warning "between 3 and 4 " }
42 T ( "%i", R (Int, 1, 1)); // { dg-warning "writing 1 " }
43 T ( "%i", R (Int, 1, 22)); // { dg-warning "between 1 and 2 " }
44 T ( "%i", R (Int, 22, 333)); // { dg-warning "between 2 and 3 " }
45 T ( "%i", R (Int, 333, 4444)); // { dg-warning "between 3 and 4 " }
46 T ( "%i", R (Int, 4444, 55555)); // { dg-warning "between 4 and 5 " }
48 #if __LONG_MAX__ == __LONG_LONG_MAX__
49 # define LLI "%li"
50 #else
51 # define LLI "%lli"
52 #endif
54 T (LLI, R (LLong, 1, 1)); // { dg-warning "writing 1 " }
55 T (LLI, R (LLong, 1, 22)); // { dg-warning "between 1 and 2 " }
56 T (LLI, R (LLong, 22, 333)); // { dg-warning "between 2 and 3 " }
57 T (LLI, R (LLong, 333, 4444)); // { dg-warning "between 3 and 4 " }
58 T (LLI, R (LLong, 4444, 55555)); // { dg-warning "between 4 and 5 " }
60 T (LLI, R (LLong, 4444, 1234567890)); // { dg-warning "between 4 and 10 " }
61 T (LLI, R (LLong, 4444, 12345678901)); // { dg-warning "between 4 and 11 " }