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" } */ 6 7 __attribute__((noinline, noclone)) int foo(int x)8foo (int x) 9 { 10 if (x < 4096 + 8 || x >= 4096 + 256 + 8) 11 return -1; 12 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; 17 } 18 19 int main(void)20main (void) 21 { 22 if (__SCHAR_MAX__ != 127 || __CHAR_BIT__ != 8 || __SIZEOF_INT__ != 4) 23 return 0; 24 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 (); 34 35 return 0; 36 } 37