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

            Bug ID: 98547
           Summary: GCC spends many minutes instead of seconds building a
                    file with array initialization
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ilord.tiran at yandex dot ru
  Target Milestone: ---

Hi, GCC Team.

GCC spends a lot of time building the code below, the code in a real project is
compiled for more than an hour. It looks like a GCC has problem with long array
initialization. All versions of GCC that I have tested are affected by this
bug.

GCC/Linux ENV:

$ g++ --version

g++ (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How to reproduce:

$ time g++ -O3 long_build.cpp -o long_build_gcc

real    6m49,286s
user    6m48,478s
sys     0m0,526s

Clang compiles this code in less than a minute

$ clang++ --version

Ubuntu clang version
11.0.1-++20201126023002+d8e8ae195a2-1~exp1~20201126013616.135
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

$ time clang++ -O3 long_build.cpp -o long_build_clang

real    0m0,208s
user    0m0,194s
sys     0m0,008s

Output file is huge. It contains copy-paste assembly for each array member
initialization:

proydakov@:~/gcc-bug$ ls -lah
total 1,2M
drwxrwxr-x  2 proydakov proydakov 4,0K янв  5 23:26 .
drwxrwxr-x 19 proydakov proydakov 4,0K ноя 15 22:44 ..
-rwxrwxr-x  1 proydakov proydakov  17K янв  5 22:03 long_build_clang
-rw-rw-r--  1 proydakov proydakov  477 янв  5 23:10 long_build.cpp
-rwxrwxr-x  1 proydakov proydakov 1,2M янв  5 22:48 long_build_gcc
-rw-rw-r--  1 proydakov proydakov  618 янв  5 23:10 long_build.ii

Code snippet:

struct header_t
{
    unsigned msg_id;
    unsigned length;
};
template<typename HEADER, unsigned MTU>
struct packet_t
{
    enum { DATA_SIZE = MTU - sizeof(HEADER) };
    packet_t() : data{}
    {
        header.msg_id = 0;
        header.length = sizeof(HEADER);
    }
    HEADER header;
    char data[DATA_SIZE];
};
struct pool
{
    pool() : packets{}
    {
    }
    packet_t<header_t, 1500> packets[1024 * 16];
};
int main()
{
    pool l;
    return sizeof(l);
}

Best regards, Proydakov Evgeny.
  • [Bug c++/98547] New: GCC spends ... ilord.tiran at yandex dot ru via Gcc-bugs

Reply via email to