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

            Bug ID: 79033
           Summary: asan.c not compiling with make BOOT_CFLAGS='-O0' (or
                    '-O1')
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lkrupp at gcc dot gnu.org
  Target Milestone: ---

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.

Reply via email to