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

            Bug ID: 94979
           Summary: gcc-9 generates incorrect code causing segfault
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: makhaloff at gmail dot com
  Target Milestone: ---

I found this issue while compiling systemd-239 with gcc-9.3.0

The problem is in local data initialization on the stack such as array of
pointers to global data.

-O0 is fine, but -01,02,03 eliminates such data causing app to segfault. 

Confirmed gcc-9 branch (up to commit 25c60fcadc397c42a0ec778e5b1238888f2c94d3)
still has this bug.


Test program is attached below.
Additional info and steps to reproduce:

~/gcc$ ./host-x86_64-pc-linux-gnu/gcc/xgcc -v
Using built-in specs.
COLLECT_GCC=./host-x86_64-pc-linux-gnu/gcc/xgcc
Target: x86_64-pc-linux-gnu
Configured with: ./configure --enable-shared --enable-threads=posix
--enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c
--disable-multilib --disable-bootstrap --disable-libstdcxx-pch
--enable-linker-build-id --enable-plugin --with-system-zlib
Thread model: posix
gcc version 9.3.1 20200507 (GCC)
~/gcc$ ./host-x86_64-pc-linux-gnu/gcc/xgcc -B./host-x86_64-pc-linux-gnu/gcc/
test.c
~/gcc$ ./a.out
~/gcc$ echo $?
0
~/gcc$ ./host-x86_64-pc-linux-gnu/gcc/xgcc -B./host-x86_64-pc-linux-gnu/gcc/
-O1 test.c
~/gcc$ ./a.out
Segmentation fault (core dumped)


===================== test.c ==========================

#include <string.h>

int chararray(char **j) {
        if (!j)
                j = (char *[]){"a", "test"};

        return (strlen(j[0]) == 1) & (strlen(j[1]) == 4);
}

int main(void) {
        return chararray(0) == 0;
}

=======================================================

Reply via email to