1 /* PR tree-optimization/79327 - wrong code at -O2 and -fprintf-return-value 2 { dg-do run } 3 { dg-options "-O2 -Wall" } */ 4 5 volatile int a, b = -1; 6 char buf[64]; 7 8 #define FMT "%+03d%02d" 9 const char *volatile fmt = FMT; 10 main()11int main () 12 { 13 int c = a; 14 int d = b; 15 if (c >= -35791395 && c < 35791394 && d >= -1 && d < __INT_MAX__) 16 { 17 /* In the following the range of return values can be computed 18 by GCC. */ 19 int n1 = __builtin_sprintf (buf, FMT, c + 1, d + 1); 20 if (n1 > 7) 21 __builtin_abort (); 22 23 /* Here GCC can't see the format string so the return value 24 must be computed by a libc call. */ 25 int n2 = __builtin_sprintf (buf, fmt, c + 1, d + 1); 26 27 if (n1 != n2) 28 __builtin_abort (); 29 } 30 return 0; 31 } 32