When building with: make BOOT_CFLAGS='-O0' (or '-O1') This command: /home/louis/gcc_obj/./prev-gcc/xg++ -B/home/louis/gcc_obj/./prev-gcc/ -B/home/louis/gcc_inst/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -I/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/include -I/home/louis/gcc_trunk/libstdc++-v3/libsupc++ -L/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/home/louis/gcc_obj/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -fno-PIE -c -O1 -gtoggle -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common -DHAVE_CONFIG_H -I. -I. -I../../gcc_trunk/gcc -I../../gcc_trunk/gcc/. -I../../gcc_trunk/gcc/../include -I../../gcc_trunk/gcc/../libcpp/include -I../../gcc_trunk/gcc/../libdecnumber -I../../gcc_trunk/gcc/../libdecnumber/bid -I../libdecnumber -I../../gcc_trunk/gcc/../libbacktrace -o asan.o -MT asan.o -MMD -MP -MF ./.deps/asan.TPo ../../gcc_trunk/gcc/asan.c gets this error: ../../gcc_trunk/gcc/asan.c:1065:1: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 10 [-Werror=format-truncation=] asan_emit_stack_protection (rtx base, rtx pbase, unsigned int alignb, ^~~~~~~~~~~~~~~~~~~~~~~~~~ ../../gcc_trunk/gcc/asan.c:1065:1: note: using the range [1, -2147483648] for directive argument ../../gcc_trunk/gcc/asan.c:1163:26: note: format output between 22 and 32 bytes into a destination of size 30 use_after_return_class); The problem is with this code: 1071 char buf[30]; ... 1080 int use_after_return_class = -1; ... 1162 snprintf (buf, sizeof buf, "__asan_stack_malloc_%d", 1163 use_after_return_class); If use_after_return_class is in fact a negative 10-digit number, buf would overflow. With -O2, the compiler presumably knows more about the value of use_after_return_class, and asan.c compiles without errors. Changing buf to an array of length 31 makes the error go away, but I believe the length should be 32 to leave room for the terminating null byte.
Confirmed. The warning is the result of splitting -Wformat-truncation out of the -Wformat-length warning in r244210. Based on the note ("format output between 22 and 32 bytes") 32 sounds like the right size. Let me do a build with BOOT_CFLAGS='-O0' to see if there are any other problems and fix them all.
Author: msebor Date: Mon Jan 9 20:08:49 2017 New Revision: 244237 URL: https://gcc.gnu.org/viewcvs?rev=244237&root=gcc&view=rev Log: PR bootstrap/79033 - asan.c not compiling with make BOOT_CFLAGS=-O0 gcc/ChangeLog: * asan.c (asan_emit_stack_protection): Increase local buffer size to avoid snprintf truncation warning. Modified: trunk/gcc/ChangeLog trunk/gcc/asan.c
Trivial fix committed in r244237.