Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr78622.c
blobb672710028d8a24c7d23b2d2b522ccc4a72ff224
1 /* PR middle-end/78622 - [7 Regression] -Wformat-overflow/-fprintf-return-value
2 incorrect with overflow/wrapping
3 { dg-do compile }
4 { dg-options "-Wformat-overflow=2" }
5 The h and hh length modifiers are a C99 feature (see PR 78959).
6 { dg-require-effective-target c99_runtime } */
8 char buf[1];
10 int test_uchar_hhd (unsigned char x)
12 if (x < 64 || x > 2U * __SCHAR_MAX__ - 10)
13 return -1;
15 return __builtin_sprintf (buf, "%hhd", x + 1); /* { dg-warning "directive writing between 1 and 4 bytes into a region of size 1" "int32plus" { target { int32plus } } } */
18 int test_uint_hhd (unsigned x)
20 if (x < 64 || x > 2U * __INT_MAX__ - 10)
21 return -1;
23 return __builtin_sprintf (buf, "%hhd", x + 1); /* { dg-warning "directive writing between 1 and 4 bytes into a region of size 1" "int32plus" { target { int32plus } } } */
26 int test_schar_hhu (signed char x)
28 if (x < -9 || x > 9)
29 return -1;
31 return __builtin_sprintf (buf, "%hhu", x + 1); /* { dg-warning "directive writing between 1 and 3 bytes into a region of size 1" "int32plus" { target { int32plus } } } */
34 int test_ushort_hd (unsigned short x)
36 if (x < 64 || x > 2U * __SHRT_MAX__ - 10)
37 return -1;
39 return __builtin_sprintf (buf, "%hd", x + 1); /* { dg-warning "directive writing between 1 and 6 bytes into a region of size 1" "int32plus" { target { int32plus } } } */
42 int test_uint_d (unsigned x)
44 if (x < 64 || x > 2U * __INT_MAX__ - 10)
45 return -1;
47 return __builtin_sprintf (buf, "%d", x + 1); /* { dg-warning "directive writing between 1 and 11 bytes into a region of size 1" "int32plus" { target { int32plus } } } */
50 int test_ulong_ld (unsigned long x)
52 if (x < 64 || x > 2LU * __LONG_MAX__ - 10)
53 return -1;
55 return __builtin_sprintf (buf, "%ld", x + 1); /* { dg-warning "directive writing between 1 and 11 bytes into a region of size 1" "ilp32" { target { ilp32 } } } */
56 /* { dg-warning "directive writing between 1 and 20 bytes into a region of size 1" "lp64" { target { lp64 } } .-1 } */
59 int test_ullong_lld (unsigned long long x)
61 if (x < 64 || x > 2LLU * __LONG_LONG_MAX__ - 10)
62 return -1;
64 return __builtin_sprintf (buf, "%lld", x + 1); /* { dg-warning "directive writing between 1 and 20 bytes into a region of size 1" "int32plus" { target { int32plus } } } */