https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77743

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2016-09-27
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I was able to reproduce the warning but only at -O0 and with -Wformat-length=2,
not with optimization or with -Wformat-length=1.  With this combination of
options the bfd/ihex.c warning is expected.  (This was on x86_64 but I assume
the coff-rs6000.c warning is of the same nature.)

The gimple-ssa-sprintf pass that implements the warning relies on the VRP pass
to make use of range information.  When optimization is disabled and the VRP
pass doesn't run, with -Wformat-length=1 the warning makes the optimistic
assumption that unknown integer arguments to integer directives have the value
1.  At this level the file compiles cleanly.   With -Wformat-length=2, the pass
assumes that unknown integers can have the full range of their type and so the
warning is expected.  With optimization, the pass makes use of range
information whenever it is available.  In this case it is and the file compiles
cleanly at both -Wformat-length levels.

Please let me know if this doesn't resolve the problem for you.

libtool: compile:  /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc
-DHAVE_CONFIG_H -I. -I/src/binutils-gdb/bfd -I. -I/src/binutils-gdb/bfd
-I/src/binutils-gdb/bfd/../include -DHAVE_x86_64_elf64_vec
-DHAVE_i386_elf32_vec -DHAVE_iamcu_elf32_vec -DHAVE_x86_64_elf32_vec
-DHAVE_i386_aout_linux_vec -DHAVE_i386_pei_vec -DHAVE_x86_64_pei_vec
-DHAVE_l1om_elf64_vec -DHAVE_k1om_elf64_vec -DHAVE_elf64_le_vec
-DHAVE_elf64_be_vec -DHAVE_elf32_le_vec -DHAVE_elf32_be_vec -DHAVE_plugin_vec
-DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes
-Wshadow -Wstack-usage=262144 -Werror -I/src/binutils-gdb/bfd/../zlib
-Wformat-length=2 -Wno-error -MT ihex.lo -MD -MP -MF .deps/ihex.Tpo -c
/src/binutils-gdb/bfd/ihex.c -o ihex.o
/src/binutils-gdb/bfd/ihex.c: In function ‘ihex_bad_byte’:
/src/binutils-gdb/bfd/ihex.c:222:19: warning: ‘%03o’ directive writing between
3 and 11 bytes into a region of size 9 [-Wformat-length=]
  sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
                   ^~~~
/src/binutils-gdb/bfd/ihex.c:222:16: note: using the range [‘1u’,
‘2147483648u’] for directive argument
  sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
                ^~~~~~~~
/src/binutils-gdb/bfd/ihex.c:222:2: note: format output between 5 and 13 bytes
into a destination of size 10
  sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to