https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81483
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Status|UNCONFIRMED |NEW Last reconfirmed| |2017-07-19 CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The VRP pass computes the correct range for the sprintf argument but the range made available outside the pass via the get_range_info() function for the promoted argument is that of unsigned int (a similar problem is described in bug 78969). It's a bug/limitation in the range propagation machinery in GCC. I'm not sure there's an easy way to work around it in the sprintf pass. If not, hopefully the new VRP implementation will solve these problems. Until then, a workaround is to unsigned int as the loop counter and cast it to unsigned char in the sprintf call: unsigned zone; char buffer[10]; for (zone = 0; zone != num_zones; zone++) __builtin_sprintf (buffer, "zone%02X", (unsigned char)zone);