Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / pr78622.c
blob384803d1a091723fdb6368faf5b5389de7509555
1 /* PR middle-end/78622 - [7 Regression] -Wformat-overflow/-fprintf-return-value
2 incorrect with overflow/wrapping
3 { dg-skip-if "Requires %hhd format" { hppa*-*-hpux* } { "*" } { "" } }
4 { dg-require-effective-target c99_runtime }
5 { dg-additional-options "-Wformat-overflow=2" } */
7 __attribute__((noinline, noclone)) int
8 foo (int x)
10 if (x < 4096 + 8 || x >= 4096 + 256 + 8)
11 return -1;
13 char buf[5];
14 int n = __builtin_snprintf (buf, sizeof buf, "%hhd", x + 1);
15 __builtin_printf ("\"%hhd\" => %i\n", x + 1, n);
16 return n;
19 int
20 main (void)
22 if (__SCHAR_MAX__ != 127 || __CHAR_BIT__ != 8 || __SIZEOF_INT__ != 4)
23 return 0;
25 if (foo (4095 + 9) != 1
26 || foo (4095 + 32) != 2
27 || foo (4095 + 127) != 3
28 || foo (4095 + 128) != 4
29 || foo (4095 + 240) != 3
30 || foo (4095 + 248) != 2
31 || foo (4095 + 255) != 2
32 || foo (4095 + 256) != 1)
33 __builtin_abort ();
35 return 0;