https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81840
Bug ID: 81840 Summary: Incorrect warning issued in arm-to-x86_64 cross compilation Product: gcc Version: 7.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bneumeier at gmail dot com Target Milestone: --- Created attachment 41985 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41985&action=edit preprocessed source code that demonstrates the issue I'm using GCC 7 to build an armv7 to x86_64 cross toolchain. gas compilation fails with an incorrect warning when compiling tc-i386.c. I've pruned tc-i386.i as much as I can while preserving the problematic behavior, but it is still pretty long so I am compressing it. Details: gcc version 7.1.1 20170802 (GCC) Target: armv7l-unknown-linux-gnueabihf Configured with: /home/random/work/build/gcc-7.1.0/configure --prefix=/home/random/hostcbl2 --with-local-prefix=/home/random/hostcbl2 --disable-multilib --disable-nls --enable-shared --enable-languages=c,c++ --enable-c99 --enable-long-long --enable-threads=posix --with-gmp=/home/random/hostcbl2 --with-mpfr=/home/random/hostcbl2 --with-mpc=/home/random/hostcbl2 --with-isl=/home/random/hostcbl2 --with-float=hard The compilation line that fails is: armv7l-unknown-linux-gnueabihf-gcc -W -Wall -Werror -Wno-unused-function -Wno-implicit-fallthrough -g -O2 -c -o tc-i386.o tc-i386.i The compiler emits this output: tc-i386.i: In function 'output_invalid': tc-i386.i:13834:12: error: '%x' directive output may be truncated writing between 1 and 8 bytes into a region of size 5 [-Werror=format-truncation=] "(0x%x)", (unsigned char) c); ^~ tc-i386.i:13834:8: note: directive argument in the range [0, 2147483647] "(0x%x)", (unsigned char) c); ^~~~~~~~ tc-i386.i:13833:5: note: 'snprintf' output between 6 and 13 bytes into a destination of size 8 snprintf (output_invalid_buf, sizeof (output_invalid_buf), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "(0x%x)", (unsigned char) c); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors