https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109421
Bug ID: 109421
Summary: Compilation takes a long time for struct that contains
a large default-initialized array
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ejakobs at boerboeltrading dot com
Target Milestone: ---
This is similar to #59659, but is still a problem in GCC 11.2.1 and GCC 10.2.1.
The following code takes a very long time to compile with -O3 enabled:
#include <vector>
#ifndef SIZE
#define SIZE 100000
#endif
struct S
{
int a;
};
struct T
{
std::vector<S> arr[SIZE]{}; // remove the default-initializer {} to compile
fast
};
int main(int argc, char** argv)
{
T t;
for (int i=0; i<SIZE; ++i) {
t.arr[i].push_back(S{argc * i}); // use argc so that gcc doesn't optimize
everything out
}
return t.arr[SIZE-1][0].a;
}